Add support for _NET_WM_FULLSCREEN_MONITORS
[wmaker-crm.git] / src / actions.c
blobc1d61424c33999116b6e10a673b7d3d1a8b550c8
1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
7 * Copyright (c) 2014 Window Maker Team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "wconfig.h"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <math.h>
32 #include <time.h>
34 #include "WindowMaker.h"
35 #include "framewin.h"
36 #include "window.h"
37 #include "client.h"
38 #include "icon.h"
39 #include "colormap.h"
40 #include "application.h"
41 #include "actions.h"
42 #include "stacking.h"
43 #include "appicon.h"
44 #include "dock.h"
45 #include "appmenu.h"
46 #include "winspector.h"
47 #include "workspace.h"
48 #include "xinerama.h"
49 #include "usermenu.h"
50 #include "placement.h"
51 #include "misc.h"
52 #include "event.h"
55 #ifndef HAVE_FLOAT_MATHFUNC
56 #define sinf(x) ((float)sin((double)(x)))
57 #define cosf(x) ((float)cos((double)(x)))
58 #define sqrtf(x) ((float)sqrt((double)(x)))
59 #define atan2f(y, x) ((float)atan((double)(y) / (double)(x)))
60 #endif
62 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
63 unsigned int *new_width, unsigned int *new_height);
64 static void save_old_geometry(WWindow *wwin, int directions);
66 /******* Local Variables *******/
67 #ifdef USE_ANIMATIONS
68 static struct {
69 int steps;
70 int delay;
71 } shadePars[5] = {
72 { SHADE_STEPS_UF, SHADE_DELAY_UF },
73 { SHADE_STEPS_F, SHADE_DELAY_F },
74 { SHADE_STEPS_M, SHADE_DELAY_M },
75 { SHADE_STEPS_S, SHADE_DELAY_S },
76 { SHADE_STEPS_US, SHADE_DELAY_US }
79 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
80 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
81 #endif
83 #define UNSHADE 0
84 #define SHADE 1
86 static int compareTimes(Time t1, Time t2)
88 Time diff;
89 if (t1 == t2)
90 return 0;
91 diff = t1 - t2;
92 return (diff < 60000) ? 1 : -1;
95 #ifdef USE_ANIMATIONS
96 static void shade_animate(WWindow *wwin, Bool what);
97 #else
98 static inline void shade_animate(WWindow *wwin, Bool what)
101 * This function is empty on purpose, so tell the compiler
102 * to not warn about parameters being not used
104 (void) wwin;
105 (void) what;
107 #endif
110 *----------------------------------------------------------------------
111 * wSetFocusTo--
112 * Changes the window focus to the one passed as argument.
113 * If the window to focus is not already focused, it will be brought
114 * to the head of the list of windows. Previously focused window is
115 * unfocused.
117 * Side effects:
118 * Window list may be reordered and the window focus is changed.
120 *----------------------------------------------------------------------
122 void wSetFocusTo(WScreen *scr, WWindow *wwin)
124 static WScreen *old_scr = NULL;
126 WWindow *old_focused;
127 WWindow *focused = scr->focused_window;
128 Time timestamp = w_global.timestamp.last_event;
129 WApplication *oapp = NULL, *napp = NULL;
130 int wasfocused;
132 if (scr->flags.ignore_focus_events || compareTimes(w_global.timestamp.focus_change, timestamp) > 0)
133 return;
135 if (!old_scr)
136 old_scr = scr;
138 old_focused = old_scr->focused_window;
140 w_global.timestamp.focus_change = timestamp;
142 if (old_focused)
143 oapp = wApplicationOf(old_focused->main_window);
145 if (wwin == NULL) {
146 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
147 if (old_focused)
148 wWindowUnfocus(old_focused);
150 if (oapp) {
151 wAppMenuUnmap(oapp->menu);
152 if (wPreferences.highlight_active_app)
153 wApplicationDeactivate(oapp);
156 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
157 return;
160 if (old_scr != scr && old_focused)
161 wWindowUnfocus(old_focused);
163 wasfocused = wwin->flags.focused;
164 napp = wApplicationOf(wwin->main_window);
166 /* remember last workspace where the app has been */
167 if (napp)
168 napp->last_workspace = wwin->frame->workspace;
170 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
171 /* install colormap if colormap mode is lock mode */
172 if (wPreferences.colormap_mode == WCM_CLICK)
173 wColormapInstallForWindow(scr, wwin);
175 /* set input focus */
176 switch (wwin->focus_mode) {
177 case WFM_NO_INPUT:
178 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
179 break;
180 case WFM_PASSIVE:
181 case WFM_LOCALLY_ACTIVE:
182 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
183 break;
184 case WFM_GLOBALLY_ACTIVE:
185 break;
188 XFlush(dpy);
189 if (wwin->protocols.TAKE_FOCUS)
190 wClientSendProtocol(wwin, w_global.atom.wm.take_focus, timestamp);
192 XSync(dpy, False);
193 } else {
194 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
197 if (WFLAGP(wwin, no_focusable))
198 return;
200 /* if this is not the focused window focus it */
201 if (focused != wwin) {
202 /* change the focus window list order */
203 if (wwin->prev)
204 wwin->prev->next = wwin->next;
206 if (wwin->next)
207 wwin->next->prev = wwin->prev;
209 wwin->prev = focused;
210 focused->next = wwin;
211 wwin->next = NULL;
212 scr->focused_window = wwin;
214 if (oapp && oapp != napp) {
215 wAppMenuUnmap(oapp->menu);
216 if (wPreferences.highlight_active_app)
217 wApplicationDeactivate(oapp);
220 /* reset fullscreen if temporarily removed due to lost focus*/
221 if (wwin->flags.fullscreen)
222 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
225 wWindowFocus(wwin, focused);
227 if (napp && !wasfocused) {
228 #ifdef USER_MENU
229 wUserMenuRefreshInstances(napp->menu, wwin);
230 #endif /* USER_MENU */
232 /* kix: Only menu map with mouse, not alt+tab! */
233 if (wwin->flags.mapped)
234 wAppMenuMap(napp->menu, wwin);
236 if (napp && wPreferences.highlight_active_app)
237 wApplicationActivate(napp);
239 XFlush(dpy);
240 old_scr = scr;
243 void wShadeWindow(WWindow *wwin)
246 if (wwin->flags.shaded)
247 return;
249 XLowerWindow(dpy, wwin->client_win);
250 shade_animate(wwin, SHADE);
252 wwin->flags.skip_next_animation = 0;
253 wwin->flags.shaded = 1;
254 wwin->flags.mapped = 0;
255 /* prevent window withdrawal when getting UnmapNotify */
256 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
257 XUnmapWindow(dpy, wwin->client_win);
258 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
260 /* for the client it's just like iconification */
261 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
263 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
264 wWindowSynthConfigureNotify(wwin);
267 wClientSetState(wwin, IconicState, None);
270 WMPostNotificationName(WMNChangedState, wwin, "shade");
272 #ifdef USE_ANIMATIONS
273 if (!wwin->screen_ptr->flags.startup) {
274 /* Catch up with events not processed while animation was running */
275 ProcessPendingEvents();
277 #endif
280 void wUnshadeWindow(WWindow *wwin)
283 if (!wwin->flags.shaded)
284 return;
286 wwin->flags.shaded = 0;
287 wwin->flags.mapped = 1;
288 XMapWindow(dpy, wwin->client_win);
290 shade_animate(wwin, UNSHADE);
292 wwin->flags.skip_next_animation = 0;
293 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
294 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
296 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
297 wWindowSynthConfigureNotify(wwin);
299 /* if the window is focused, set the focus again as it was disabled during
300 * shading */
301 if (wwin->flags.focused)
302 wSetFocusTo(wwin->screen_ptr, wwin);
304 WMPostNotificationName(WMNChangedState, wwin, "shade");
307 /* Set the old coordinates using the current values */
308 static void save_old_geometry(WWindow *wwin, int directions)
310 /* never been saved? */
311 if (!wwin->old_geometry.width)
312 directions |= SAVE_GEOMETRY_X | SAVE_GEOMETRY_WIDTH;
313 if (!wwin->old_geometry.height)
314 directions |= SAVE_GEOMETRY_Y | SAVE_GEOMETRY_HEIGHT;
316 if (directions & SAVE_GEOMETRY_X)
317 wwin->old_geometry.x = wwin->frame_x;
318 if (directions & SAVE_GEOMETRY_Y)
319 wwin->old_geometry.y = wwin->frame_y;
320 if (directions & SAVE_GEOMETRY_WIDTH)
321 wwin->old_geometry.width = wwin->client.width;
322 if (directions & SAVE_GEOMETRY_HEIGHT)
323 wwin->old_geometry.height = wwin->client.height;
326 static void remember_geometry(WWindow *wwin, int *x, int *y, int *w, int *h)
328 WMRect old_geom_rect;
329 int old_head;
330 Bool same_head;
332 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
333 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
334 same_head = (wGetHeadForWindow(wwin) == old_head);
335 *x = ((wwin->old_geometry.x || wwin->old_geometry.width) && same_head) ? wwin->old_geometry.x : wwin->frame_x;
336 *y = ((wwin->old_geometry.y || wwin->old_geometry.height) && same_head) ? wwin->old_geometry.y : wwin->frame_y;
337 *w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
338 *h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
341 /* Remember geometry for unmaximizing */
342 void update_saved_geometry(WWindow *wwin)
344 /* NOT if we aren't already maximized
345 * we'll save geometry when maximizing */
346 if (!wwin->flags.maximized)
347 return;
349 /* NOT if we are fully maximized */
350 if ((wwin->flags.maximized & MAX_MAXIMUS) ||
351 ((wwin->flags.maximized & MAX_HORIZONTAL) &&
352 (wwin->flags.maximized & MAX_VERTICAL)))
353 return;
355 /* save the co-ordinate in the axis in which we AREN'T maximized */
356 if (wwin->flags.maximized & MAX_HORIZONTAL)
357 save_old_geometry(wwin, SAVE_GEOMETRY_Y);
358 if (wwin->flags.maximized & MAX_VERTICAL)
359 save_old_geometry(wwin, SAVE_GEOMETRY_X);
362 void wMaximizeWindow(WWindow *wwin, int directions, int head)
364 unsigned int new_width, new_height, half_scr_width, half_scr_height;
365 int new_x = 0;
366 int new_y = 0;
367 int maximus_x = 0;
368 int maximus_y = 0;
369 unsigned int maximus_width = 0;
370 unsigned int maximus_height = 0;
371 WArea usableArea, totalArea;
372 Bool has_border = 1;
373 int adj_size;
374 WScreen *scr = wwin->screen_ptr;
376 if (!IS_RESIZABLE(wwin))
377 return;
379 if (!HAS_BORDER(wwin))
380 has_border = 0;
382 if (wPreferences.drag_maximized_window == DRAGMAX_NOMOVE)
383 wwin->client_flags.no_movable = 1;
385 /* the size to adjust the geometry */
386 adj_size = scr->frame_border_width * 2 * has_border;
388 /* save old coordinates before we change the current values */
389 if (!wwin->flags.maximized)
390 save_old_geometry(wwin, SAVE_GEOMETRY_ALL);
392 totalArea.x2 = scr->scr_width;
393 totalArea.y2 = scr->scr_height;
394 totalArea.x1 = 0;
395 totalArea.y1 = 0;
397 /* In case of mouse initiated maximize, use the head in which pointer is
398 located, rather than window position, which is passed to the function */
399 if (!(directions & MAX_IGNORE_XINERAMA) && !(directions & MAX_KEYBOARD)) {
400 WScreen *scr = wwin->screen_ptr;
401 head = wGetHeadForPointerLocation(scr);
404 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
406 /* Only save directions, not kbd or xinerama hints */
407 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS);
409 if (WFLAGP(wwin, full_maximize))
410 usableArea = totalArea;
411 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
412 half_scr_height = (usableArea.y2 - usableArea.y1)/2;
414 if (wwin->flags.shaded) {
415 wwin->flags.skip_next_animation = 1;
416 wUnshadeWindow(wwin);
419 if (directions & MAX_MAXIMUS) {
420 find_Maximus_geometry(wwin, usableArea, &maximus_x, &maximus_y, &maximus_width, &maximus_height);
421 new_width = maximus_width - adj_size;
422 new_height = maximus_height - adj_size;
423 new_x = maximus_x;
424 new_y = maximus_y;
425 if (WFLAGP(wwin, full_maximize) && (new_y == 0)) {
426 new_height += wwin->frame->bottom_width - 1;
427 new_y -= wwin->frame->top_width;
430 wwin->maximus_x = new_x;
431 wwin->maximus_y = new_y;
432 wwin->flags.old_maximized |= MAX_MAXIMUS;
433 } else {
434 /* set default values if no option set then */
435 if (!(directions & (MAX_HORIZONTAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS))) {
436 new_width = (wwin->old_geometry.width) ? wwin->old_geometry.width : wwin->frame->core->width;
437 new_x = (wwin->old_geometry.x) ? wwin->old_geometry.x : wwin->frame_x;
439 if (!(directions & (MAX_VERTICAL | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS))) {
440 new_height = (wwin->old_geometry.height) ? wwin->old_geometry.height : wwin->frame->core->height;
441 new_y = (wwin->old_geometry.y) ? wwin->old_geometry.y : wwin->frame_y;
444 /* left|right position */
445 if (directions & MAX_LEFTHALF) {
446 new_width = half_scr_width - adj_size;
447 new_x = usableArea.x1;
448 } else if (directions & MAX_RIGHTHALF) {
449 new_width = half_scr_width - adj_size;
450 new_x = usableArea.x1 + half_scr_width;
452 /* top|bottom position */
453 if (directions & MAX_TOPHALF) {
454 new_height = half_scr_height - adj_size;
455 new_y = usableArea.y1;
456 } else if (directions & MAX_BOTTOMHALF) {
457 new_height = half_scr_height - adj_size;
458 new_y = usableArea.y1 + half_scr_height;
461 /* vertical|horizontal position */
462 if (directions & MAX_HORIZONTAL) {
463 new_width = usableArea.x2 - usableArea.x1 - adj_size;
464 new_x = usableArea.x1;
466 if (directions & MAX_VERTICAL) {
467 new_height = usableArea.y2 - usableArea.y1 - adj_size;
468 new_y = usableArea.y1;
469 if (WFLAGP(wwin, full_maximize) && (new_y == 0))
470 new_y -= wwin->frame->top_width;
474 if (!WFLAGP(wwin, full_maximize) && !(directions == MAX_MAXIMUS || directions == MAX_HORIZONTAL))
475 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
477 /* set maximization state */
478 wwin->flags.maximized = directions;
479 if ((wwin->flags.old_maximized & MAX_MAXIMUS) && !wwin->flags.maximized)
480 wwin->flags.maximized = MAX_MAXIMUS;
482 wWindowConstrainSize(wwin, &new_width, &new_height);
484 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
485 usableArea.y2 - usableArea.y1, &new_width, &new_height);
487 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
488 wWindowSynthConfigureNotify(wwin);
490 WMPostNotificationName(WMNChangedState, wwin, "maximize");
493 /* generic (un)maximizer */
494 void handleMaximize(WWindow *wwin, int directions)
496 int current = wwin->flags.maximized;
497 int requested = directions & (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS);
498 int effective = requested ^ current;
499 int flags = directions & ~requested;
500 int head = wGetHeadForWindow(wwin);
501 int dest_head = -1;
503 if (!effective) {
504 /* allow wMaximizeWindow to restore the Maximusized size */
505 if ((wwin->flags.old_maximized & MAX_MAXIMUS) &&
506 !(requested & MAX_MAXIMUS))
507 wMaximizeWindow(wwin, MAX_MAXIMUS | flags, head);
509 else if (wPreferences.alt_half_maximize &&
510 current & MAX_HORIZONTAL && current & MAX_VERTICAL &&
511 requested & MAX_HORIZONTAL && requested & MAX_VERTICAL)
512 wUnmaximizeWindow(wwin);
514 /* Apply for window state, which is only horizontally or vertically
515 * maximized. Quarters cannot be handled here, since there is not clear
516 * on which direction user intend to move such window. */
517 else if (wPreferences.move_half_max_between_heads &&
518 current & (MAX_VERTICAL | MAX_HORIZONTAL)) {
519 if (requested & MAX_LEFTHALF && current & MAX_LEFTHALF) {
520 dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr,
521 head, DIRECTION_LEFT);
522 if (dest_head != -1) {
523 effective |= MAX_RIGHTHALF;
524 effective |= MAX_VERTICAL;
525 effective &= ~(MAX_HORIZONTAL | MAX_LEFTHALF);
527 } else if (requested & MAX_RIGHTHALF &&
528 current & MAX_RIGHTHALF) {
529 dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr,
530 head, DIRECTION_RIGHT);
531 if (dest_head != -1) {
532 effective |= MAX_LEFTHALF;
533 effective |= MAX_VERTICAL;
534 effective &= ~(MAX_HORIZONTAL | MAX_RIGHTHALF);
536 } else if (requested & MAX_TOPHALF && current & MAX_TOPHALF) {
537 dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr,
538 head, DIRECTION_UP);
539 if (dest_head != -1) {
540 effective |= MAX_BOTTOMHALF;
541 effective |= MAX_HORIZONTAL;
542 effective &= ~(MAX_VERTICAL | MAX_TOPHALF);
544 } else if (requested & MAX_BOTTOMHALF &&
545 current & MAX_BOTTOMHALF) {
546 dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr,
547 head, DIRECTION_DOWN);
548 if (dest_head != -1) {
549 effective |= MAX_TOPHALF;
550 effective |= MAX_HORIZONTAL;
551 effective &= ~(MAX_VERTICAL | MAX_BOTTOMHALF);
556 if (dest_head != -1)
557 /* tell wMaximizeWindow that we were using keyboard, not mouse,
558 * so that it will use calculated head as destination for
559 * move_half_max_between_heads feature, not from mouse pointer */
560 wMaximizeWindow(wwin, (effective | flags | MAX_KEYBOARD),
561 dest_head);
562 else if (!wPreferences.alt_half_maximize)
563 wUnmaximizeWindow(wwin);
565 return;
568 /* these alone mean vertical|horizontal toggle */
569 if ((effective == MAX_LEFTHALF) ||
570 (effective == MAX_RIGHTHALF) ||
571 (effective == MAX_TOPHALF) ||
572 (effective == MAX_BOTTOMHALF))
573 wUnmaximizeWindow(wwin);
575 /* Following conditions might look complicated, but they are really simple:
576 * allow fullscreen transition only for half maximized state (and not
577 * corners) and only when requested state is also half maximized, but on
578 * opposite side of the screen. As for corners, it is similar, but
579 * expected is that only quarter maximized windows on corner can change
580 * its state to half maximized window, depending on direction. Note, that
581 * MAX_KEYBOARD is passed to the wMaximizeWindow function, to preserve the
582 * head, even if mouse was used for triggering the action. */
584 /* Quarters alternative transition. */
585 else if (wPreferences.alt_half_maximize &&
586 ((requested & MAX_LEFTHALF && requested & MAX_TOPHALF &&
587 current & MAX_RIGHTHALF && current & MAX_TOPHALF) ||
588 (requested & MAX_RIGHTHALF && requested & MAX_TOPHALF &&
589 current & MAX_LEFTHALF && current & MAX_TOPHALF)))
590 wMaximizeWindow(wwin, (MAX_TOPHALF | MAX_HORIZONTAL | MAX_KEYBOARD),
591 head);
592 else if (wPreferences.alt_half_maximize &&
593 ((requested & MAX_LEFTHALF && requested & MAX_BOTTOMHALF &&
594 current & MAX_RIGHTHALF && current & MAX_BOTTOMHALF) ||
595 (requested & MAX_RIGHTHALF && requested & MAX_BOTTOMHALF &&
596 current & MAX_LEFTHALF && current & MAX_BOTTOMHALF)))
597 wMaximizeWindow(wwin, (MAX_BOTTOMHALF | MAX_HORIZONTAL | MAX_KEYBOARD),
598 head);
599 else if (wPreferences.alt_half_maximize &&
600 ((requested & MAX_LEFTHALF && requested & MAX_BOTTOMHALF &&
601 current & MAX_LEFTHALF && current & MAX_TOPHALF) ||
602 (requested & MAX_LEFTHALF && requested & MAX_TOPHALF &&
603 current & MAX_LEFTHALF && current & MAX_BOTTOMHALF)))
604 wMaximizeWindow(wwin, (MAX_LEFTHALF | MAX_VERTICAL| MAX_KEYBOARD),
605 head);
606 else if (wPreferences.alt_half_maximize &&
607 ((requested & MAX_RIGHTHALF && requested & MAX_BOTTOMHALF &&
608 current & MAX_RIGHTHALF && current & MAX_TOPHALF) ||
609 (requested & MAX_RIGHTHALF && requested & MAX_TOPHALF &&
610 current & MAX_RIGHTHALF && current & MAX_BOTTOMHALF)))
611 wMaximizeWindow(wwin, (MAX_RIGHTHALF | MAX_VERTICAL| MAX_KEYBOARD),
612 head);
614 /* Half-maximized alternative transition */
615 else if (wPreferences.alt_half_maximize && (
616 (requested & MAX_LEFTHALF && requested & MAX_VERTICAL &&
617 current & MAX_RIGHTHALF && current & MAX_VERTICAL) ||
618 (requested & MAX_RIGHTHALF && requested & MAX_VERTICAL &&
619 current & MAX_LEFTHALF && current & MAX_VERTICAL) ||
620 (requested & MAX_TOPHALF && requested & MAX_HORIZONTAL &&
621 current & MAX_BOTTOMHALF && current & MAX_HORIZONTAL) ||
622 (requested & MAX_BOTTOMHALF && requested & MAX_HORIZONTAL &&
623 current & MAX_TOPHALF && current & MAX_HORIZONTAL)))
624 wMaximizeWindow(wwin, (MAX_HORIZONTAL|MAX_VERTICAL|MAX_KEYBOARD),
625 head);
627 else {
628 if ((requested == (MAX_HORIZONTAL | MAX_VERTICAL)) ||
629 (requested == MAX_MAXIMUS))
630 effective = requested;
631 else {
632 if (requested & MAX_LEFTHALF) {
633 if (!(requested & (MAX_TOPHALF | MAX_BOTTOMHALF)))
634 effective |= MAX_VERTICAL;
635 else
636 effective |= requested & (MAX_TOPHALF | MAX_BOTTOMHALF);
637 effective |= MAX_LEFTHALF;
638 effective &= ~(MAX_HORIZONTAL | MAX_RIGHTHALF);
639 } else if (requested & MAX_RIGHTHALF) {
640 if (!(requested & (MAX_TOPHALF | MAX_BOTTOMHALF)))
641 effective |= MAX_VERTICAL;
642 else
643 effective |= requested & (MAX_TOPHALF | MAX_BOTTOMHALF);
644 effective |= MAX_RIGHTHALF;
645 effective &= ~(MAX_HORIZONTAL | MAX_LEFTHALF);
647 if (requested & MAX_TOPHALF) {
648 if (!(requested & (MAX_LEFTHALF | MAX_RIGHTHALF)))
649 effective |= MAX_HORIZONTAL;
650 else
651 effective |= requested & (MAX_LEFTHALF | MAX_RIGHTHALF);
652 effective |= MAX_TOPHALF;
653 effective &= ~(MAX_VERTICAL | MAX_BOTTOMHALF);
654 } else if (requested & MAX_BOTTOMHALF) {
655 if (!(requested & (MAX_LEFTHALF | MAX_RIGHTHALF)))
656 effective |= MAX_HORIZONTAL;
657 else
658 effective |= requested & (MAX_LEFTHALF | MAX_RIGHTHALF);
659 effective |= MAX_BOTTOMHALF;
660 effective &= ~(MAX_VERTICAL | MAX_TOPHALF);
662 if (requested & MAX_HORIZONTAL)
663 effective &= ~(MAX_LEFTHALF | MAX_RIGHTHALF);
664 if (requested & MAX_VERTICAL)
665 effective &= ~(MAX_TOPHALF | MAX_BOTTOMHALF);
666 effective &= ~MAX_MAXIMUS;
668 wMaximizeWindow(wwin, effective | flags, head);
672 /* Moving window between heads
674 * Window is moved between all avaiable heads for current screen in
675 * requested direction.
677 * If heads have different sizes, window position will be adjusted to be inside
678 * screen. Window will be unmaximized on move, so that it can be immediately be
679 * maximixed by another shortcut.
682 * direction = 0 means move clock-wise from 12h position to 6h
683 * (first try moving right, then bottom, then left, then up)
684 * direction = 1 means move clock-wise from 6h position to 12h
685 * (first try moving left, then up, then right, then bottom)
688 * As side effect this mean if you have 9 monitors - you will not be able to
689 * move window into central cell without mouse.
691 * For common cases with 1 or 2 extra monitors this should work just fine.
693 * */
695 void moveBetweenHeads(WWindow *wwin, int direction)
697 int head = wGetHeadForWindow(wwin);
698 int destHead = -1;
700 unsigned int new_width, new_height;
701 int offsetX, newX = 0;
702 int offsetY, newY = 0;
703 WArea totalArea, oldHeadArea, destHeadArea;
704 WScreen *scr = wwin->screen_ptr;
706 int try_movements[2][4] = {
707 {DIRECTION_RIGHT, DIRECTION_DOWN, DIRECTION_LEFT, DIRECTION_UP},
708 {DIRECTION_LEFT, DIRECTION_UP, DIRECTION_RIGHT, DIRECTION_DOWN}
711 /* loop through directions array and try movements until one works */
712 for (int try_movement_idx = 0;
713 destHead == -1 && try_movement_idx < 4; try_movement_idx++) {
714 destHead = wGetHeadRelativeToCurrentHead(wwin->screen_ptr,
715 head, try_movements[direction][try_movement_idx]);
718 if (destHead != -1) {
719 totalArea.x1 = 0;
720 totalArea.y1 = 0;
721 totalArea.x2 = scr->scr_width;
722 totalArea.y2 = scr->scr_height;
724 oldHeadArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
725 destHeadArea = wGetUsableAreaForHead(scr, destHead, &totalArea, True);
727 offsetX = wwin->frame_x - oldHeadArea.x1;
728 offsetY = wwin->frame_y - oldHeadArea.y1;
730 newX = destHeadArea.x1 + offsetX;
731 newY = destHeadArea.y1 + offsetY;
733 new_width = wwin->client.width;
734 new_height = wwin->client.height;
736 /* try to brind window inside head coordinates */
737 if (newX > destHeadArea.x2)
738 newX = destHeadArea.x2 - wwin->client.width;
740 if (newX < destHeadArea.x1)
741 newX = destHeadArea.x1;
743 if (newY > destHeadArea.y2)
744 newY = destHeadArea.y2 - wwin->client.height;
746 if (newY < destHeadArea.y1)
747 newY = destHeadArea.y1;
749 /* unset maximization state */
750 wwin->flags.maximized = 0;
751 wWindowConfigure(wwin, newX, newY, new_width, new_height);
754 return;
757 /* the window boundary coordinates */
758 typedef struct {
759 int left;
760 int right;
761 int bottom;
762 int top;
763 int width;
764 int height;
765 } win_coords;
767 static void set_window_coords(WWindow *wwin, win_coords *obs)
769 obs->left = wwin->frame_x;
770 obs->top = wwin->frame_y;
771 obs->width = wwin->frame->core->width;
772 obs->height = wwin->frame->core->height;
773 obs->bottom = obs->top + obs->height;
774 obs->right = obs->left + obs->width;
778 * Maximus: tiled maximization (maximize without overlapping other windows)
780 * The original window 'orig' will be maximized to new coordinates 'new'.
781 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
783 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
784 unsigned int *new_width, unsigned int *new_height)
786 WWindow *tmp;
787 short int tbar_height_0 = 0, rbar_height_0 = 0, bd_width_0 = 0;
788 short int adjust_height;
789 int x_intsect, y_intsect;
790 /* the obstructing, original and new windows */
791 win_coords obs, orig, new;
793 /* set the original coordinate positions of the window to be Maximumized */
794 if (wwin->flags.maximized) {
795 /* window is already maximized; consider original geometry */
796 remember_geometry(wwin, &orig.left, &orig.top, &orig.width, &orig.height);
797 orig.bottom = orig.top + orig.height;
798 orig.right = orig.left + orig.width;
799 } else
800 set_window_coords(wwin, &orig);
802 /* Try to fully maximize first, then readjust later */
803 new.left = usableArea.x1;
804 new.right = usableArea.x2;
805 new.top = usableArea.y1;
806 new.bottom = usableArea.y2;
808 if (HAS_TITLEBAR(wwin))
809 tbar_height_0 = TITLEBAR_HEIGHT;
810 if (HAS_RESIZEBAR(wwin))
811 rbar_height_0 = RESIZEBAR_HEIGHT;
812 if (HAS_BORDER(wwin))
813 bd_width_0 = wwin->screen_ptr->frame_border_width;
815 /* the length to be subtracted if the window has titlebar, etc */
816 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
818 tmp = wwin;
819 /* The focused window is always the last in the list */
820 while (tmp->prev) {
821 /* ignore windows in other workspaces etc */
822 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
823 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
824 tmp = tmp->prev;
825 continue;
827 tmp = tmp->prev;
829 /* Set the coordinates of obstructing window */
830 set_window_coords(tmp, &obs);
832 /* Try to maximize in the y direction first */
833 x_intsect = calcIntersectionLength(orig.left, orig.width, obs.left, obs.width);
834 if (x_intsect != 0) {
835 /* TODO: Consider the case when coords are equal */
836 if (obs.bottom < orig.top && obs.bottom > new.top) {
837 /* w_0 is below the bottom of w_j */
838 new.top = obs.bottom + 1;
840 if (orig.bottom < obs.top && obs.top < new.bottom) {
841 /* The bottom of w_0 is above the top of w_j */
842 new.bottom = obs.top - 1;
847 tmp = wwin;
848 while (tmp->prev) {
849 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
850 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
851 tmp = tmp->prev;
852 continue;
854 tmp = tmp->prev;
856 set_window_coords(tmp, &obs);
859 * Use the new.top and new.height instead of original values
860 * as they may have different intersections with the obstructing windows
862 new.height = new.bottom - new.top - adjust_height;
863 y_intsect = calcIntersectionLength(new.top, new.height, obs.top, obs.height);
864 if (y_intsect != 0) {
865 if (obs.right < orig.left && obs.right > new.left) {
866 /* w_0 is completely to the right of w_j */
867 new.left = obs.right + 1;
869 if (orig.right < obs.left && obs.left < new.right) {
870 /* w_0 is completely to the left of w_j */
871 new.right = obs.left - 1;
876 *new_x = new.left;
877 *new_y = new.top;
878 /* xcalc needs -7 here, but other apps don't */
879 *new_height = new.bottom - new.top - adjust_height - 1;
880 *new_width = new.right - new.left;
883 void wUnmaximizeWindow(WWindow *wwin)
885 int x, y, w, h;
887 if (!wwin->flags.maximized)
888 return;
890 if (wwin->flags.shaded) {
891 wwin->flags.skip_next_animation = 1;
892 wUnshadeWindow(wwin);
895 if (wPreferences.drag_maximized_window == DRAGMAX_NOMOVE)
896 wwin->client_flags.no_movable = 0;
898 /* Use old coordinates if they are set, current values otherwise */
899 remember_geometry(wwin, &x, &y, &w, &h);
901 /* unMaximusize relative to original position */
902 if (wwin->flags.maximized & MAX_MAXIMUS) {
903 x += wwin->frame_x - wwin->maximus_x;
904 y += wwin->frame_y - wwin->maximus_y;
907 wwin->flags.maximized = 0;
908 wwin->flags.old_maximized = 0;
909 wWindowConfigure(wwin, x, y, w, h);
910 wWindowSynthConfigureNotify(wwin);
912 WMPostNotificationName(WMNChangedState, wwin, "maximize");
915 #ifdef USE_XINERAMA
916 void wFullscreenMonitorsWindow(WWindow *wwin, unsigned long top, unsigned long bottom,
917 unsigned long left, unsigned long right)
919 int i;
920 long monitor;
921 WMRect rect1, rect2;
923 if ((int)top < wwin->screen_ptr->xine_info.count &&
924 (int)bottom < wwin->screen_ptr->xine_info.count &&
925 (int)left < wwin->screen_ptr->xine_info.count &&
926 (int)right < wwin->screen_ptr->xine_info.count) {
927 wwin->flags.fullscreen_monitors[0] = top;
928 wwin->flags.fullscreen_monitors[1] = bottom;
929 wwin->flags.fullscreen_monitors[2] = left;
930 wwin->flags.fullscreen_monitors[3] = right;
931 } else {
932 wwin->flags.fullscreen_monitors[0] = -1;
933 return;
936 wwin->flags.fullscreen = True;
937 wWindowConfigureBorders(wwin);
938 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
940 wwin->bfs_geometry.x = wwin->frame_x;
941 wwin->bfs_geometry.y = wwin->frame_y;
942 wwin->bfs_geometry.width = wwin->frame->core->width;
943 wwin->bfs_geometry.height = wwin->frame->core->height;
945 i = 0;
946 monitor = wwin->flags.fullscreen_monitors[i];
947 rect1 = wwin->screen_ptr->xine_info.screens[monitor];
949 for (i = 1; i <= 3; i++) {
950 monitor = wwin->flags.fullscreen_monitors[i];
951 rect2 = wwin->screen_ptr->xine_info.screens[monitor];
952 wGetRectUnion(&rect1, &rect2, &rect1);
954 wWindowConfigure(wwin, rect1.pos.x, rect1.pos.y, rect1.size.width, rect1.size.height);
956 wwin->screen_ptr->bfs_focused_window = wwin->screen_ptr->focused_window;
957 wSetFocusTo(wwin->screen_ptr, wwin);
959 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
961 #endif
963 void wFullscreenWindow(WWindow *wwin)
965 int head;
966 WMRect rect;
968 if (wwin->flags.fullscreen)
969 return;
971 wwin->flags.fullscreen = True;
973 wWindowConfigureBorders(wwin);
975 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
977 wwin->bfs_geometry.x = wwin->frame_x;
978 wwin->bfs_geometry.y = wwin->frame_y;
979 wwin->bfs_geometry.width = wwin->frame->core->width;
980 wwin->bfs_geometry.height = wwin->frame->core->height;
982 head = wGetHeadForWindow(wwin);
983 rect = wGetRectForHead(wwin->screen_ptr, head);
984 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
986 wwin->screen_ptr->bfs_focused_window = wwin->screen_ptr->focused_window;
987 wSetFocusTo(wwin->screen_ptr, wwin);
989 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
992 void wUnfullscreenWindow(WWindow *wwin)
994 if (!wwin->flags.fullscreen)
995 return;
997 wwin->flags.fullscreen = False;
999 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
1000 if (WFLAGP(wwin, sunken)) {
1001 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
1002 } else if (WFLAGP(wwin, floating)) {
1003 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
1004 } else {
1005 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
1009 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
1010 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
1012 wWindowConfigureBorders(wwin);
1014 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
1015 wFrameWindowPaint(wwin->frame);
1018 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
1020 if (wwin->screen_ptr->bfs_focused_window) {
1021 wSetFocusTo(wwin->screen_ptr, wwin->screen_ptr->bfs_focused_window);
1022 wwin->screen_ptr->bfs_focused_window = NULL;
1026 #ifdef USE_ANIMATIONS
1027 static void animateResizeFlip(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
1029 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
1030 float cx, cy, cw, ch;
1031 float xstep, ystep, wstep, hstep;
1032 XPoint points[5];
1033 float dx, dch, midy;
1034 float angle, final_angle, delta;
1036 xstep = (float)(fx - x) / steps;
1037 ystep = (float)(fy - y) / steps;
1038 wstep = (float)(fw - w) / steps;
1039 hstep = (float)(fh - h) / steps;
1041 cx = (float)x;
1042 cy = (float)y;
1043 cw = (float)w;
1044 ch = (float)h;
1046 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
1047 delta = (float)(final_angle / FRAMES);
1048 for (angle = 0;; angle += delta) {
1049 if (angle > final_angle)
1050 angle = final_angle;
1052 dx = (cw / 10) - ((cw / 5) * sinf(angle));
1053 dch = (ch / 2) * cosf(angle);
1054 midy = cy + (ch / 2);
1056 points[0].x = cx + dx;
1057 points[0].y = midy - dch;
1058 points[1].x = cx + cw - dx;
1059 points[1].y = points[0].y;
1060 points[2].x = cx + cw + dx;
1061 points[2].y = midy + dch;
1062 points[3].x = cx - dx;
1063 points[3].y = points[2].y;
1064 points[4].x = points[0].x;
1065 points[4].y = points[0].y;
1067 XGrabServer(dpy);
1068 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
1069 XFlush(dpy);
1070 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
1072 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
1073 XUngrabServer(dpy);
1074 cx += xstep;
1075 cy += ystep;
1076 cw += wstep;
1077 ch += hstep;
1078 if (angle >= final_angle)
1079 break;
1082 XFlush(dpy);
1085 #undef FRAMES
1087 static void
1088 animateResizeTwist(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
1090 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
1091 float cx, cy, cw, ch;
1092 float xstep, ystep, wstep, hstep;
1093 XPoint points[5];
1094 float angle, final_angle, a, d, delta;
1096 x += w / 2;
1097 y += h / 2;
1098 fx += fw / 2;
1099 fy += fh / 2;
1101 xstep = (float)(fx - x) / steps;
1102 ystep = (float)(fy - y) / steps;
1103 wstep = (float)(fw - w) / steps;
1104 hstep = (float)(fh - h) / steps;
1106 cx = (float)x;
1107 cy = (float)y;
1108 cw = (float)w;
1109 ch = (float)h;
1111 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
1112 delta = (float)(final_angle / FRAMES);
1113 for (angle = 0;; angle += delta) {
1114 if (angle > final_angle)
1115 angle = final_angle;
1117 a = atan2f(ch, cw);
1118 d = sqrtf((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
1120 points[0].x = cx + cosf(angle - a) * d;
1121 points[0].y = cy + sinf(angle - a) * d;
1122 points[1].x = cx + cosf(angle + a) * d;
1123 points[1].y = cy + sinf(angle + a) * d;
1124 points[2].x = cx + cosf(angle - a + (float)WM_PI) * d;
1125 points[2].y = cy + sinf(angle - a + (float)WM_PI) * d;
1126 points[3].x = cx + cosf(angle + a + (float)WM_PI) * d;
1127 points[3].y = cy + sinf(angle + a + (float)WM_PI) * d;
1128 points[4].x = cx + cosf(angle - a) * d;
1129 points[4].y = cy + sinf(angle - a) * d;
1130 XGrabServer(dpy);
1131 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
1132 XFlush(dpy);
1133 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
1135 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
1136 XUngrabServer(dpy);
1137 cx += xstep;
1138 cy += ystep;
1139 cw += wstep;
1140 ch += hstep;
1141 if (angle >= final_angle)
1142 break;
1145 XFlush(dpy);
1148 #undef FRAMES
1150 static void animateResizeZoom(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
1152 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
1153 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
1154 float xstep, ystep, wstep, hstep;
1155 int i, j;
1157 xstep = (float)(fx - x) / steps;
1158 ystep = (float)(fy - y) / steps;
1159 wstep = (float)(fw - w) / steps;
1160 hstep = (float)(fh - h) / steps;
1162 for (j = 0; j < FRAMES; j++) {
1163 cx[j] = (float)x;
1164 cy[j] = (float)y;
1165 cw[j] = (float)w;
1166 ch[j] = (float)h;
1168 XGrabServer(dpy);
1169 for (i = 0; i < steps; i++) {
1170 for (j = 0; j < FRAMES; j++) {
1171 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
1172 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
1174 XFlush(dpy);
1175 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
1177 for (j = 0; j < FRAMES; j++) {
1178 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
1179 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
1180 if (j < FRAMES - 1) {
1181 cx[j] = cx[j + 1];
1182 cy[j] = cy[j + 1];
1183 cw[j] = cw[j + 1];
1184 ch[j] = ch[j + 1];
1185 } else {
1186 cx[j] += xstep;
1187 cy[j] += ystep;
1188 cw[j] += wstep;
1189 ch[j] += hstep;
1194 for (j = 0; j < FRAMES; j++)
1195 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
1196 XFlush(dpy);
1197 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
1199 for (j = 0; j < FRAMES; j++)
1200 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
1202 XUngrabServer(dpy);
1205 #undef FRAMES
1207 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
1209 int style = wPreferences.iconification_style; /* Catch the value */
1210 int steps;
1212 if (style == WIS_NONE)
1213 return;
1215 if (style == WIS_RANDOM)
1216 style = rand() % 3;
1218 switch (style) {
1219 case WIS_TWIST:
1220 steps = MINIATURIZE_ANIMATION_STEPS_T;
1221 if (steps > 0)
1222 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
1223 break;
1224 case WIS_FLIP:
1225 steps = MINIATURIZE_ANIMATION_STEPS_F;
1226 if (steps > 0)
1227 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
1228 break;
1229 case WIS_ZOOM:
1230 default:
1231 steps = MINIATURIZE_ANIMATION_STEPS_Z;
1232 if (steps > 0)
1233 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
1234 break;
1237 #endif /* USE_ANIMATIONS */
1239 static void flushExpose(void)
1241 XEvent tmpev;
1243 while (XCheckTypedEvent(dpy, Expose, &tmpev))
1244 WMHandleEvent(&tmpev);
1245 XSync(dpy, 0);
1248 static void unmapTransientsFor(WWindow *wwin)
1250 WWindow *tmp;
1252 tmp = wwin->screen_ptr->focused_window;
1253 while (tmp) {
1254 /* unmap the transients for this transient */
1255 if (tmp != wwin && tmp->transient_for == wwin->client_win
1256 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
1257 unmapTransientsFor(tmp);
1258 tmp->flags.miniaturized = 1;
1259 if (!tmp->flags.shaded)
1260 wWindowUnmap(tmp);
1261 else
1262 XUnmapWindow(dpy, tmp->frame->core->window);
1264 if (!tmp->flags.shaded)
1266 wClientSetState(tmp, IconicState, None);
1268 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
1270 tmp = tmp->prev;
1274 static void mapTransientsFor(WWindow *wwin)
1276 WWindow *tmp;
1278 tmp = wwin->screen_ptr->focused_window;
1279 while (tmp) {
1280 /* recursively map the transients for this transient */
1281 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
1282 && tmp->icon == NULL) {
1283 mapTransientsFor(tmp);
1284 tmp->flags.miniaturized = 0;
1285 if (!tmp->flags.shaded)
1286 wWindowMap(tmp);
1287 else
1288 XMapWindow(dpy, tmp->frame->core->window);
1289 tmp->flags.semi_focused = 0;
1291 if (!tmp->flags.shaded)
1293 wClientSetState(tmp, NormalState, None);
1295 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
1297 tmp = tmp->prev;
1301 static WWindow *recursiveTransientFor(WWindow *wwin)
1303 int i;
1305 if (!wwin)
1306 return None;
1308 /* hackish way to detect transient_for cycle */
1309 i = wwin->screen_ptr->window_count + 1;
1311 while (wwin && wwin->transient_for != None && i > 0) {
1312 wwin = wWindowFor(wwin->transient_for);
1313 i--;
1315 if (i == 0 && wwin) {
1316 wwarning(_("window \"%s\" has a severely broken WM_TRANSIENT_FOR hint"),
1317 wwin->frame->title);
1318 return NULL;
1321 return wwin;
1324 #ifdef USE_ANIMATIONS
1325 static int getAnimationGeometry(WWindow *wwin, int *ix, int *iy, int *iw, int *ih)
1327 if (wwin->screen_ptr->flags.startup || wPreferences.no_animations
1328 || wwin->flags.skip_next_animation || wwin->icon == NULL)
1329 return 0;
1331 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1332 *ix = wwin->icon_x;
1333 *iy = wwin->icon_y;
1334 *iw = wwin->icon->core->width;
1335 *ih = wwin->icon->core->height;
1336 } else {
1337 if (wwin->flags.net_handle_icon) {
1338 *ix = wwin->icon_x;
1339 *iy = wwin->icon_y;
1340 *iw = wwin->icon_w;
1341 *ih = wwin->icon_h;
1342 } else {
1343 *ix = 0;
1344 *iy = 0;
1345 *iw = wwin->screen_ptr->scr_width;
1346 *ih = wwin->screen_ptr->scr_height;
1349 return 1;
1351 #endif /* USE_ANIMATIONS */
1353 void wIconifyWindow(WWindow *wwin)
1355 XWindowAttributes attribs;
1356 int present;
1358 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs))
1359 return; /* the window doesn't exist anymore */
1361 if (wwin->flags.miniaturized)
1362 return; /* already miniaturized */
1364 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1365 WWindow *owner = wWindowFor(wwin->transient_for);
1367 if (owner && owner->flags.miniaturized)
1368 return;
1371 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
1373 /* if the window is in another workspace, simplify process */
1374 if (present) {
1375 /* icon creation may take a while */
1376 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
1377 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
1378 GrabModeAsync, None, None, CurrentTime);
1381 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1382 if (!wwin->flags.icon_moved)
1383 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
1385 wwin->icon = icon_create_for_wwindow(wwin);
1386 wwin->icon->mapped = 1;
1388 /* extract the window screenshot every time, as the option can be enable anytime */
1389 if (wwin->client_win && wwin->flags.mapped) {
1390 RImage *mini_preview;
1391 XImage *pimg;
1392 unsigned int w, h;
1393 int x, y;
1394 Window baz;
1396 XRaiseWindow(dpy, wwin->frame->core->window);
1397 XTranslateCoordinates(dpy, wwin->client_win, wwin->screen_ptr->root_win, 0, 0, &x, &y, &baz);
1399 w = attribs.width;
1400 h = attribs.height;
1402 if (x - attribs.x + attribs.width > wwin->screen_ptr->scr_width)
1403 w = wwin->screen_ptr->scr_width - x + attribs.x;
1405 if (y - attribs.y + attribs.height > wwin->screen_ptr->scr_height)
1406 h = wwin->screen_ptr->scr_height - y + attribs.y;
1408 pimg = XGetImage(dpy, wwin->client_win, 0, 0, w, h, AllPlanes, ZPixmap);
1409 if (pimg) {
1410 mini_preview = RCreateImageFromXImage(wwin->screen_ptr->rcontext, pimg, NULL);
1411 XDestroyImage(pimg);
1413 if (mini_preview) {
1414 set_icon_minipreview(wwin->icon, mini_preview);
1415 RReleaseImage(mini_preview);
1416 } else {
1417 const char *title;
1418 char title_buf[32];
1420 if (wwin->frame->title) {
1421 title = wwin->frame->title;
1422 } else {
1423 snprintf(title_buf, sizeof(title_buf), "(id=0x%lx)", wwin->client_win);
1424 title = title_buf;
1426 wwarning(_("creation of mini-preview failed for window \"%s\""), title);
1432 wwin->flags.miniaturized = 1;
1433 wwin->flags.mapped = 0;
1435 /* unmap transients */
1436 unmapTransientsFor(wwin);
1438 if (present) {
1439 #ifdef USE_ANIMATIONS
1440 int ix, iy, iw, ih;
1441 #endif
1442 XUngrabPointer(dpy, CurrentTime);
1443 wWindowUnmap(wwin);
1444 /* let all Expose events arrive so that we can repaint
1445 * something before the animation starts (and the server is grabbed) */
1446 XSync(dpy, 0);
1448 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
1449 wClientSetState(wwin, IconicState, None);
1450 else
1451 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
1453 flushExpose();
1454 #ifdef USE_ANIMATIONS
1455 if (getAnimationGeometry(wwin, &ix, &iy, &iw, &ih))
1456 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1457 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
1458 #endif
1461 wwin->flags.skip_next_animation = 0;
1463 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1464 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
1465 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1466 XMapWindow(dpy, wwin->icon->core->window);
1468 AddToStackList(wwin->icon->core);
1469 wLowerFrame(wwin->icon->core);
1472 if (present) {
1473 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1476 * It doesn't seem to be working and causes button event hangup
1477 * when deiconifying a transient window.
1478 setupIconGrabs(wwin->icon);
1480 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1481 && wPreferences.focus_mode == WKF_CLICK) {
1482 WWindow *tmp;
1484 tmp = wwin->prev;
1485 while (tmp) {
1486 if (!WFLAGP(tmp, no_focusable)
1487 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1488 && (wwin->frame->workspace == tmp->frame->workspace))
1489 break;
1490 tmp = tmp->prev;
1492 wSetFocusTo(wwin->screen_ptr, tmp);
1493 } else if (wPreferences.focus_mode != WKF_CLICK) {
1494 wSetFocusTo(wwin->screen_ptr, NULL);
1496 #ifdef USE_ANIMATIONS
1497 if (!wwin->screen_ptr->flags.startup) {
1498 /* Catch up with events not processed while animation was running */
1499 Window clientwin = wwin->client_win;
1501 ProcessPendingEvents();
1503 /* the window can disappear while ProcessPendingEvents() runs */
1504 if (!wWindowFor(clientwin))
1505 return;
1507 #endif
1510 /* maybe we want to do this regardless of net_handle_icon
1511 * it seems to me we might break behaviour this way.
1513 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1514 && !wwin->flags.net_handle_icon)
1515 wIconSelect(wwin->icon);
1517 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1519 if (wPreferences.auto_arrange_icons)
1520 wArrangeIcons(wwin->screen_ptr, True);
1523 void wDeiconifyWindow(WWindow *wwin)
1525 /* Let's avoid changing workspace while deiconifying */
1526 w_global.ignore_workspace_change = True;
1528 /* we're hiding for show_desktop */
1529 int netwm_hidden = wwin->flags.net_show_desktop &&
1530 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1532 if (!netwm_hidden)
1533 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1535 if (!wwin->flags.miniaturized) {
1536 w_global.ignore_workspace_change = False;
1537 return;
1540 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1541 WWindow *owner = recursiveTransientFor(wwin);
1543 if (owner && owner->flags.miniaturized) {
1544 wDeiconifyWindow(owner);
1545 wSetFocusTo(wwin->screen_ptr, wwin);
1546 wRaiseFrame(wwin->frame->core);
1547 w_global.ignore_workspace_change = False;
1548 return;
1552 wwin->flags.miniaturized = 0;
1554 if (!netwm_hidden && !wwin->flags.shaded)
1555 wwin->flags.mapped = 1;
1557 if (!netwm_hidden || wPreferences.sticky_icons) {
1558 /* maybe we want to do this regardless of net_handle_icon
1559 * it seems to me we might break behaviour this way.
1561 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1562 && wwin->icon != NULL) {
1563 if (wwin->icon->selected)
1564 wIconSelect(wwin->icon);
1566 XUnmapWindow(dpy, wwin->icon->core->window);
1570 /* if the window is in another workspace, do it silently */
1571 if (!netwm_hidden) {
1572 #ifdef USE_ANIMATIONS
1573 int ix, iy, iw, ih;
1574 if (getAnimationGeometry(wwin, &ix, &iy, &iw, &ih))
1575 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1576 wwin->frame_x, wwin->frame_y,
1577 wwin->frame->core->width, wwin->frame->core->height);
1578 #endif
1579 wwin->flags.skip_next_animation = 0;
1580 XGrabServer(dpy);
1581 if (!wwin->flags.shaded)
1582 XMapWindow(dpy, wwin->client_win);
1584 XMapWindow(dpy, wwin->frame->core->window);
1585 wRaiseFrame(wwin->frame->core);
1586 if (!wwin->flags.shaded)
1587 wClientSetState(wwin, NormalState, None);
1589 mapTransientsFor(wwin);
1592 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1593 && !wwin->flags.net_handle_icon) {
1594 RemoveFromStackList(wwin->icon->core);
1595 wSetFocusTo(wwin->screen_ptr, wwin);
1596 wIconDestroy(wwin->icon);
1597 wwin->icon = NULL;
1600 if (!netwm_hidden) {
1601 XUngrabServer(dpy);
1603 wSetFocusTo(wwin->screen_ptr, wwin);
1605 #ifdef USE_ANIMATIONS
1606 if (!wwin->screen_ptr->flags.startup) {
1607 /* Catch up with events not processed while animation was running */
1608 Window clientwin = wwin->client_win;
1610 ProcessPendingEvents();
1612 /* the window can disappear while ProcessPendingEvents() runs */
1613 if (!wWindowFor(clientwin)) {
1614 w_global.ignore_workspace_change = False;
1615 return;
1618 #endif
1621 if (wPreferences.auto_arrange_icons)
1622 wArrangeIcons(wwin->screen_ptr, True);
1624 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1626 /* In case we were shaded and iconified, also unshade */
1627 if (!netwm_hidden)
1628 wUnshadeWindow(wwin);
1630 w_global.ignore_workspace_change = False;
1633 static void hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1635 if (wwin->flags.miniaturized) {
1636 if (wwin->icon) {
1637 XUnmapWindow(dpy, wwin->icon->core->window);
1638 wwin->icon->mapped = 0;
1640 wwin->flags.hidden = 1;
1642 WMPostNotificationName(WMNChangedState, wwin, "hide");
1643 return;
1646 if (wwin->flags.inspector_open)
1647 wHideInspectorForWindow(wwin);
1649 wwin->flags.hidden = 1;
1650 wWindowUnmap(wwin);
1652 wClientSetState(wwin, IconicState, icon->icon_win);
1653 flushExpose();
1655 #ifdef USE_ANIMATIONS
1656 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1657 !wwin->flags.skip_next_animation && animate) {
1658 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1659 wwin->frame->core->width, wwin->frame->core->height,
1660 icon_x, icon_y, icon->core->width, icon->core->height);
1662 #else
1663 /* Tell the compiler it is normal that those parameters are not used in this case */
1664 (void) icon_x;
1665 (void) icon_y;
1666 (void) animate;
1667 #endif
1668 wwin->flags.skip_next_animation = 0;
1670 WMPostNotificationName(WMNChangedState, wwin, "hide");
1673 void wHideAll(WScreen *scr)
1675 WWindow *wwin;
1676 WWindow **windows;
1677 WMenu *menu;
1678 unsigned int wcount = 0;
1679 int i;
1681 if (!scr)
1682 return;
1684 menu = scr->switch_menu;
1686 windows = wmalloc(sizeof(WWindow *));
1688 if (menu != NULL) {
1689 for (i = 0; i < menu->entry_no; i++) {
1690 windows[wcount] = (WWindow *) menu->entries[i]->clientdata;
1691 wcount++;
1692 windows = wrealloc(windows, sizeof(WWindow *) * (wcount + 1));
1694 } else {
1695 wwin = scr->focused_window;
1697 while (wwin) {
1698 windows[wcount] = wwin;
1699 wcount++;
1700 windows = wrealloc(windows, sizeof(WWindow *) * (wcount + 1));
1701 wwin = wwin->prev;
1706 for (i = 0; i < wcount; i++) {
1707 wwin = windows[i];
1708 if (wwin->frame->workspace == scr->current_workspace
1709 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1710 && !wwin->flags.internal_window
1711 && !WFLAGP(wwin, no_miniaturizable)
1713 wwin->flags.skip_next_animation = 1;
1714 wIconifyWindow(wwin);
1718 wfree(windows);
1721 void wHideOtherApplications(WWindow *awin)
1723 WWindow *wwin;
1724 WApplication *tapp;
1726 if (!awin)
1727 return;
1728 wwin = awin->screen_ptr->focused_window;
1730 while (wwin) {
1731 if (wwin != awin
1732 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1733 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1734 && !wwin->flags.internal_window
1735 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1737 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1738 if (!WFLAGP(wwin, no_miniaturizable)) {
1739 wwin->flags.skip_next_animation = 1;
1740 wIconifyWindow(wwin);
1742 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1743 tapp = wApplicationOf(wwin->main_window);
1744 if (tapp) {
1745 tapp->flags.skip_next_animation = 1;
1746 wHideApplication(tapp);
1747 } else {
1748 if (!WFLAGP(wwin, no_miniaturizable)) {
1749 wwin->flags.skip_next_animation = 1;
1750 wIconifyWindow(wwin);
1755 wwin = wwin->prev;
1758 wSetFocusTo(awin->screen_ptr, awin);
1762 void wHideApplication(WApplication *wapp)
1764 WScreen *scr;
1765 WWindow *wlist;
1766 int hadfocus;
1767 int animate;
1769 if (!wapp) {
1770 wwarning("trying to hide a non grouped window");
1771 return;
1773 if (!wapp->main_window_desc) {
1774 wwarning("group leader not found for window group");
1775 return;
1777 scr = wapp->main_window_desc->screen_ptr;
1778 hadfocus = 0;
1779 wlist = scr->focused_window;
1780 if (!wlist)
1781 return;
1783 if (wlist->main_window == wapp->main_window)
1784 wapp->last_focused = wlist;
1785 else
1786 wapp->last_focused = NULL;
1788 animate = !wapp->flags.skip_next_animation;
1790 while (wlist) {
1791 if (wlist->main_window == wapp->main_window) {
1792 if (wlist->flags.focused)
1793 hadfocus = 1;
1794 if (wapp->app_icon) {
1795 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1796 wapp->app_icon->y_pos, wlist, animate);
1797 animate = False;
1800 wlist = wlist->prev;
1803 wapp->flags.skip_next_animation = 0;
1805 if (hadfocus) {
1806 if (wPreferences.focus_mode == WKF_CLICK) {
1807 wlist = scr->focused_window;
1808 while (wlist) {
1809 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1810 && (wlist->flags.mapped || wlist->flags.shaded))
1811 break;
1812 wlist = wlist->prev;
1814 wSetFocusTo(scr, wlist);
1815 } else {
1816 wSetFocusTo(scr, NULL);
1820 wapp->flags.hidden = 1;
1822 if (wPreferences.auto_arrange_icons)
1823 wArrangeIcons(scr, True);
1825 #ifdef HIDDENDOT
1826 if (wapp->app_icon)
1827 wAppIconPaint(wapp->app_icon);
1828 #endif
1831 static void unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate, int bringToCurrentWS)
1833 if (bringToCurrentWS)
1834 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1836 wwin->flags.hidden = 0;
1838 #ifdef USE_ANIMATIONS
1839 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1840 animateResize(wwin->screen_ptr, icon_x, icon_y,
1841 icon->core->width, icon->core->height,
1842 wwin->frame_x, wwin->frame_y,
1843 wwin->frame->core->width, wwin->frame->core->height);
1845 #else
1846 /* Tell the compiler it is normal that those parameters are not used in this case */
1847 (void) icon;
1848 (void) icon_x;
1849 (void) icon_y;
1850 (void) animate;
1851 #endif
1852 wwin->flags.skip_next_animation = 0;
1853 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1854 XMapWindow(dpy, wwin->client_win);
1855 XMapWindow(dpy, wwin->frame->core->window);
1856 wClientSetState(wwin, NormalState, None);
1857 wwin->flags.mapped = 1;
1858 wRaiseFrame(wwin->frame->core);
1860 if (wwin->flags.inspector_open)
1861 wUnhideInspectorForWindow(wwin);
1863 WMPostNotificationName(WMNChangedState, wwin, "hide");
1866 void wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1868 WScreen *scr;
1869 WWindow *wlist, *next;
1870 WWindow *focused = NULL;
1871 int animate;
1873 if (!wapp)
1874 return;
1876 scr = wapp->main_window_desc->screen_ptr;
1877 wlist = scr->focused_window;
1878 if (!wlist)
1879 return;
1881 /* goto beginning of list */
1882 while (wlist->prev)
1883 wlist = wlist->prev;
1885 animate = !wapp->flags.skip_next_animation;
1887 while (wlist) {
1888 next = wlist->next;
1890 if (wlist->main_window == wapp->main_window) {
1891 if (wlist->flags.focused)
1892 focused = wlist;
1893 else if (!focused || !focused->flags.focused)
1894 focused = wlist;
1896 if (wlist->flags.miniaturized) {
1897 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1898 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1899 if (!wlist->icon->mapped) {
1900 int x, y;
1902 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1903 if (wlist->icon_x != x || wlist->icon_y != y)
1904 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1905 wlist->icon_x = x;
1906 wlist->icon_y = y;
1907 XMapWindow(dpy, wlist->icon->core->window);
1908 wlist->icon->mapped = 1;
1910 wRaiseFrame(wlist->icon->core);
1912 if (bringToCurrentWS)
1913 wWindowChangeWorkspace(wlist, scr->current_workspace);
1914 wlist->flags.hidden = 0;
1915 if (miniwindows && wlist->frame->workspace == scr->current_workspace)
1916 wDeiconifyWindow(wlist);
1917 WMPostNotificationName(WMNChangedState, wlist, "hide");
1918 } else if (wlist->flags.shaded) {
1919 if (bringToCurrentWS)
1920 wWindowChangeWorkspace(wlist, scr->current_workspace);
1921 wlist->flags.hidden = 0;
1922 wRaiseFrame(wlist->frame->core);
1923 if (wlist->frame->workspace == scr->current_workspace) {
1924 XMapWindow(dpy, wlist->frame->core->window);
1925 if (miniwindows)
1926 wUnshadeWindow(wlist);
1928 WMPostNotificationName(WMNChangedState, wlist, "hide");
1929 } else if (wlist->flags.hidden) {
1930 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1931 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1932 animate = False;
1933 } else {
1934 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace)
1935 wWindowChangeWorkspace(wlist, scr->current_workspace);
1937 wRaiseFrame(wlist->frame->core);
1940 wlist = next;
1943 wapp->flags.skip_next_animation = 0;
1944 wapp->flags.hidden = 0;
1946 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1947 wRaiseFrame(wapp->last_focused->frame->core);
1948 wSetFocusTo(scr, wapp->last_focused);
1949 } else if (focused) {
1950 wSetFocusTo(scr, focused);
1952 wapp->last_focused = NULL;
1953 if (wPreferences.auto_arrange_icons)
1954 wArrangeIcons(scr, True);
1956 #ifdef HIDDENDOT
1957 wAppIconPaint(wapp->app_icon);
1958 #endif
1961 void wShowAllWindows(WScreen *scr)
1963 WWindow *wwin, *old_foc;
1964 WApplication *wapp;
1966 old_foc = wwin = scr->focused_window;
1967 while (wwin) {
1968 if (!wwin->flags.internal_window &&
1969 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1970 if (wwin->flags.miniaturized) {
1971 wwin->flags.skip_next_animation = 1;
1972 wDeiconifyWindow(wwin);
1973 } else if (wwin->flags.hidden) {
1974 wapp = wApplicationOf(wwin->main_window);
1975 if (wapp) {
1976 wUnhideApplication(wapp, False, False);
1977 } else {
1978 wwin->flags.skip_next_animation = 1;
1979 wDeiconifyWindow(wwin);
1983 wwin = wwin->prev;
1985 wSetFocusTo(scr, old_foc);
1986 /*wRaiseFrame(old_foc->frame->core); */
1989 void wRefreshDesktop(WScreen *scr)
1991 Window win;
1992 XSetWindowAttributes attr;
1994 attr.backing_store = NotUseful;
1995 attr.save_under = False;
1996 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1997 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1998 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1999 XMapRaised(dpy, win);
2000 XDestroyWindow(dpy, win);
2001 XFlush(dpy);
2004 void wArrangeIcons(WScreen *scr, Bool arrangeAll)
2006 WWindow *wwin;
2007 WAppIcon *aicon;
2009 int head;
2010 const int heads = wXineramaHeads(scr);
2012 struct HeadVars {
2013 int pf; /* primary axis */
2014 int sf; /* secondary axis */
2015 int fullW;
2016 int fullH;
2017 int pi, si;
2018 int sx1, sx2, sy1, sy2; /* screen boundary */
2019 int sw, sh;
2020 int xo, yo;
2021 int xs, ys;
2022 } *vars;
2024 int isize = wPreferences.icon_size;
2026 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
2028 for (head = 0; head < heads; ++head) {
2029 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
2030 WMRect rect;
2032 if (scr->dock) {
2033 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
2035 if (scr->dock->on_right_side)
2036 area.x2 -= offset;
2037 else
2038 area.x1 += offset;
2041 rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
2043 vars[head].pi = vars[head].si = 0;
2044 vars[head].sx1 = rect.pos.x;
2045 vars[head].sy1 = rect.pos.y;
2046 vars[head].sw = rect.size.width;
2047 vars[head].sh = rect.size.height;
2048 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
2049 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
2050 vars[head].sw = isize * (vars[head].sw / isize);
2051 vars[head].sh = isize * (vars[head].sh / isize);
2052 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
2053 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
2055 /* icon yard boundaries */
2056 if (wPreferences.icon_yard & IY_VERT) {
2057 vars[head].pf = vars[head].fullH;
2058 vars[head].sf = vars[head].fullW;
2059 } else {
2060 vars[head].pf = vars[head].fullW;
2061 vars[head].sf = vars[head].fullH;
2063 if (wPreferences.icon_yard & IY_RIGHT) {
2064 vars[head].xo = vars[head].sx2 - isize;
2065 vars[head].xs = -1;
2066 } else {
2067 vars[head].xo = vars[head].sx1;
2068 vars[head].xs = 1;
2070 if (wPreferences.icon_yard & IY_TOP) {
2071 vars[head].yo = vars[head].sy1;
2072 vars[head].ys = 1;
2073 } else {
2074 vars[head].yo = vars[head].sy2 - isize;
2075 vars[head].ys = -1;
2079 #define X ((wPreferences.icon_yard & IY_VERT) \
2080 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
2081 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
2083 #define Y ((wPreferences.icon_yard & IY_VERT) \
2084 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
2085 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
2087 /* arrange application icons */
2088 aicon = scr->app_icon_list;
2089 /* reverse them to avoid unnecessarily sliding of icons */
2090 while (aicon && aicon->next)
2091 aicon = aicon->next;
2093 while (aicon) {
2094 if (!aicon->docked) {
2095 /* CHECK: can icon be NULL here ? */
2096 /* The intention here is to place the AppIcon on the head that
2097 * contains most of the applications _main_ window. */
2098 head = wGetHeadForWindow(aicon->icon->owner);
2100 if (aicon->x_pos != X || aicon->y_pos != Y) {
2101 #ifdef USE_ANIMATIONS
2102 if (!wPreferences.no_animations)
2103 slide_window(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
2104 #endif /* USE_ANIMATIONS */
2106 wAppIconMove(aicon, X, Y);
2107 vars[head].pi++;
2108 if (vars[head].pi >= vars[head].pf) {
2109 vars[head].pi = 0;
2110 vars[head].si++;
2113 aicon = aicon->prev;
2116 /* arrange miniwindows */
2117 wwin = scr->focused_window;
2118 /* reverse them to avoid unnecessarily shuffling */
2119 while (wwin && wwin->prev)
2120 wwin = wwin->prev;
2122 while (wwin) {
2123 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
2124 (wwin->frame->workspace == scr->current_workspace ||
2125 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
2127 head = wGetHeadForWindow(wwin);
2129 if (arrangeAll || !wwin->flags.icon_moved) {
2130 if (wwin->icon_x != X || wwin->icon_y != Y)
2131 move_window(wwin->icon->core->window, wwin->icon_x, wwin->icon_y, X, Y);
2133 wwin->icon_x = X;
2134 wwin->icon_y = Y;
2136 vars[head].pi++;
2137 if (vars[head].pi >= vars[head].pf) {
2138 vars[head].pi = 0;
2139 vars[head].si++;
2143 if (arrangeAll)
2144 wwin->flags.icon_moved = 0;
2145 /* we reversed the order, so we use next */
2146 wwin = wwin->next;
2149 wfree(vars);
2152 void wSelectWindow(WWindow *wwin, Bool flag)
2154 WScreen *scr = wwin->screen_ptr;
2156 if (flag) {
2157 wwin->flags.selected = 1;
2158 if (wwin->frame->selected_border_pixel)
2159 XSetWindowBorder(dpy, wwin->frame->core->window, *wwin->frame->selected_border_pixel);
2160 else
2161 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
2163 if (!HAS_BORDER(wwin))
2164 XSetWindowBorderWidth(dpy, wwin->frame->core->window, wwin->screen_ptr->frame_border_width);
2166 if (!scr->selected_windows)
2167 scr->selected_windows = WMCreateArray(4);
2168 WMAddToArray(scr->selected_windows, wwin);
2169 } else {
2170 wwin->flags.selected = 0;
2171 if (wwin->flags.focused) {
2172 if (wwin->frame->focused_border_pixel)
2173 XSetWindowBorder(dpy, wwin->frame->core->window, *wwin->frame->focused_border_pixel);
2174 else
2175 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_focused_border_pixel);
2176 } else {
2177 if (wwin->frame->border_pixel)
2178 XSetWindowBorder(dpy, wwin->frame->core->window, *wwin->frame->border_pixel);
2179 else
2180 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
2183 if (!HAS_BORDER(wwin))
2184 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
2186 if (scr->selected_windows)
2187 WMRemoveFromArray(scr->selected_windows, wwin);
2191 void wMakeWindowVisible(WWindow *wwin)
2193 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
2194 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
2196 if (wwin->flags.shaded)
2197 wUnshadeWindow(wwin);
2199 if (wwin->flags.hidden) {
2200 WApplication *app;
2202 app = wApplicationOf(wwin->main_window);
2203 if (app) {
2204 /* trick to get focus to this window */
2205 app->last_focused = wwin;
2206 wUnhideApplication(app, False, False);
2209 if (wwin->flags.miniaturized) {
2210 wDeiconifyWindow(wwin);
2211 } else {
2212 if (!WFLAGP(wwin, no_focusable))
2213 wSetFocusTo(wwin->screen_ptr, wwin);
2214 wRaiseFrame(wwin->frame->core);
2218 void movePionterToWindowCenter(WWindow *wwin)
2220 if (!wPreferences.pointer_with_half_max_windows)
2221 return;
2223 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
2224 XWarpPointer(dpy, None, wwin->screen_ptr->root_win, 0, 0, 0, 0,
2225 wwin->frame_x + wwin->client.width / 2,
2226 wwin->frame_y + wwin->client.height / 2);
2227 XFlush(dpy);
2231 * Do the animation while shading (called with what = SHADE)
2232 * or unshading (what = UNSHADE).
2234 #ifdef USE_ANIMATIONS
2235 static void shade_animate(WWindow *wwin, Bool what)
2237 int y, s, w, h;
2238 time_t time0 = time(NULL);
2240 if (wwin->flags.skip_next_animation || wPreferences.no_animations)
2241 return;
2243 switch (what) {
2244 case SHADE:
2245 if (!wwin->screen_ptr->flags.startup) {
2246 /* do the shading animation */
2247 h = wwin->frame->core->height;
2248 s = h / SHADE_STEPS;
2249 if (s < 1)
2250 s = 1;
2251 w = wwin->frame->core->width;
2252 y = wwin->frame->top_width;
2253 while (h > wwin->frame->top_width + 1) {
2254 XMoveWindow(dpy, wwin->client_win, 0, y);
2255 XResizeWindow(dpy, wwin->frame->core->window, w, h);
2256 XFlush(dpy);
2258 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
2259 break;
2261 if (SHADE_DELAY > 0)
2262 wusleep(SHADE_DELAY * 1000L);
2263 else
2264 wusleep(10);
2265 h -= s;
2266 y -= s;
2268 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2270 break;
2272 case UNSHADE:
2273 h = wwin->frame->top_width + wwin->frame->bottom_width;
2274 y = wwin->frame->top_width - wwin->client.height;
2275 s = abs(y) / SHADE_STEPS;
2276 if (s < 1)
2277 s = 1;
2278 w = wwin->frame->core->width;
2279 XMoveWindow(dpy, wwin->client_win, 0, y);
2280 if (s > 0) {
2281 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
2282 XResizeWindow(dpy, wwin->frame->core->window, w, h);
2283 XMoveWindow(dpy, wwin->client_win, 0, y);
2284 XFlush(dpy);
2285 if (SHADE_DELAY > 0)
2286 wusleep(SHADE_DELAY * 2000L / 3);
2287 else
2288 wusleep(10);
2289 h += s;
2290 y += s;
2292 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
2293 break;
2296 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2297 break;
2300 #endif