Remove WMFullscreenLevel
[wmaker-crm.git] / src / actions.c
blob36a0ca144415c8947fdb4061c25947b1889edde0
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
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "wconfig.h"
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <unistd.h>
30 #include <math.h>
31 #include <time.h>
33 #include "WindowMaker.h"
34 #include "framewin.h"
35 #include "window.h"
36 #include "client.h"
37 #include "icon.h"
38 #include "colormap.h"
39 #include "application.h"
40 #include "actions.h"
41 #include "stacking.h"
42 #include "appicon.h"
43 #include "dock.h"
44 #include "appmenu.h"
45 #include "winspector.h"
46 #include "workspace.h"
47 #include "xinerama.h"
48 #include "usermenu.h"
49 #include "placement.h"
50 #include "misc.h"
51 #include "event.h"
54 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
55 unsigned int *new_width, unsigned int *new_height);
56 static void save_old_geometry(WWindow *wwin, int directions);
58 /******* Local Variables *******/
59 static struct {
60 int steps;
61 int delay;
62 } shadePars[5] = {
64 SHADE_STEPS_UF, SHADE_DELAY_UF}, {
65 SHADE_STEPS_F, SHADE_DELAY_F}, {
66 SHADE_STEPS_M, SHADE_DELAY_M}, {
67 SHADE_STEPS_S, SHADE_DELAY_S}, {
68 SHADE_STEPS_US, SHADE_DELAY_US}};
70 #define UNSHADE 0
71 #define SHADE 1
72 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
73 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
75 static int compareTimes(Time t1, Time t2)
77 Time diff;
78 if (t1 == t2)
79 return 0;
80 diff = t1 - t2;
81 return (diff < 60000) ? 1 : -1;
84 #ifdef ANIMATIONS
85 static void shade_animate(WWindow *wwin, Bool what);
86 #else
87 static void shade_animate(WWindow *wwin, Bool what) { }
88 #endif
91 *----------------------------------------------------------------------
92 * wSetFocusTo--
93 * Changes the window focus to the one passed as argument.
94 * If the window to focus is not already focused, it will be brought
95 * to the head of the list of windows. Previously focused window is
96 * unfocused.
98 * Side effects:
99 * Window list may be reordered and the window focus is changed.
101 *----------------------------------------------------------------------
103 void wSetFocusTo(WScreen *scr, WWindow *wwin)
105 static WScreen *old_scr = NULL;
107 WWindow *old_focused;
108 WWindow *focused = scr->focused_window;
109 Time timestamp = w_global.timestamp.last_event;
110 WApplication *oapp = NULL, *napp = NULL;
111 int wasfocused;
113 if (scr->flags.ignore_focus_events || compareTimes(w_global.timestamp.focus_change, timestamp) > 0)
114 return;
116 if (!old_scr)
117 old_scr = scr;
119 old_focused = old_scr->focused_window;
121 w_global.timestamp.focus_change = timestamp;
123 if (old_focused)
124 oapp = wApplicationOf(old_focused->main_window);
126 if (wwin == NULL) {
127 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
128 if (old_focused)
129 wWindowUnfocus(old_focused);
131 if (oapp) {
132 wAppMenuUnmap(oapp->menu);
133 if (wPreferences.highlight_active_app)
134 wApplicationDeactivate(oapp);
137 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
138 return;
141 if (old_scr != scr && old_focused)
142 wWindowUnfocus(old_focused);
144 wasfocused = wwin->flags.focused;
145 napp = wApplicationOf(wwin->main_window);
147 /* remember last workspace where the app has been */
148 if (napp)
149 napp->last_workspace = wwin->frame->workspace;
151 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
152 /* install colormap if colormap mode is lock mode */
153 if (wPreferences.colormap_mode == WCM_CLICK)
154 wColormapInstallForWindow(scr, wwin);
156 /* set input focus */
157 switch (wwin->focus_mode) {
158 case WFM_NO_INPUT:
159 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
160 break;
161 case WFM_PASSIVE:
162 case WFM_LOCALLY_ACTIVE:
163 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
164 break;
165 case WFM_GLOBALLY_ACTIVE:
166 break;
169 XFlush(dpy);
170 if (wwin->protocols.TAKE_FOCUS)
171 wClientSendProtocol(wwin, w_global.atom.wm.take_focus, timestamp);
173 XSync(dpy, False);
174 } else {
175 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
178 if (WFLAGP(wwin, no_focusable))
179 return;
181 /* if this is not the focused window focus it */
182 if (focused != wwin) {
183 /* change the focus window list order */
184 if (wwin->prev)
185 wwin->prev->next = wwin->next;
187 if (wwin->next)
188 wwin->next->prev = wwin->prev;
190 wwin->prev = focused;
191 focused->next = wwin;
192 wwin->next = NULL;
193 scr->focused_window = wwin;
195 if (oapp && oapp != napp) {
196 wAppMenuUnmap(oapp->menu);
197 if (wPreferences.highlight_active_app)
198 wApplicationDeactivate(oapp);
202 wWindowFocus(wwin, focused);
204 if (napp && !wasfocused) {
205 #ifdef USER_MENU
206 wUserMenuRefreshInstances(napp->menu, wwin);
207 #endif /* USER_MENU */
209 if (wwin->flags.mapped)
210 wAppMenuMap(napp->menu, wwin);
212 if (napp && wPreferences.highlight_active_app)
213 wApplicationActivate(napp);
215 XFlush(dpy);
216 old_scr = scr;
219 void wShadeWindow(WWindow *wwin)
222 if (wwin->flags.shaded)
223 return;
225 XLowerWindow(dpy, wwin->client_win);
226 shade_animate(wwin, SHADE);
228 wwin->flags.skip_next_animation = 0;
229 wwin->flags.shaded = 1;
230 wwin->flags.mapped = 0;
231 /* prevent window withdrawal when getting UnmapNotify */
232 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
233 XUnmapWindow(dpy, wwin->client_win);
234 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
236 /* for the client it's just like iconification */
237 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
239 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
240 wWindowSynthConfigureNotify(wwin);
243 wClientSetState(wwin, IconicState, None);
246 WMPostNotificationName(WMNChangedState, wwin, "shade");
248 #ifdef ANIMATIONS
249 if (!wwin->screen_ptr->flags.startup) {
250 /* Catch up with events not processed while animation was running */
251 ProcessPendingEvents();
253 #endif
256 void wUnshadeWindow(WWindow *wwin)
259 if (!wwin->flags.shaded)
260 return;
262 wwin->flags.shaded = 0;
263 wwin->flags.mapped = 1;
264 XMapWindow(dpy, wwin->client_win);
266 shade_animate(wwin, UNSHADE);
268 wwin->flags.skip_next_animation = 0;
269 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
270 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
272 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
273 wWindowSynthConfigureNotify(wwin);
275 /* if the window is focused, set the focus again as it was disabled during
276 * shading */
277 if (wwin->flags.focused)
278 wSetFocusTo(wwin->screen_ptr, wwin);
280 WMPostNotificationName(WMNChangedState, wwin, "shade");
283 /* Set the old coordinates using the current values */
284 static void save_old_geometry(WWindow *wwin, int directions)
286 /* never been saved? */
287 if (! wwin->old_geometry.width)
288 directions |= SAVE_GEOMETRY_X | SAVE_GEOMETRY_WIDTH;
289 if (! wwin->old_geometry.height)
290 directions |= SAVE_GEOMETRY_Y | SAVE_GEOMETRY_HEIGHT;
292 if (directions & SAVE_GEOMETRY_X)
293 wwin->old_geometry.x = wwin->frame_x;
294 if (directions & SAVE_GEOMETRY_Y)
295 wwin->old_geometry.y = wwin->frame_y;
296 if (directions & SAVE_GEOMETRY_WIDTH)
297 wwin->old_geometry.width = wwin->client.width;
298 if (directions & SAVE_GEOMETRY_HEIGHT)
299 wwin->old_geometry.height = wwin->client.height;
302 static void remember_geometry(WWindow *wwin, int *x, int *y, int *w, int *h)
304 WMRect old_geom_rect;
305 int old_head;
306 Bool same_head;
308 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
309 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
310 same_head = (wGetHeadForWindow(wwin) == old_head);
311 *x = ((wwin->old_geometry.x || wwin->old_geometry.width) && same_head) ? wwin->old_geometry.x : wwin->frame_x;
312 *y = ((wwin->old_geometry.y || wwin->old_geometry.height) && same_head) ? wwin->old_geometry.y : wwin->frame_y;
313 *w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
314 *h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
317 /* Remember geometry for unmaximizing */
318 void update_saved_geometry(WWindow *wwin)
320 /* NOT if we aren't already maximized
321 * we'll save geometry when maximizing */
322 if (!wwin->flags.maximized)
323 return;
325 /* NOT if we are fully maximized */
326 if ((wwin->flags.maximized & MAX_MAXIMUS) ||
327 ((wwin->flags.maximized & MAX_HORIZONTAL) &&
328 (wwin->flags.maximized & MAX_VERTICAL)))
329 return;
331 /* save the co-ordinate in the axis in which we AREN'T maximized */
332 if (wwin->flags.maximized & MAX_HORIZONTAL)
333 save_old_geometry(wwin, SAVE_GEOMETRY_Y);
334 if (wwin->flags.maximized & MAX_VERTICAL)
335 save_old_geometry(wwin, SAVE_GEOMETRY_X);
338 void wMaximizeWindow(WWindow *wwin, int directions)
340 unsigned int new_width, new_height, half_scr_width, half_scr_height;
341 int new_x = 0;
342 int new_y = 0;
343 int maximus_x = 0;
344 int maximus_y = 0;
345 unsigned int maximus_width = 0;
346 unsigned int maximus_height = 0;
347 WArea usableArea, totalArea;
348 Bool has_border = 1;
349 int adj_size;
351 if (!IS_RESIZABLE(wwin))
352 return;
354 if (!HAS_BORDER(wwin))
355 has_border = 0;
357 /* the size to adjust the geometry */
358 adj_size = wwin->screen_ptr->frame_border_width * 2 * has_border;
360 /* save old coordinates before we change the current values */
361 if (!wwin->flags.maximized)
362 save_old_geometry(wwin, SAVE_GEOMETRY_ALL);
364 totalArea.x2 = wwin->screen_ptr->scr_width;
365 totalArea.y2 = wwin->screen_ptr->scr_height;
366 totalArea.x1 = 0;
367 totalArea.y1 = 0;
368 usableArea = totalArea;
370 if (!(directions & MAX_IGNORE_XINERAMA)) {
371 WScreen *scr = wwin->screen_ptr;
372 int head;
374 if (directions & MAX_KEYBOARD)
375 head = wGetHeadForWindow(wwin);
376 else
377 head = wGetHeadForPointerLocation(scr);
379 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
382 /* Only save directions, not kbd or xinerama hints */
383 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS);
385 if (WFLAGP(wwin, full_maximize)) {
386 usableArea = totalArea;
388 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
389 half_scr_height = (usableArea.y2 - usableArea.y1)/2;
391 if (wwin->flags.shaded) {
392 wwin->flags.skip_next_animation = 1;
393 wUnshadeWindow(wwin);
396 if (directions & MAX_MAXIMUS) {
397 find_Maximus_geometry(wwin, usableArea, &maximus_x, &maximus_y, &maximus_width, &maximus_height);
398 new_width = maximus_width - adj_size;
399 new_height = maximus_height - adj_size;
400 new_x = maximus_x;
401 new_y = maximus_y;
402 if (WFLAGP(wwin, full_maximize) && (new_y == 0)) {
403 new_height += wwin->frame->bottom_width - 1;
404 new_y -= wwin->frame->top_width;
407 wwin->maximus_x = new_x;
408 wwin->maximus_y = new_y;
409 wwin->flags.old_maximized |= MAX_MAXIMUS;
410 } else {
411 /* set default values if no option set then */
412 if (!(directions & (MAX_HORIZONTAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS))) {
413 new_width = (wwin->old_geometry.width) ? wwin->old_geometry.width : wwin->frame->core->width;
414 new_x = (wwin->old_geometry.x) ? wwin->old_geometry.x : wwin->frame_x;
416 if (!(directions & (MAX_VERTICAL | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS))) {
417 new_height = (wwin->old_geometry.height) ? wwin->old_geometry.height : wwin->frame->core->height;
418 new_y = (wwin->old_geometry.y) ? wwin->old_geometry.y : wwin->frame_y;
421 /* left|right position */
422 if (directions & MAX_LEFTHALF) {
423 new_width = half_scr_width - adj_size;
424 new_x = usableArea.x1;
425 } else if (directions & MAX_RIGHTHALF) {
426 new_width = half_scr_width - adj_size;
427 new_x = usableArea.x1 + half_scr_width;
429 /* top|bottom position */
430 if (directions & MAX_TOPHALF) {
431 new_height = half_scr_height - adj_size;
432 new_y = usableArea.y1;
433 } else if (directions & MAX_BOTTOMHALF) {
434 new_height = half_scr_height - adj_size;
435 new_y = usableArea.y1 + half_scr_height;
438 /* vertical|horizontal position */
439 if (directions & MAX_HORIZONTAL) {
440 new_width = usableArea.x2 - usableArea.x1 - adj_size;
441 new_x = usableArea.x1;
443 if (directions & MAX_VERTICAL) {
444 new_height = usableArea.y2 - usableArea.y1 - adj_size;
445 new_y = usableArea.y1;
446 if (WFLAGP(wwin, full_maximize) && (new_y == 0))
447 new_y -= wwin->frame->top_width;
451 if (!WFLAGP(wwin, full_maximize) && !(directions == MAX_MAXIMUS || directions == MAX_HORIZONTAL))
452 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
454 /* set maximization state */
455 wwin->flags.maximized = directions;
456 if ((wwin->flags.old_maximized & MAX_MAXIMUS) && !wwin->flags.maximized)
457 wwin->flags.maximized = MAX_MAXIMUS;
459 wWindowConstrainSize(wwin, &new_width, &new_height);
461 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
462 usableArea.y2 - usableArea.y1, &new_width, &new_height);
464 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
465 wWindowSynthConfigureNotify(wwin);
467 WMPostNotificationName(WMNChangedState, wwin, "maximize");
470 /* generic (un)maximizer */
471 void handleMaximize(WWindow *wwin, int directions)
473 int current = wwin->flags.maximized;
474 int requested = directions & (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS);
475 int effective = requested ^ current;
476 int flags = directions & ~requested;
478 if (!effective) {
479 /* allow wMaximizeWindow to restore the Maximusized size */
480 if ((wwin->flags.old_maximized & MAX_MAXIMUS) &&
481 !(requested & MAX_MAXIMUS))
482 wMaximizeWindow(wwin, MAX_MAXIMUS | flags);
483 else
484 wUnmaximizeWindow(wwin);
485 /* these alone mean vertical|horizontal toggle */
486 } else if ((effective == MAX_LEFTHALF) ||
487 (effective == MAX_RIGHTHALF) ||
488 (effective == MAX_TOPHALF) ||
489 (effective == MAX_BOTTOMHALF))
490 wUnmaximizeWindow(wwin);
491 else {
492 if ((requested == (MAX_HORIZONTAL | MAX_VERTICAL)) ||
493 (requested == MAX_MAXIMUS))
494 effective = requested;
495 else {
496 if (requested & MAX_LEFTHALF) {
497 if (!(requested & (MAX_TOPHALF | MAX_BOTTOMHALF)))
498 effective |= MAX_VERTICAL;
499 else
500 effective |= requested & (MAX_TOPHALF | MAX_BOTTOMHALF);
501 effective |= MAX_LEFTHALF;
502 effective &= ~(MAX_HORIZONTAL | MAX_RIGHTHALF);
503 } else if (requested & MAX_RIGHTHALF) {
504 if (!(requested & (MAX_TOPHALF | MAX_BOTTOMHALF)))
505 effective |= MAX_VERTICAL;
506 else
507 effective |= requested & (MAX_TOPHALF | MAX_BOTTOMHALF);
508 effective |= MAX_RIGHTHALF;
509 effective &= ~(MAX_HORIZONTAL | MAX_LEFTHALF);
511 if (requested & MAX_TOPHALF) {
512 if (!(requested & (MAX_LEFTHALF | MAX_RIGHTHALF)))
513 effective |= MAX_HORIZONTAL;
514 else
515 effective |= requested & (MAX_LEFTHALF | MAX_RIGHTHALF);
516 effective |= MAX_TOPHALF;
517 effective &= ~(MAX_VERTICAL | MAX_BOTTOMHALF);
518 } else if (requested & MAX_BOTTOMHALF) {
519 if (!(requested & (MAX_LEFTHALF | MAX_RIGHTHALF)))
520 effective |= MAX_HORIZONTAL;
521 else
522 effective |= requested & (MAX_LEFTHALF | MAX_RIGHTHALF);
523 effective |= MAX_BOTTOMHALF;
524 effective &= ~(MAX_VERTICAL | MAX_TOPHALF);
526 if (requested & MAX_HORIZONTAL)
527 effective &= ~(MAX_LEFTHALF | MAX_RIGHTHALF);
528 if (requested & MAX_VERTICAL)
529 effective &= ~(MAX_TOPHALF | MAX_BOTTOMHALF);
530 effective &= ~MAX_MAXIMUS;
532 wMaximizeWindow(wwin, effective | flags);
536 /* the window boundary coordinates */
537 typedef struct {
538 int left;
539 int right;
540 int bottom;
541 int top;
542 int width;
543 int height;
544 } win_coords;
546 static void set_window_coords(WWindow *wwin, win_coords *obs)
548 obs->left = wwin->frame_x;
549 obs->top = wwin->frame_y;
550 obs->width = wwin->frame->core->width;
551 obs->height = wwin->frame->core->height;
552 obs->bottom = obs->top + obs->height;
553 obs->right = obs->left + obs->width;
557 * Maximus: tiled maximization (maximize without overlapping other windows)
559 * The original window 'orig' will be maximized to new coordinates 'new'.
560 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
562 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
563 unsigned int *new_width, unsigned int *new_height)
565 WWindow *tmp;
566 short int tbar_height_0 = 0, rbar_height_0 = 0, bd_width_0 = 0;
567 short int adjust_height;
568 int x_intsect, y_intsect;
569 /* the obstructing, original and new windows */
570 win_coords obs, orig, new;
572 /* set the original coordinate positions of the window to be Maximumized */
573 if (wwin->flags.maximized) {
574 /* window is already maximized; consider original geometry */
575 remember_geometry(wwin, &orig.left, &orig.top, &orig.width, &orig.height);
576 orig.bottom = orig.top + orig.height;
577 orig.right = orig.left + orig.width;
579 else
580 set_window_coords(wwin, &orig);
582 /* Try to fully maximize first, then readjust later */
583 new.left = usableArea.x1;
584 new.right = usableArea.x2;
585 new.top = usableArea.y1;
586 new.bottom = usableArea.y2;
588 if (HAS_TITLEBAR(wwin))
589 tbar_height_0 = TITLEBAR_HEIGHT;
590 if (HAS_RESIZEBAR(wwin))
591 rbar_height_0 = RESIZEBAR_HEIGHT;
592 if (HAS_BORDER(wwin))
593 bd_width_0 = wwin->screen_ptr->frame_border_width;
595 /* the length to be subtracted if the window has titlebar, etc */
596 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
598 tmp = wwin;
599 /* The focused window is always the last in the list */
600 while (tmp->prev) {
601 /* ignore windows in other workspaces etc */
602 if (tmp->prev->frame->workspace != w_global.workspace.current ||
603 tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
604 tmp = tmp->prev;
605 continue;
607 tmp = tmp->prev;
609 /* Set the coordinates of obstructing window */
610 set_window_coords(tmp, &obs);
612 /* Try to maximize in the y direction first */
613 x_intsect = calcIntersectionLength(orig.left, orig.width, obs.left, obs.width);
614 if (x_intsect != 0) {
615 /* TODO: Consider the case when coords are equal */
616 if (obs.bottom < orig.top && obs.bottom > new.top) {
617 /* w_0 is below the bottom of w_j */
618 new.top = obs.bottom + 1;
620 if (orig.bottom < obs.top && obs.top < new.bottom) {
621 /* The bottom of w_0 is above the top of w_j */
622 new.bottom = obs.top - 1;
627 tmp = wwin;
628 while (tmp->prev) {
629 if (tmp->prev->frame->workspace != w_global.workspace.current ||
630 tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
631 tmp = tmp->prev;
632 continue;
634 tmp = tmp->prev;
636 set_window_coords(tmp, &obs);
639 * Use the new.top and new.height instead of original values
640 * as they may have different intersections with the obstructing windows
642 new.height = new.bottom - new.top - adjust_height;
643 y_intsect = calcIntersectionLength(new.top, new.height, obs.top, obs.height);
644 if (y_intsect != 0) {
645 if (obs.right < orig.left && obs.right > new.left) {
646 /* w_0 is completely to the right of w_j */
647 new.left = obs.right + 1;
649 if (orig.right < obs.left && obs.left < new.right) {
650 /* w_0 is completely to the left of w_j */
651 new.right = obs.left - 1;
656 *new_x = new.left;
657 *new_y = new.top;
658 /* xcalc needs -7 here, but other apps don't */
659 *new_height = new.bottom - new.top - adjust_height - 1;;
660 *new_width = new.right - new.left;
663 void wUnmaximizeWindow(WWindow *wwin)
665 int x, y, w, h;
667 if (!wwin->flags.maximized)
668 return;
670 if (wwin->flags.shaded) {
671 wwin->flags.skip_next_animation = 1;
672 wUnshadeWindow(wwin);
675 /* Use old coordinates if they are set, current values otherwise */
676 remember_geometry(wwin, &x, &y, &w, &h);
678 /* unMaximusize relative to original position */
679 if (wwin->flags.maximized & MAX_MAXIMUS) {
680 x += wwin->frame_x - wwin->maximus_x;
681 y += wwin->frame_y - wwin->maximus_y;
684 wwin->flags.maximized = 0;
685 wwin->flags.old_maximized = 0;
686 wWindowConfigure(wwin, x, y, w, h);
687 wWindowSynthConfigureNotify(wwin);
689 WMPostNotificationName(WMNChangedState, wwin, "maximize");
692 void wFullscreenWindow(WWindow *wwin)
694 int head;
695 WMRect rect;
697 if (wwin->flags.fullscreen)
698 return;
700 wwin->flags.fullscreen = True;
702 wWindowConfigureBorders(wwin);
704 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
706 wwin->bfs_geometry.x = wwin->frame_x;
707 wwin->bfs_geometry.y = wwin->frame_y;
708 wwin->bfs_geometry.width = wwin->frame->core->width;
709 wwin->bfs_geometry.height = wwin->frame->core->height;
711 head = wGetHeadForWindow(wwin);
712 rect = wGetRectForHead(wwin->screen_ptr, head);
713 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
715 wwin->screen_ptr->bfs_focused_window = wwin->screen_ptr->focused_window;
716 wSetFocusTo(wwin->screen_ptr, wwin);
718 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
721 void wUnfullscreenWindow(WWindow *wwin)
723 if (!wwin->flags.fullscreen)
724 return;
726 wwin->flags.fullscreen = False;
728 if (WFLAGP(wwin, sunken)) {
729 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
730 } else if (WFLAGP(wwin, floating)) {
731 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
734 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
735 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
737 wWindowConfigureBorders(wwin);
739 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
740 wFrameWindowPaint(wwin->frame);
743 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
745 if (wwin->screen_ptr->bfs_focused_window) {
746 wSetFocusTo(wwin->screen_ptr, wwin->screen_ptr->bfs_focused_window);
747 wwin->screen_ptr->bfs_focused_window = NULL;
751 #ifdef ANIMATIONS
752 static void animateResizeFlip(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
754 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
755 float cx, cy, cw, ch;
756 float xstep, ystep, wstep, hstep;
757 XPoint points[5];
758 float dx, dch, midy;
759 float angle, final_angle, delta;
761 xstep = (float)(fx - x) / steps;
762 ystep = (float)(fy - y) / steps;
763 wstep = (float)(fw - w) / steps;
764 hstep = (float)(fh - h) / steps;
766 cx = (float)x;
767 cy = (float)y;
768 cw = (float)w;
769 ch = (float)h;
771 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
772 delta = (float)(final_angle / FRAMES);
773 for (angle = 0;; angle += delta) {
774 if (angle > final_angle)
775 angle = final_angle;
777 dx = (cw / 10) - ((cw / 5) * sin(angle));
778 dch = (ch / 2) * cos(angle);
779 midy = cy + (ch / 2);
781 points[0].x = cx + dx;
782 points[0].y = midy - dch;
783 points[1].x = cx + cw - dx;
784 points[1].y = points[0].y;
785 points[2].x = cx + cw + dx;
786 points[2].y = midy + dch;
787 points[3].x = cx - dx;
788 points[3].y = points[2].y;
789 points[4].x = points[0].x;
790 points[4].y = points[0].y;
792 XGrabServer(dpy);
793 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
794 XFlush(dpy);
795 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
797 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
798 XUngrabServer(dpy);
799 cx += xstep;
800 cy += ystep;
801 cw += wstep;
802 ch += hstep;
803 if (angle >= final_angle)
804 break;
807 XFlush(dpy);
810 #undef FRAMES
812 static void
813 animateResizeTwist(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
815 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
816 float cx, cy, cw, ch;
817 float xstep, ystep, wstep, hstep;
818 XPoint points[5];
819 float angle, final_angle, a, d, delta;
821 x += w / 2;
822 y += h / 2;
823 fx += fw / 2;
824 fy += fh / 2;
826 xstep = (float)(fx - x) / steps;
827 ystep = (float)(fy - y) / steps;
828 wstep = (float)(fw - w) / steps;
829 hstep = (float)(fh - h) / steps;
831 cx = (float)x;
832 cy = (float)y;
833 cw = (float)w;
834 ch = (float)h;
836 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
837 delta = (float)(final_angle / FRAMES);
838 for (angle = 0;; angle += delta) {
839 if (angle > final_angle)
840 angle = final_angle;
842 a = atan(ch / cw);
843 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
845 points[0].x = cx + cos(angle - a) * d;
846 points[0].y = cy + sin(angle - a) * d;
847 points[1].x = cx + cos(angle + a) * d;
848 points[1].y = cy + sin(angle + a) * d;
849 points[2].x = cx + cos(angle - a + WM_PI) * d;
850 points[2].y = cy + sin(angle - a + WM_PI) * d;
851 points[3].x = cx + cos(angle + a + WM_PI) * d;
852 points[3].y = cy + sin(angle + a + WM_PI) * d;
853 points[4].x = cx + cos(angle - a) * d;
854 points[4].y = cy + sin(angle - a) * d;
855 XGrabServer(dpy);
856 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
857 XFlush(dpy);
858 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
860 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
861 XUngrabServer(dpy);
862 cx += xstep;
863 cy += ystep;
864 cw += wstep;
865 ch += hstep;
866 if (angle >= final_angle)
867 break;
870 XFlush(dpy);
873 #undef FRAMES
875 static void animateResizeZoom(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
877 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
878 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
879 float xstep, ystep, wstep, hstep;
880 int i, j;
882 xstep = (float)(fx - x) / steps;
883 ystep = (float)(fy - y) / steps;
884 wstep = (float)(fw - w) / steps;
885 hstep = (float)(fh - h) / steps;
887 for (j = 0; j < FRAMES; j++) {
888 cx[j] = (float)x;
889 cy[j] = (float)y;
890 cw[j] = (float)w;
891 ch[j] = (float)h;
893 XGrabServer(dpy);
894 for (i = 0; i < steps; i++) {
895 for (j = 0; j < FRAMES; j++) {
896 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
897 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
899 XFlush(dpy);
900 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
902 for (j = 0; j < FRAMES; j++) {
903 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
904 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
905 if (j < FRAMES - 1) {
906 cx[j] = cx[j + 1];
907 cy[j] = cy[j + 1];
908 cw[j] = cw[j + 1];
909 ch[j] = ch[j + 1];
910 } else {
911 cx[j] += xstep;
912 cy[j] += ystep;
913 cw[j] += wstep;
914 ch[j] += hstep;
919 for (j = 0; j < FRAMES; j++) {
920 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
922 XFlush(dpy);
923 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
925 for (j = 0; j < FRAMES; j++) {
926 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
929 XUngrabServer(dpy);
932 #undef FRAMES
934 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
936 int style = wPreferences.iconification_style; /* Catch the value */
937 int steps;
939 if (style == WIS_NONE)
940 return;
942 if (style == WIS_RANDOM) {
943 style = rand() % 3;
946 switch (style) {
947 case WIS_TWIST:
948 steps = MINIATURIZE_ANIMATION_STEPS_T;
949 if (steps > 0)
950 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
951 break;
952 case WIS_FLIP:
953 steps = MINIATURIZE_ANIMATION_STEPS_F;
954 if (steps > 0)
955 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
956 break;
957 case WIS_ZOOM:
958 default:
959 steps = MINIATURIZE_ANIMATION_STEPS_Z;
960 if (steps > 0)
961 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
962 break;
965 #endif /* ANIMATIONS */
967 static void flushExpose(void)
969 XEvent tmpev;
971 while (XCheckTypedEvent(dpy, Expose, &tmpev))
972 WMHandleEvent(&tmpev);
973 XSync(dpy, 0);
976 static void unmapTransientsFor(WWindow *wwin)
978 WWindow *tmp;
980 tmp = wwin->screen_ptr->focused_window;
981 while (tmp) {
982 /* unmap the transients for this transient */
983 if (tmp != wwin && tmp->transient_for == wwin->client_win
984 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
985 unmapTransientsFor(tmp);
986 tmp->flags.miniaturized = 1;
987 if (!tmp->flags.shaded) {
988 wWindowUnmap(tmp);
989 } else {
990 XUnmapWindow(dpy, tmp->frame->core->window);
993 if (!tmp->flags.shaded)
995 wClientSetState(tmp, IconicState, None);
997 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
999 tmp = tmp->prev;
1003 static void mapTransientsFor(WWindow *wwin)
1005 WWindow *tmp;
1007 tmp = wwin->screen_ptr->focused_window;
1008 while (tmp) {
1009 /* recursively map the transients for this transient */
1010 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
1011 && tmp->icon == NULL) {
1012 mapTransientsFor(tmp);
1013 tmp->flags.miniaturized = 0;
1014 if (!tmp->flags.shaded) {
1015 wWindowMap(tmp);
1016 } else {
1017 XMapWindow(dpy, tmp->frame->core->window);
1019 tmp->flags.semi_focused = 0;
1021 if (!tmp->flags.shaded)
1023 wClientSetState(tmp, NormalState, None);
1025 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
1027 tmp = tmp->prev;
1031 static WWindow *recursiveTransientFor(WWindow * wwin)
1033 int i;
1035 if (!wwin)
1036 return None;
1038 /* hackish way to detect transient_for cycle */
1039 i = wwin->screen_ptr->window_count + 1;
1041 while (wwin && wwin->transient_for != None && i > 0) {
1042 wwin = wWindowFor(wwin->transient_for);
1043 i--;
1045 if (i == 0 && wwin) {
1046 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
1047 return NULL;
1050 return wwin;
1053 void wIconifyWindow(WWindow * wwin)
1055 XWindowAttributes attribs;
1056 int present;
1058 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs))
1059 return; /* the window doesn't exist anymore */
1061 if (wwin->flags.miniaturized)
1062 return; /* already miniaturized */
1064 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1065 WWindow *owner = wWindowFor(wwin->transient_for);
1067 if (owner && owner->flags.miniaturized)
1068 return;
1071 present = wwin->frame->workspace == w_global.workspace.current;
1073 /* if the window is in another workspace, simplify process */
1074 if (present) {
1075 /* icon creation may take a while */
1076 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
1077 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
1078 GrabModeAsync, None, None, CurrentTime);
1081 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1082 if (!wwin->flags.icon_moved)
1083 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
1085 wwin->icon = icon_create_for_wwindow(wwin);
1086 wwin->icon->mapped = 1;
1089 wwin->flags.miniaturized = 1;
1090 wwin->flags.mapped = 0;
1092 /* unmap transients */
1093 unmapTransientsFor(wwin);
1095 if (present) {
1096 XUngrabPointer(dpy, CurrentTime);
1097 wWindowUnmap(wwin);
1098 /* let all Expose events arrive so that we can repaint
1099 * something before the animation starts (and the server is grabbed) */
1100 XSync(dpy, 0);
1102 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
1103 wClientSetState(wwin, IconicState, None);
1104 else
1105 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
1107 flushExpose();
1108 #ifdef ANIMATIONS
1109 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
1110 && !wPreferences.no_animations) {
1111 int ix, iy, iw, ih;
1113 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1114 ix = wwin->icon_x;
1115 iy = wwin->icon_y;
1116 iw = wwin->icon->core->width;
1117 ih = wwin->icon->core->height;
1118 } else {
1119 if (wwin->flags.net_handle_icon) {
1120 ix = wwin->icon_x;
1121 iy = wwin->icon_y;
1122 iw = wwin->icon_w;
1123 ih = wwin->icon_h;
1124 } else {
1125 ix = 0;
1126 iy = 0;
1127 iw = wwin->screen_ptr->scr_width;
1128 ih = wwin->screen_ptr->scr_height;
1131 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1132 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
1134 #endif
1137 wwin->flags.skip_next_animation = 0;
1139 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1140 if (w_global.workspace.current == wwin->frame->workspace ||
1141 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1142 XMapWindow(dpy, wwin->icon->core->window);
1144 AddToStackList(wwin->icon->core);
1145 wLowerFrame(wwin->icon->core);
1148 if (present) {
1149 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1152 * It doesn't seem to be working and causes button event hangup
1153 * when deiconifying a transient window.
1154 setupIconGrabs(wwin->icon);
1156 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1157 && wPreferences.focus_mode == WKF_CLICK) {
1158 WWindow *tmp;
1160 tmp = wwin->prev;
1161 while (tmp) {
1162 if (!WFLAGP(tmp, no_focusable)
1163 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1164 && (wwin->frame->workspace == tmp->frame->workspace))
1165 break;
1166 tmp = tmp->prev;
1168 wSetFocusTo(wwin->screen_ptr, tmp);
1169 } else if (wPreferences.focus_mode != WKF_CLICK) {
1170 wSetFocusTo(wwin->screen_ptr, NULL);
1172 #ifdef ANIMATIONS
1173 if (!wwin->screen_ptr->flags.startup) {
1174 /* Catch up with events not processed while animation was running */
1175 Window clientwin = wwin->client_win;
1177 ProcessPendingEvents();
1179 /* the window can disappear while ProcessPendingEvents() runs */
1180 if (!wWindowFor(clientwin)) {
1181 return;
1184 #endif
1187 /* maybe we want to do this regardless of net_handle_icon
1188 * it seems to me we might break behaviour this way.
1190 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1191 && !wwin->flags.net_handle_icon)
1192 wIconSelect(wwin->icon);
1194 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1196 if (wPreferences.auto_arrange_icons)
1197 wArrangeIcons(wwin->screen_ptr, True);
1200 void wDeiconifyWindow(WWindow *wwin)
1202 /* Let's avoid changing workspace while deiconifying */
1203 w_global.workspace.ignore_change = True;
1205 /* we're hiding for show_desktop */
1206 int netwm_hidden = wwin->flags.net_show_desktop &&
1207 wwin->frame->workspace != w_global.workspace.current;
1209 if (!netwm_hidden)
1210 wWindowChangeWorkspace(wwin, w_global.workspace.current);
1212 if (!wwin->flags.miniaturized) {
1213 w_global.workspace.ignore_change = False;
1214 return;
1217 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1218 WWindow *owner = recursiveTransientFor(wwin);
1220 if (owner && owner->flags.miniaturized) {
1221 wDeiconifyWindow(owner);
1222 wSetFocusTo(wwin->screen_ptr, wwin);
1223 wRaiseFrame(wwin->frame->core);
1224 w_global.workspace.ignore_change = False;
1225 return;
1229 wwin->flags.miniaturized = 0;
1231 if (!netwm_hidden && !wwin->flags.shaded)
1232 wwin->flags.mapped = 1;
1234 if (!netwm_hidden || wPreferences.sticky_icons) {
1235 /* maybe we want to do this regardless of net_handle_icon
1236 * it seems to me we might break behaviour this way.
1238 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1239 && wwin->icon != NULL) {
1240 if (wwin->icon->selected)
1241 wIconSelect(wwin->icon);
1243 XUnmapWindow(dpy, wwin->icon->core->window);
1247 /* if the window is in another workspace, do it silently */
1248 if (!netwm_hidden) {
1249 #ifdef ANIMATIONS
1250 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1251 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1252 int ix, iy, iw, ih;
1254 if (!wPreferences.disable_miniwindows
1255 && !wwin->flags.net_handle_icon) {
1256 ix = wwin->icon_x;
1257 iy = wwin->icon_y;
1258 iw = wwin->icon->core->width;
1259 ih = wwin->icon->core->height;
1260 } else {
1261 if (wwin->flags.net_handle_icon) {
1262 ix = wwin->icon_x;
1263 iy = wwin->icon_y;
1264 iw = wwin->icon_w;
1265 ih = wwin->icon_h;
1266 } else {
1267 ix = 0;
1268 iy = 0;
1269 iw = wwin->screen_ptr->scr_width;
1270 ih = wwin->screen_ptr->scr_height;
1273 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1274 wwin->frame_x, wwin->frame_y,
1275 wwin->frame->core->width, wwin->frame->core->height);
1277 #endif /* ANIMATIONS */
1278 wwin->flags.skip_next_animation = 0;
1279 XGrabServer(dpy);
1280 if (!wwin->flags.shaded)
1281 XMapWindow(dpy, wwin->client_win);
1283 XMapWindow(dpy, wwin->frame->core->window);
1284 wRaiseFrame(wwin->frame->core);
1285 if (!wwin->flags.shaded)
1286 wClientSetState(wwin, NormalState, None);
1288 mapTransientsFor(wwin);
1291 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1292 && !wwin->flags.net_handle_icon) {
1293 RemoveFromStackList(wwin->icon->core);
1294 /* removeIconGrabs(wwin->icon); */
1295 wIconDestroy(wwin->icon);
1296 wwin->icon = NULL;
1299 if (!netwm_hidden) {
1300 XUngrabServer(dpy);
1302 wSetFocusTo(wwin->screen_ptr, wwin);
1304 #ifdef ANIMATIONS
1305 if (!wwin->screen_ptr->flags.startup) {
1306 /* Catch up with events not processed while animation was running */
1307 Window clientwin = wwin->client_win;
1309 ProcessPendingEvents();
1311 /* the window can disappear while ProcessPendingEvents() runs */
1312 if (!wWindowFor(clientwin)) {
1313 w_global.workspace.ignore_change = False;
1314 return;
1317 #endif
1320 if (wPreferences.auto_arrange_icons)
1321 wArrangeIcons(wwin->screen_ptr, True);
1323 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1325 /* In case we were shaded and iconified, also unshade */
1326 if (!netwm_hidden)
1327 wUnshadeWindow(wwin);
1329 w_global.workspace.ignore_change = False;
1332 static void hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1334 if (wwin->flags.miniaturized) {
1335 if (wwin->icon) {
1336 XUnmapWindow(dpy, wwin->icon->core->window);
1337 wwin->icon->mapped = 0;
1339 wwin->flags.hidden = 1;
1341 WMPostNotificationName(WMNChangedState, wwin, "hide");
1342 return;
1345 if (wwin->flags.inspector_open) {
1346 wHideInspectorForWindow(wwin);
1349 wwin->flags.hidden = 1;
1350 wWindowUnmap(wwin);
1352 wClientSetState(wwin, IconicState, icon->icon_win);
1353 flushExpose();
1355 #ifdef ANIMATIONS
1356 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1357 !wwin->flags.skip_next_animation && animate) {
1358 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1359 wwin->frame->core->width, wwin->frame->core->height,
1360 icon_x, icon_y, icon->core->width, icon->core->height);
1362 #endif
1363 wwin->flags.skip_next_animation = 0;
1365 WMPostNotificationName(WMNChangedState, wwin, "hide");
1368 void wHideAll(WScreen *scr)
1370 WWindow *wwin;
1371 WWindow **windows;
1372 WMenu *menu;
1373 unsigned int wcount = 0;
1374 int i;
1376 if (!scr)
1377 return;
1379 menu = scr->switch_menu;
1381 windows = wmalloc(sizeof(WWindow *));
1383 if (menu != NULL) {
1384 for (i = 0; i < menu->entry_no; i++) {
1385 windows[wcount] = (WWindow *) menu->entries[i]->clientdata;
1386 wcount++;
1387 windows = wrealloc(windows, sizeof(WWindow *) * (wcount + 1));
1389 } else {
1390 wwin = scr->focused_window;
1392 while (wwin) {
1393 windows[wcount] = wwin;
1394 wcount++;
1395 windows = wrealloc(windows, sizeof(WWindow *) * (wcount + 1));
1396 wwin = wwin->prev;
1401 for (i = 0; i < wcount; i++) {
1402 wwin = windows[i];
1403 if (wwin->frame->workspace == w_global.workspace.current
1404 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1405 && !wwin->flags.internal_window
1406 && !WFLAGP(wwin, no_miniaturizable)
1408 wwin->flags.skip_next_animation = 1;
1409 wIconifyWindow(wwin);
1413 wfree(windows);
1416 void wHideOtherApplications(WWindow *awin)
1418 WWindow *wwin;
1419 WApplication *tapp;
1421 if (!awin)
1422 return;
1423 wwin = awin->screen_ptr->focused_window;
1425 while (wwin) {
1426 if (wwin != awin
1427 && wwin->frame->workspace == w_global.workspace.current
1428 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1429 && !wwin->flags.internal_window
1430 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1432 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1433 if (!WFLAGP(wwin, no_miniaturizable)) {
1434 wwin->flags.skip_next_animation = 1;
1435 wIconifyWindow(wwin);
1437 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1438 tapp = wApplicationOf(wwin->main_window);
1439 if (tapp) {
1440 tapp->flags.skip_next_animation = 1;
1441 wHideApplication(tapp);
1442 } else {
1443 if (!WFLAGP(wwin, no_miniaturizable)) {
1444 wwin->flags.skip_next_animation = 1;
1445 wIconifyWindow(wwin);
1450 wwin = wwin->prev;
1453 wSetFocusTo(awin->screen_ptr, awin);
1457 void wHideApplication(WApplication *wapp)
1459 WScreen *scr;
1460 WWindow *wlist;
1461 int hadfocus;
1462 int animate;
1464 if (!wapp) {
1465 wwarning("trying to hide a non grouped window");
1466 return;
1468 if (!wapp->main_window_desc) {
1469 wwarning("group leader not found for window group");
1470 return;
1472 scr = wapp->main_window_desc->screen_ptr;
1473 hadfocus = 0;
1474 wlist = scr->focused_window;
1475 if (!wlist)
1476 return;
1478 if (wlist->main_window == wapp->main_window)
1479 wapp->last_focused = wlist;
1480 else
1481 wapp->last_focused = NULL;
1483 animate = !wapp->flags.skip_next_animation;
1485 while (wlist) {
1486 if (wlist->main_window == wapp->main_window) {
1487 if (wlist->flags.focused) {
1488 hadfocus = 1;
1490 if (wapp->app_icon) {
1491 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1492 wapp->app_icon->y_pos, wlist, animate);
1493 animate = False;
1496 wlist = wlist->prev;
1499 wapp->flags.skip_next_animation = 0;
1501 if (hadfocus) {
1502 if (wPreferences.focus_mode == WKF_CLICK) {
1503 wlist = scr->focused_window;
1504 while (wlist) {
1505 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1506 && (wlist->flags.mapped || wlist->flags.shaded))
1507 break;
1508 wlist = wlist->prev;
1510 wSetFocusTo(scr, wlist);
1511 } else {
1512 wSetFocusTo(scr, NULL);
1516 wapp->flags.hidden = 1;
1518 if (wPreferences.auto_arrange_icons)
1519 wArrangeIcons(scr, True);
1521 #ifdef HIDDENDOT
1522 if (wapp->app_icon)
1523 wAppIconPaint(wapp->app_icon);
1524 #endif
1527 static void unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate, int bringToCurrentWS)
1529 if (bringToCurrentWS)
1530 wWindowChangeWorkspace(wwin, w_global.workspace.current);
1532 wwin->flags.hidden = 0;
1534 #ifdef ANIMATIONS
1535 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1536 animateResize(wwin->screen_ptr, icon_x, icon_y,
1537 icon->core->width, icon->core->height,
1538 wwin->frame_x, wwin->frame_y,
1539 wwin->frame->core->width, wwin->frame->core->height);
1541 #endif
1542 wwin->flags.skip_next_animation = 0;
1543 if (w_global.workspace.current == wwin->frame->workspace) {
1544 XMapWindow(dpy, wwin->client_win);
1545 XMapWindow(dpy, wwin->frame->core->window);
1546 wClientSetState(wwin, NormalState, None);
1547 wwin->flags.mapped = 1;
1548 wRaiseFrame(wwin->frame->core);
1550 if (wwin->flags.inspector_open) {
1551 wUnhideInspectorForWindow(wwin);
1554 WMPostNotificationName(WMNChangedState, wwin, "hide");
1557 void wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1559 WScreen *scr;
1560 WWindow *wlist, *next;
1561 WWindow *focused = NULL;
1562 int animate;
1564 if (!wapp)
1565 return;
1567 scr = wapp->main_window_desc->screen_ptr;
1568 wlist = scr->focused_window;
1569 if (!wlist)
1570 return;
1572 /* goto beginning of list */
1573 while (wlist->prev)
1574 wlist = wlist->prev;
1576 animate = !wapp->flags.skip_next_animation;
1578 while (wlist) {
1579 next = wlist->next;
1581 if (wlist->main_window == wapp->main_window) {
1582 if (wlist->flags.focused)
1583 focused = wlist;
1584 else if (!focused || !focused->flags.focused)
1585 focused = wlist;
1587 if (wlist->flags.miniaturized) {
1588 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1589 wlist->frame->workspace == w_global.workspace.current) && wlist->icon) {
1590 if (!wlist->icon->mapped) {
1591 int x, y;
1593 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1594 if (wlist->icon_x != x || wlist->icon_y != y) {
1595 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1597 wlist->icon_x = x;
1598 wlist->icon_y = y;
1599 XMapWindow(dpy, wlist->icon->core->window);
1600 wlist->icon->mapped = 1;
1602 wRaiseFrame(wlist->icon->core);
1604 if (bringToCurrentWS)
1605 wWindowChangeWorkspace(wlist, w_global.workspace.current);
1606 wlist->flags.hidden = 0;
1607 if (miniwindows && wlist->frame->workspace == w_global.workspace.current) {
1608 wDeiconifyWindow(wlist);
1610 WMPostNotificationName(WMNChangedState, wlist, "hide");
1611 } else if (wlist->flags.shaded) {
1612 if (bringToCurrentWS)
1613 wWindowChangeWorkspace(wlist, w_global.workspace.current);
1614 wlist->flags.hidden = 0;
1615 wRaiseFrame(wlist->frame->core);
1616 if (wlist->frame->workspace == w_global.workspace.current) {
1617 XMapWindow(dpy, wlist->frame->core->window);
1618 if (miniwindows) {
1619 wUnshadeWindow(wlist);
1622 WMPostNotificationName(WMNChangedState, wlist, "hide");
1623 } else if (wlist->flags.hidden) {
1624 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1625 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1626 animate = False;
1627 } else {
1628 if (bringToCurrentWS && wlist->frame->workspace != w_global.workspace.current)
1629 wWindowChangeWorkspace(wlist, w_global.workspace.current);
1631 wRaiseFrame(wlist->frame->core);
1634 wlist = next;
1637 wapp->flags.skip_next_animation = 0;
1638 wapp->flags.hidden = 0;
1640 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1641 wRaiseFrame(wapp->last_focused->frame->core);
1642 wSetFocusTo(scr, wapp->last_focused);
1643 } else if (focused) {
1644 wSetFocusTo(scr, focused);
1646 wapp->last_focused = NULL;
1647 if (wPreferences.auto_arrange_icons)
1648 wArrangeIcons(scr, True);
1650 #ifdef HIDDENDOT
1651 wAppIconPaint(wapp->app_icon);
1652 #endif
1655 void wShowAllWindows(WScreen *scr)
1657 WWindow *wwin, *old_foc;
1658 WApplication *wapp;
1660 old_foc = wwin = scr->focused_window;
1661 while (wwin) {
1662 if (!wwin->flags.internal_window &&
1663 (w_global.workspace.current == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1664 if (wwin->flags.miniaturized) {
1665 wwin->flags.skip_next_animation = 1;
1666 wDeiconifyWindow(wwin);
1667 } else if (wwin->flags.hidden) {
1668 wapp = wApplicationOf(wwin->main_window);
1669 if (wapp) {
1670 wUnhideApplication(wapp, False, False);
1671 } else {
1672 wwin->flags.skip_next_animation = 1;
1673 wDeiconifyWindow(wwin);
1677 wwin = wwin->prev;
1679 wSetFocusTo(scr, old_foc);
1680 /*wRaiseFrame(old_foc->frame->core); */
1683 void wRefreshDesktop(WScreen *scr)
1685 Window win;
1686 XSetWindowAttributes attr;
1688 attr.backing_store = NotUseful;
1689 attr.save_under = False;
1690 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1691 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1692 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1693 XMapRaised(dpy, win);
1694 XDestroyWindow(dpy, win);
1695 XFlush(dpy);
1698 void wArrangeIcons(WScreen *scr, Bool arrangeAll)
1700 WWindow *wwin;
1701 WAppIcon *aicon;
1703 int head;
1704 const int heads = wXineramaHeads(scr);
1706 struct HeadVars {
1707 int pf; /* primary axis */
1708 int sf; /* secondary axis */
1709 int fullW;
1710 int fullH;
1711 int pi, si;
1712 int sx1, sx2, sy1, sy2; /* screen boundary */
1713 int sw, sh;
1714 int xo, yo;
1715 int xs, ys;
1716 } *vars;
1718 int isize = wPreferences.icon_size;
1720 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1722 for (head = 0; head < heads; ++head) {
1723 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1724 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1725 vars[head].pi = vars[head].si = 0;
1726 vars[head].sx1 = rect.pos.x;
1727 vars[head].sy1 = rect.pos.y;
1728 vars[head].sw = rect.size.width;
1729 vars[head].sh = rect.size.height;
1730 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1731 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1732 vars[head].sw = isize * (vars[head].sw / isize);
1733 vars[head].sh = isize * (vars[head].sh / isize);
1734 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1735 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1737 /* icon yard boundaries */
1738 if (wPreferences.icon_yard & IY_VERT) {
1739 vars[head].pf = vars[head].fullH;
1740 vars[head].sf = vars[head].fullW;
1741 } else {
1742 vars[head].pf = vars[head].fullW;
1743 vars[head].sf = vars[head].fullH;
1745 if (wPreferences.icon_yard & IY_RIGHT) {
1746 vars[head].xo = vars[head].sx2 - isize;
1747 vars[head].xs = -1;
1748 } else {
1749 vars[head].xo = vars[head].sx1;
1750 vars[head].xs = 1;
1752 if (wPreferences.icon_yard & IY_TOP) {
1753 vars[head].yo = vars[head].sy1;
1754 vars[head].ys = 1;
1755 } else {
1756 vars[head].yo = vars[head].sy2 - isize;
1757 vars[head].ys = -1;
1761 #define X ((wPreferences.icon_yard & IY_VERT) \
1762 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1763 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1765 #define Y ((wPreferences.icon_yard & IY_VERT) \
1766 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1767 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1769 /* arrange application icons */
1770 aicon = w_global.app_icon_list;
1771 /* reverse them to avoid unnecessarily sliding of icons */
1772 while (aicon && aicon->next)
1773 aicon = aicon->next;
1775 while (aicon) {
1776 if (!aicon->docked) {
1777 /* CHECK: can icon be NULL here ? */
1778 /* The intention here is to place the AppIcon on the head that
1779 * contains most of the applications _main_ window. */
1780 head = wGetHeadForWindow(aicon->icon->owner);
1782 if (aicon->x_pos != X || aicon->y_pos != Y) {
1783 #ifdef ANIMATIONS
1784 if (!wPreferences.no_animations)
1785 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1786 #endif /* ANIMATIONS */
1788 wAppIconMove(aicon, X, Y);
1789 vars[head].pi++;
1790 if (vars[head].pi >= vars[head].pf) {
1791 vars[head].pi = 0;
1792 vars[head].si++;
1795 aicon = aicon->prev;
1798 /* arrange miniwindows */
1799 wwin = scr->focused_window;
1800 /* reverse them to avoid unnecessarily shuffling */
1801 while (wwin && wwin->prev)
1802 wwin = wwin->prev;
1804 while (wwin) {
1805 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1806 (wwin->frame->workspace == w_global.workspace.current ||
1807 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1809 head = wGetHeadForWindow(wwin);
1811 if (arrangeAll || !wwin->flags.icon_moved) {
1812 if (wwin->icon_x != X || wwin->icon_y != Y)
1813 move_window(wwin->icon->core->window, wwin->icon_x, wwin->icon_y, X, Y);
1815 wwin->icon_x = X;
1816 wwin->icon_y = Y;
1818 vars[head].pi++;
1819 if (vars[head].pi >= vars[head].pf) {
1820 vars[head].pi = 0;
1821 vars[head].si++;
1825 if (arrangeAll) {
1826 wwin->flags.icon_moved = 0;
1828 /* we reversed the order, so we use next */
1829 wwin = wwin->next;
1832 wfree(vars);
1835 void wSelectWindow(WWindow *wwin, Bool flag)
1837 WScreen *scr = wwin->screen_ptr;
1839 if (flag) {
1840 wwin->flags.selected = 1;
1841 if (wwin->frame->selected_border_pixel)
1842 XSetWindowBorder(dpy, wwin->frame->core->window, *wwin->frame->selected_border_pixel);
1843 else
1844 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1846 if (!HAS_BORDER(wwin)) {
1847 XSetWindowBorderWidth(dpy, wwin->frame->core->window, wwin->screen_ptr->frame_border_width);
1850 if (!scr->selected_windows)
1851 scr->selected_windows = WMCreateArray(4);
1852 WMAddToArray(scr->selected_windows, wwin);
1853 } else {
1854 wwin->flags.selected = 0;
1855 if (wwin->frame->border_pixel)
1856 XSetWindowBorder(dpy, wwin->frame->core->window, *wwin->frame->border_pixel);
1857 else
1858 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1860 if (!HAS_BORDER(wwin)) {
1861 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1864 if (scr->selected_windows) {
1865 WMRemoveFromArray(scr->selected_windows, wwin);
1870 void wMakeWindowVisible(WWindow *wwin)
1872 if (wwin->frame->workspace != w_global.workspace.current)
1873 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1875 if (wwin->flags.shaded)
1876 wUnshadeWindow(wwin);
1878 if (wwin->flags.hidden) {
1879 WApplication *app;
1881 app = wApplicationOf(wwin->main_window);
1882 if (app) {
1883 /* trick to get focus to this window */
1884 app->last_focused = wwin;
1885 wUnhideApplication(app, False, False);
1888 if (wwin->flags.miniaturized) {
1889 wDeiconifyWindow(wwin);
1890 } else {
1891 if (!WFLAGP(wwin, no_focusable))
1892 wSetFocusTo(wwin->screen_ptr, wwin);
1893 wRaiseFrame(wwin->frame->core);
1898 * Do the animation while shading (called with what = SHADE)
1899 * or unshading (what = UNSHADE).
1901 #ifdef ANIMATIONS
1902 static void shade_animate(WWindow *wwin, Bool what)
1904 int y, s, w, h;
1905 time_t time0 = time(NULL);
1907 if (wwin->flags.skip_next_animation || wPreferences.no_animations)
1908 return;
1910 switch(what) {
1911 case SHADE:
1912 if (!wwin->screen_ptr->flags.startup) {
1913 /* do the shading animation */
1914 h = wwin->frame->core->height;
1915 s = h / SHADE_STEPS;
1916 if (s < 1)
1917 s = 1;
1918 w = wwin->frame->core->width;
1919 y = wwin->frame->top_width;
1920 while (h > wwin->frame->top_width + 1) {
1921 XMoveWindow(dpy, wwin->client_win, 0, y);
1922 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1923 XFlush(dpy);
1925 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1926 break;
1928 if (SHADE_DELAY > 0) {
1929 wusleep(SHADE_DELAY * 1000L);
1930 } else {
1931 wusleep(10);
1933 h -= s;
1934 y -= s;
1936 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1938 break;
1940 case UNSHADE:
1941 h = wwin->frame->top_width + wwin->frame->bottom_width;
1942 y = wwin->frame->top_width - wwin->client.height;
1943 s = abs(y) / SHADE_STEPS;
1944 if (s < 1)
1945 s = 1;
1946 w = wwin->frame->core->width;
1947 XMoveWindow(dpy, wwin->client_win, 0, y);
1948 if (s > 0) {
1949 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1950 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1951 XMoveWindow(dpy, wwin->client_win, 0, y);
1952 XFlush(dpy);
1953 if (SHADE_DELAY > 0) {
1954 wusleep(SHADE_DELAY * 2000L / 3);
1955 } else {
1956 wusleep(10);
1958 h += s;
1959 y += s;
1961 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1962 break;
1965 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1966 break;
1969 #endif