Use half_scr_width instead of computing it each time
[wmaker-crm.git] / src / actions.c
blobcd7faa105e72e02dddb175717e69cbfa69733e6d
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * 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 "wcore.h"
36 #include "framewin.h"
37 #include "window.h"
38 #include "client.h"
39 #include "icon.h"
40 #include "funcs.h"
41 #include "application.h"
42 #include "actions.h"
43 #include "stacking.h"
44 #include "appicon.h"
45 #include "dock.h"
46 #include "appmenu.h"
47 #include "winspector.h"
48 #include "workspace.h"
49 #include "wsound.h"
50 #include "xinerama.h"
52 /****** Global Variables ******/
53 extern Time LastTimestamp;
54 extern Time LastFocusChange;
56 extern Cursor wCursor[WCUR_LAST];
58 extern WPreferences wPreferences;
60 extern Atom _XA_WM_TAKE_FOCUS;
62 extern void ProcessPendingEvents();
64 /******* Local Variables *******/
65 static struct {
66 int steps;
67 int delay;
68 } shadePars[5] = {
70 SHADE_STEPS_UF, SHADE_DELAY_UF}, {
71 SHADE_STEPS_F, SHADE_DELAY_F}, {
72 SHADE_STEPS_M, SHADE_DELAY_M}, {
73 SHADE_STEPS_S, SHADE_DELAY_S}, {
74 SHADE_STEPS_US, SHADE_DELAY_US}};
76 #define UNSHADE 0
77 #define SHADE 1
78 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
79 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
81 static int compareTimes(Time t1, Time t2)
83 Time diff;
84 if (t1 == t2)
85 return 0;
86 diff = t1 - t2;
87 return (diff < 60000) ? 1 : -1;
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 = LastTimestamp;
110 WApplication *oapp = NULL, *napp = NULL;
111 int wasfocused;
113 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
114 return;
116 if (!old_scr)
117 old_scr = scr;
118 old_focused = old_scr->focused_window;
120 LastFocusChange = timestamp;
122 if (old_focused)
123 oapp = wApplicationOf(old_focused->main_window);
125 if (wwin == NULL) {
126 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
127 if (old_focused) {
128 wWindowUnfocus(old_focused);
130 if (oapp) {
131 wAppMenuUnmap(oapp->menu);
132 #ifdef NEWAPPICON
133 wApplicationDeactivate(oapp);
134 #endif
137 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
138 return;
139 } else if (old_scr != scr && old_focused) {
140 wWindowUnfocus(old_focused);
143 wasfocused = wwin->flags.focused;
144 napp = wApplicationOf(wwin->main_window);
146 /* remember last workspace where the app has been */
147 if (napp) {
148 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
149 napp->last_workspace = wwin->frame->workspace;
152 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
153 /* install colormap if colormap mode is lock mode */
154 if (wPreferences.colormap_mode == WCM_CLICK)
155 wColormapInstallForWindow(scr, wwin);
157 /* set input focus */
158 switch (wwin->focus_mode) {
159 case WFM_NO_INPUT:
160 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
161 break;
163 case WFM_PASSIVE:
164 case WFM_LOCALLY_ACTIVE:
165 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
166 break;
168 case WFM_GLOBALLY_ACTIVE:
169 break;
171 XFlush(dpy);
172 if (wwin->protocols.TAKE_FOCUS) {
173 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
175 XSync(dpy, False);
176 } else {
177 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
179 if (WFLAGP(wwin, no_focusable))
180 return;
182 /* if this is not the focused window focus it */
183 if (focused != wwin) {
184 /* change the focus window list order */
185 if (wwin->prev)
186 wwin->prev->next = wwin->next;
188 if (wwin->next)
189 wwin->next->prev = wwin->prev;
191 wwin->prev = focused;
192 focused->next = wwin;
193 wwin->next = NULL;
194 scr->focused_window = wwin;
196 if (oapp && oapp != napp) {
197 wAppMenuUnmap(oapp->menu);
198 #ifdef NEWAPPICON
199 wApplicationDeactivate(oapp);
200 #endif
204 wWindowFocus(wwin, focused);
206 if (napp && !wasfocused) {
207 #ifdef USER_MENU
208 wUserMenuRefreshInstances(napp->menu, wwin);
209 #endif /* USER_MENU */
211 if (wwin->flags.mapped)
212 wAppMenuMap(napp->menu, wwin);
213 #ifdef NEWAPPICON
214 wApplicationActivate(napp);
215 #endif
218 XFlush(dpy);
219 old_scr = scr;
222 void wShadeWindow(WWindow *wwin)
225 if (wwin->flags.shaded)
226 return;
228 XLowerWindow(dpy, wwin->client_win);
229 wSoundPlay(WSOUND_SHADE);
230 shade_animate(wwin, SHADE);
232 wwin->flags.skip_next_animation = 0;
233 wwin->flags.shaded = 1;
234 wwin->flags.mapped = 0;
235 /* prevent window withdrawal when getting UnmapNotify */
236 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
237 XUnmapWindow(dpy, wwin->client_win);
238 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
240 /* for the client it's just like iconification */
241 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
243 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
244 wWindowSynthConfigureNotify(wwin);
247 wClientSetState(wwin, IconicState, None);
250 WMPostNotificationName(WMNChangedState, wwin, "shade");
252 #ifdef ANIMATIONS
253 if (!wwin->screen_ptr->flags.startup) {
254 /* Catch up with events not processed while animation was running */
255 ProcessPendingEvents();
257 #endif
260 void wUnshadeWindow(WWindow *wwin)
263 if (!wwin->flags.shaded)
264 return;
266 wwin->flags.shaded = 0;
267 wwin->flags.mapped = 1;
268 XMapWindow(dpy, wwin->client_win);
270 wSoundPlay(WSOUND_UNSHADE);
271 shade_animate(wwin, UNSHADE);
273 wwin->flags.skip_next_animation = 0;
274 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
275 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
277 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
278 wWindowSynthConfigureNotify(wwin);
281 wClientSetState(wwin, NormalState, None);
283 /* if the window is focused, set the focus again as it was disabled during
284 * shading */
285 if (wwin->flags.focused)
286 wSetFocusTo(wwin->screen_ptr, wwin);
288 WMPostNotificationName(WMNChangedState, wwin, "shade");
291 void wMaximizeWindow(WWindow * wwin, int directions)
293 int new_x, new_y;
294 unsigned int new_width, new_height, half_scr_width;
295 int changed_h, changed_v, shrink_h, shrink_v;
296 WArea usableArea, totalArea;
298 if (!IS_RESIZABLE(wwin))
299 return;
301 totalArea.x1 = 0;
302 totalArea.y1 = 0;
303 totalArea.x2 = wwin->screen_ptr->scr_width;
304 totalArea.y2 = wwin->screen_ptr->scr_height;
305 usableArea = totalArea;
306 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
308 if (!(directions & MAX_IGNORE_XINERAMA)) {
309 WScreen *scr = wwin->screen_ptr;
310 int head;
312 if (directions & MAX_KEYBOARD)
313 head = wGetHeadForWindow(wwin);
314 else
315 head = wGetHeadForPointerLocation(scr);
317 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
320 if (WFLAGP(wwin, full_maximize)) {
321 usableArea = totalArea;
324 if (wwin->flags.shaded) {
325 wwin->flags.skip_next_animation = 1;
326 wUnshadeWindow(wwin);
328 /* Only save directions, not kbd or xinerama hints */
329 directions &= (MAX_HORIZONTAL|MAX_VERTICAL|MAX_LEFTHALF|MAX_RIGHTHALF);
331 changed_h = ((wwin->flags.maximized ^ directions) & MAX_HORIZONTAL);
332 changed_v = ((wwin->flags.maximized ^ directions) & MAX_VERTICAL);
333 shrink_h = (changed_h && (directions & MAX_HORIZONTAL) == 0);
334 shrink_v = (changed_v && (directions & MAX_VERTICAL) == 0);
336 if (wwin->flags.maximized) {
337 /* if already maximized in some direction, we only update the
338 * appropriate old x, old y coordinates. This is necessary to
339 * allow succesive maximizations in different directions without
340 * the need to first do an un-maximize (to avoid flicker).
342 if (!(wwin->flags.maximized & (MAX_HORIZONTAL|MAX_LEFTHALF|MAX_RIGHTHALF))) {
343 wwin->old_geometry.x = wwin->frame_x;
345 if (!(wwin->flags.maximized & MAX_VERTICAL)) {
346 wwin->old_geometry.y = wwin->frame_y;
348 } else {
349 wwin->old_geometry.width = wwin->client.width;
350 wwin->old_geometry.height = wwin->client.height;
351 wwin->old_geometry.x = wwin->frame_x;
352 wwin->old_geometry.y = wwin->frame_y;
354 wwin->flags.maximized = directions;
356 if (directions & MAX_HORIZONTAL) {
357 new_width = usableArea.x2 - usableArea.x1;
358 if (HAS_BORDER(wwin))
359 new_width -= FRAME_BORDER_WIDTH * 2;
360 new_x = usableArea.x1;
361 } else if (directions & MAX_LEFTHALF) {
362 new_width = half_scr_width;
363 if (HAS_BORDER(wwin))
364 new_width -= FRAME_BORDER_WIDTH * 2;
365 new_x = usableArea.x1;
366 } else if (directions & MAX_RIGHTHALF) {
367 new_width = half_scr_width;
368 if (HAS_BORDER(wwin))
369 new_width -= FRAME_BORDER_WIDTH * 2;
370 new_x = usableArea.x1 + half_scr_width;
371 } else if (shrink_h) {
372 new_x = wwin->old_geometry.x;
373 new_width = wwin->old_geometry.width;
374 } else {
375 new_x = wwin->frame_x;
376 new_width = wwin->frame->core->width;
379 if (directions & MAX_VERTICAL) {
380 new_height = usableArea.y2 - usableArea.y1;
381 if (HAS_BORDER(wwin))
382 new_height -= FRAME_BORDER_WIDTH * 2;
383 new_y = usableArea.y1;
384 if (WFLAGP(wwin, full_maximize)) {
385 new_y -= wwin->frame->top_width;
386 new_height += wwin->frame->bottom_width - 1;
388 } else if (shrink_v) {
389 new_y = wwin->old_geometry.y;
390 new_height = wwin->old_geometry.height;
391 } else {
392 new_y = wwin->frame_y;
393 new_height = wwin->frame->core->height;
396 if (!WFLAGP(wwin, full_maximize)) {
397 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
400 wWindowConstrainSize(wwin, &new_width, &new_height);
402 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
403 usableArea.y2 - usableArea.y1, &new_width, &new_height);
405 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
407 WMPostNotificationName(WMNChangedState, wwin, "maximize");
409 wSoundPlay(WSOUND_MAXIMIZE);
412 void wUnmaximizeWindow(WWindow * wwin)
414 int x, y, w, h;
416 if (!wwin->flags.maximized)
417 return;
419 if (wwin->flags.shaded) {
420 wwin->flags.skip_next_animation = 1;
421 wUnshadeWindow(wwin);
423 x = ((wwin->flags.maximized & (MAX_HORIZONTAL|MAX_LEFTHALF|MAX_RIGHTHALF)) && wwin->old_geometry.x) ?
424 wwin->old_geometry.x : wwin->frame_x;
425 y = ((wwin->flags.maximized & MAX_VERTICAL) && wwin->old_geometry.y) ?
426 wwin->old_geometry.y : wwin->frame_y;
427 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
428 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
430 wwin->flags.maximized = 0;
431 wWindowConfigure(wwin, x, y, w, h);
433 WMPostNotificationName(WMNChangedState, wwin, "maximize");
435 wSoundPlay(WSOUND_UNMAXIMIZE);
438 void wFullscreenWindow(WWindow * wwin)
440 int head;
441 WMRect rect;
443 if (wwin->flags.fullscreen)
444 return;
446 wwin->flags.fullscreen = True;
448 wWindowConfigureBorders(wwin);
450 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
452 wwin->bfs_geometry.x = wwin->frame_x;
453 wwin->bfs_geometry.y = wwin->frame_y;
454 wwin->bfs_geometry.width = wwin->frame->core->width;
455 wwin->bfs_geometry.height = wwin->frame->core->height;
457 head = wGetHeadForWindow(wwin);
458 rect = wGetRectForHead(wwin->screen_ptr, head);
459 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
461 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
464 void wUnfullscreenWindow(WWindow * wwin)
466 if (!wwin->flags.fullscreen)
467 return;
469 wwin->flags.fullscreen = False;
471 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
472 if (WFLAGP(wwin, sunken)) {
473 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
474 } else if (WFLAGP(wwin, floating)) {
475 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
476 } else {
477 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
481 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
482 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
484 wWindowConfigureBorders(wwin);
486 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
487 wFrameWindowPaint(wwin->frame);
490 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
493 #ifdef ANIMATIONS
494 static void animateResizeFlip(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
496 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
497 float cx, cy, cw, ch;
498 float xstep, ystep, wstep, hstep;
499 XPoint points[5];
500 float dx, dch, midy;
501 float angle, final_angle, delta;
503 xstep = (float)(fx - x) / steps;
504 ystep = (float)(fy - y) / steps;
505 wstep = (float)(fw - w) / steps;
506 hstep = (float)(fh - h) / steps;
508 cx = (float)x;
509 cy = (float)y;
510 cw = (float)w;
511 ch = (float)h;
513 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
514 delta = (float)(final_angle / FRAMES);
515 for (angle = 0;; angle += delta) {
516 if (angle > final_angle)
517 angle = final_angle;
519 dx = (cw / 10) - ((cw / 5) * sin(angle));
520 dch = (ch / 2) * cos(angle);
521 midy = cy + (ch / 2);
523 points[0].x = cx + dx;
524 points[0].y = midy - dch;
525 points[1].x = cx + cw - dx;
526 points[1].y = points[0].y;
527 points[2].x = cx + cw + dx;
528 points[2].y = midy + dch;
529 points[3].x = cx - dx;
530 points[3].y = points[2].y;
531 points[4].x = points[0].x;
532 points[4].y = points[0].y;
534 XGrabServer(dpy);
535 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
536 XFlush(dpy);
537 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
538 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
539 #else
540 wusleep(10);
541 #endif
543 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
544 XUngrabServer(dpy);
545 cx += xstep;
546 cy += ystep;
547 cw += wstep;
548 ch += hstep;
549 if (angle >= final_angle)
550 break;
553 XFlush(dpy);
556 #undef FRAMES
558 static void
559 animateResizeTwist(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
561 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
562 float cx, cy, cw, ch;
563 float xstep, ystep, wstep, hstep;
564 XPoint points[5];
565 float angle, final_angle, a, d, delta;
567 x += w / 2;
568 y += h / 2;
569 fx += fw / 2;
570 fy += fh / 2;
572 xstep = (float)(fx - x) / steps;
573 ystep = (float)(fy - y) / steps;
574 wstep = (float)(fw - w) / steps;
575 hstep = (float)(fh - h) / steps;
577 cx = (float)x;
578 cy = (float)y;
579 cw = (float)w;
580 ch = (float)h;
582 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
583 delta = (float)(final_angle / FRAMES);
584 for (angle = 0;; angle += delta) {
585 if (angle > final_angle)
586 angle = final_angle;
588 a = atan(ch / cw);
589 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
591 points[0].x = cx + cos(angle - a) * d;
592 points[0].y = cy + sin(angle - a) * d;
593 points[1].x = cx + cos(angle + a) * d;
594 points[1].y = cy + sin(angle + a) * d;
595 points[2].x = cx + cos(angle - a + WM_PI) * d;
596 points[2].y = cy + sin(angle - a + WM_PI) * d;
597 points[3].x = cx + cos(angle + a + WM_PI) * d;
598 points[3].y = cy + sin(angle + a + WM_PI) * d;
599 points[4].x = cx + cos(angle - a) * d;
600 points[4].y = cy + sin(angle - a) * d;
601 XGrabServer(dpy);
602 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
603 XFlush(dpy);
604 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
605 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
606 #else
607 wusleep(10);
608 #endif
610 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
611 XUngrabServer(dpy);
612 cx += xstep;
613 cy += ystep;
614 cw += wstep;
615 ch += hstep;
616 if (angle >= final_angle)
617 break;
620 XFlush(dpy);
623 #undef FRAMES
625 static void animateResizeZoom(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
627 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
628 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
629 float xstep, ystep, wstep, hstep;
630 int i, j;
632 xstep = (float)(fx - x) / steps;
633 ystep = (float)(fy - y) / steps;
634 wstep = (float)(fw - w) / steps;
635 hstep = (float)(fh - h) / steps;
637 for (j = 0; j < FRAMES; j++) {
638 cx[j] = (float)x;
639 cy[j] = (float)y;
640 cw[j] = (float)w;
641 ch[j] = (float)h;
643 XGrabServer(dpy);
644 for (i = 0; i < steps; i++) {
645 for (j = 0; j < FRAMES; j++) {
646 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
647 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
649 XFlush(dpy);
650 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
651 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
652 #else
653 wusleep(10);
654 #endif
655 for (j = 0; j < FRAMES; j++) {
656 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
657 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
658 if (j < FRAMES - 1) {
659 cx[j] = cx[j + 1];
660 cy[j] = cy[j + 1];
661 cw[j] = cw[j + 1];
662 ch[j] = ch[j + 1];
663 } else {
664 cx[j] += xstep;
665 cy[j] += ystep;
666 cw[j] += wstep;
667 ch[j] += hstep;
672 for (j = 0; j < FRAMES; j++) {
673 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
675 XFlush(dpy);
676 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
677 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
678 #else
679 wusleep(10);
680 #endif
681 for (j = 0; j < FRAMES; j++) {
682 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
685 XUngrabServer(dpy);
688 #undef FRAMES
690 void animateResize(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int hiding)
692 int style = wPreferences.iconification_style; /* Catch the value */
693 int steps, k;
695 if (style == WIS_NONE)
696 return;
698 if (style == WIS_RANDOM) {
699 style = rand() % 3;
702 k = (hiding ? 2 : 3);
704 switch (style) {
705 case WIS_TWIST:
706 steps = (MINIATURIZE_ANIMATION_STEPS_T * k) / 3;
707 if (steps > 0)
708 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
709 break;
710 case WIS_FLIP:
711 steps = (MINIATURIZE_ANIMATION_STEPS_F * k) / 3;
712 if (steps > 0)
713 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
714 break;
715 case WIS_ZOOM:
716 default:
717 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k) / 3;
718 if (steps > 0)
719 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
720 break;
723 #endif /* ANIMATIONS */
725 static void flushExpose()
727 XEvent tmpev;
729 while (XCheckTypedEvent(dpy, Expose, &tmpev))
730 WMHandleEvent(&tmpev);
731 XSync(dpy, 0);
734 static void unmapTransientsFor(WWindow * wwin)
736 WWindow *tmp;
738 tmp = wwin->screen_ptr->focused_window;
739 while (tmp) {
740 /* unmap the transients for this transient */
741 if (tmp != wwin && tmp->transient_for == wwin->client_win
742 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
743 unmapTransientsFor(tmp);
744 tmp->flags.miniaturized = 1;
745 if (!tmp->flags.shaded) {
746 wWindowUnmap(tmp);
747 } else {
748 XUnmapWindow(dpy, tmp->frame->core->window);
751 if (!tmp->flags.shaded)
753 wClientSetState(tmp, IconicState, None);
755 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
757 tmp = tmp->prev;
761 static void mapTransientsFor(WWindow * wwin)
763 WWindow *tmp;
765 tmp = wwin->screen_ptr->focused_window;
766 while (tmp) {
767 /* recursively map the transients for this transient */
768 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
769 && tmp->icon == NULL) {
770 mapTransientsFor(tmp);
771 tmp->flags.miniaturized = 0;
772 if (!tmp->flags.shaded) {
773 wWindowMap(tmp);
774 } else {
775 XMapWindow(dpy, tmp->frame->core->window);
777 tmp->flags.semi_focused = 0;
779 if (!tmp->flags.shaded)
781 wClientSetState(tmp, NormalState, None);
783 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
785 tmp = tmp->prev;
789 #if 0
790 static void setupIconGrabs(WIcon * icon)
792 /* setup passive grabs on the icon */
793 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
794 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
795 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
796 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
797 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
798 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
799 XSync(dpy, 0);
801 #endif
803 static WWindow *recursiveTransientFor(WWindow * wwin)
805 int i;
807 if (!wwin)
808 return None;
810 /* hackish way to detect transient_for cycle */
811 i = wwin->screen_ptr->window_count + 1;
813 while (wwin && wwin->transient_for != None && i > 0) {
814 wwin = wWindowFor(wwin->transient_for);
815 i--;
817 if (i == 0 && wwin) {
818 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
819 return NULL;
822 return wwin;
825 #if 0
826 static void removeIconGrabs(WIcon * icon)
828 /* remove passive grabs on the icon */
829 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
830 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
831 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
832 XSync(dpy, 0);
834 #endif
836 void wIconifyWindow(WWindow * wwin)
838 XWindowAttributes attribs;
839 int present;
841 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
842 /* the window doesn't exist anymore */
843 return;
846 if (wwin->flags.miniaturized) {
847 return;
850 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
851 WWindow *owner = wWindowFor(wwin->transient_for);
853 if (owner && owner->flags.miniaturized)
854 return;
857 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
859 /* if the window is in another workspace, simplify process */
860 if (present) {
861 /* icon creation may take a while */
862 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
863 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
864 GrabModeAsync, None, None, CurrentTime);
867 if (!wPreferences.disable_miniwindows
868 #ifdef NETWM_HINTS
869 && !wwin->flags.net_handle_icon
870 #endif
872 if (!wwin->flags.icon_moved) {
873 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
875 wwin->icon = wIconCreate(wwin);
877 wwin->icon->mapped = 1;
880 wwin->flags.miniaturized = 1;
881 wwin->flags.mapped = 0;
883 /* unmap transients */
885 unmapTransientsFor(wwin);
887 if (present) {
888 wSoundPlay(WSOUND_ICONIFY);
890 XUngrabPointer(dpy, CurrentTime);
891 wWindowUnmap(wwin);
892 /* let all Expose events arrive so that we can repaint
893 * something before the animation starts (and the server is grabbed) */
894 XSync(dpy, 0);
896 if (wPreferences.disable_miniwindows
897 #ifdef NETWM_HINTS
898 || wwin->flags.net_handle_icon
899 #endif
901 wClientSetState(wwin, IconicState, None);
902 else
903 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
905 flushExpose();
906 #ifdef ANIMATIONS
907 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
908 && !wPreferences.no_animations) {
909 int ix, iy, iw, ih;
911 if (!wPreferences.disable_miniwindows
912 #ifdef NETWM_HINTS
913 && !wwin->flags.net_handle_icon
914 #endif
916 ix = wwin->icon_x;
917 iy = wwin->icon_y;
918 iw = wwin->icon->core->width;
919 ih = wwin->icon->core->height;
920 } else {
921 #ifdef NETWM_HINTS
922 if (wwin->flags.net_handle_icon) {
923 ix = wwin->icon_x;
924 iy = wwin->icon_y;
925 iw = wwin->icon_w;
926 ih = wwin->icon_h;
927 } else
928 #endif
930 ix = 0;
931 iy = 0;
932 iw = wwin->screen_ptr->scr_width;
933 ih = wwin->screen_ptr->scr_height;
936 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
937 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih, False);
939 #endif
942 wwin->flags.skip_next_animation = 0;
944 if (!wPreferences.disable_miniwindows
945 #ifdef NETWM_HINTS
946 && !wwin->flags.net_handle_icon
947 #endif
950 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
951 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
953 XMapWindow(dpy, wwin->icon->core->window);
955 AddToStackList(wwin->icon->core);
957 wLowerFrame(wwin->icon->core);
960 if (present) {
961 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
964 * It doesn't seem to be working and causes button event hangup
965 * when deiconifying a transient window.
966 setupIconGrabs(wwin->icon);
968 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
969 && wPreferences.focus_mode == WKF_CLICK) {
970 WWindow *tmp;
972 tmp = wwin->prev;
973 while (tmp) {
974 if (!WFLAGP(tmp, no_focusable)
975 && !(tmp->flags.hidden || tmp->flags.miniaturized)
976 && (wwin->frame->workspace == tmp->frame->workspace))
977 break;
978 tmp = tmp->prev;
980 wSetFocusTo(wwin->screen_ptr, tmp);
981 } else if (wPreferences.focus_mode != WKF_CLICK) {
982 wSetFocusTo(wwin->screen_ptr, NULL);
984 #ifdef ANIMATIONS
985 if (!wwin->screen_ptr->flags.startup) {
986 /* Catch up with events not processed while animation was running */
987 Window clientwin = wwin->client_win;
989 ProcessPendingEvents();
991 /* the window can disappear while ProcessPendingEvents() runs */
992 if (!wWindowFor(clientwin)) {
993 return;
996 #endif
999 /* maybe we want to do this regardless of net_handle_icon
1000 * it seems to me we might break behaviour this way.
1002 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1003 #ifdef NETWM_HINTS
1004 && !wwin->flags.net_handle_icon
1005 #endif
1007 wIconSelect(wwin->icon);
1009 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1012 void wDeiconifyWindow(WWindow * wwin)
1014 #ifdef NETWM_HINTS
1015 /* we're hiding for show_desktop */
1016 int netwm_hidden = wwin->flags.net_show_desktop &&
1017 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1018 #else
1019 int netwm_hidden = False;
1020 #endif
1022 if (!netwm_hidden)
1023 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1025 if (!wwin->flags.miniaturized)
1026 return;
1028 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1029 WWindow *owner = recursiveTransientFor(wwin);
1031 if (owner && owner->flags.miniaturized) {
1032 wDeiconifyWindow(owner);
1033 wSetFocusTo(wwin->screen_ptr, wwin);
1034 wRaiseFrame(wwin->frame->core);
1035 return;
1039 wwin->flags.miniaturized = 0;
1041 if (!netwm_hidden && !wwin->flags.shaded) {
1042 wwin->flags.mapped = 1;
1045 if (!netwm_hidden || wPreferences.sticky_icons) {
1046 /* maybe we want to do this regardless of net_handle_icon
1047 * it seems to me we might break behaviour this way.
1049 if (!wPreferences.disable_miniwindows
1050 #ifdef NETWM_HINTS
1051 && !wwin->flags.net_handle_icon
1052 #endif
1053 && wwin->icon != NULL) {
1054 if (wwin->icon->selected)
1055 wIconSelect(wwin->icon);
1057 XUnmapWindow(dpy, wwin->icon->core->window);
1061 if (!netwm_hidden)
1062 wSoundPlay(WSOUND_DEICONIFY);
1064 /* if the window is in another workspace, do it silently */
1065 if (!netwm_hidden) {
1066 #ifdef ANIMATIONS
1067 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1068 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1069 int ix, iy, iw, ih;
1071 if (!wPreferences.disable_miniwindows
1072 #ifdef NETWM_HINTS
1073 && !wwin->flags.net_handle_icon
1074 #endif
1076 ix = wwin->icon_x;
1077 iy = wwin->icon_y;
1078 iw = wwin->icon->core->width;
1079 ih = wwin->icon->core->height;
1080 } else {
1081 #ifdef NETWM_HINTS
1082 if (wwin->flags.net_handle_icon) {
1083 ix = wwin->icon_x;
1084 iy = wwin->icon_y;
1085 iw = wwin->icon_w;
1086 ih = wwin->icon_h;
1087 } else
1088 #endif
1090 ix = 0;
1091 iy = 0;
1092 iw = wwin->screen_ptr->scr_width;
1093 ih = wwin->screen_ptr->scr_height;
1096 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1097 wwin->frame_x, wwin->frame_y,
1098 wwin->frame->core->width, wwin->frame->core->height, False);
1100 #endif /* ANIMATIONS */
1101 wwin->flags.skip_next_animation = 0;
1102 XGrabServer(dpy);
1103 if (!wwin->flags.shaded) {
1104 XMapWindow(dpy, wwin->client_win);
1106 XMapWindow(dpy, wwin->frame->core->window);
1107 wRaiseFrame(wwin->frame->core);
1108 if (!wwin->flags.shaded) {
1109 wClientSetState(wwin, NormalState, None);
1111 mapTransientsFor(wwin);
1114 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1115 #ifdef NETWM_HINTS
1116 && !wwin->flags.net_handle_icon
1117 #endif
1119 RemoveFromStackList(wwin->icon->core);
1120 /* removeIconGrabs(wwin->icon); */
1121 wIconDestroy(wwin->icon);
1122 wwin->icon = NULL;
1125 if (!netwm_hidden) {
1126 XUngrabServer(dpy);
1128 wSetFocusTo(wwin->screen_ptr, wwin);
1130 #ifdef ANIMATIONS
1131 if (!wwin->screen_ptr->flags.startup) {
1132 /* Catch up with events not processed while animation was running */
1133 Window clientwin = wwin->client_win;
1135 ProcessPendingEvents();
1137 /* the window can disappear while ProcessPendingEvents() runs */
1138 if (!wWindowFor(clientwin)) {
1139 return;
1142 #endif
1145 if (wPreferences.auto_arrange_icons) {
1146 wArrangeIcons(wwin->screen_ptr, True);
1149 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1151 /* In case we were shaded and iconified, also unshade */
1152 if (!netwm_hidden)
1153 wUnshadeWindow(wwin);
1156 static void hideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate)
1158 if (wwin->flags.miniaturized) {
1159 if (wwin->icon) {
1160 XUnmapWindow(dpy, wwin->icon->core->window);
1161 wwin->icon->mapped = 0;
1163 wwin->flags.hidden = 1;
1165 WMPostNotificationName(WMNChangedState, wwin, "hide");
1166 return;
1169 if (wwin->flags.inspector_open) {
1170 wHideInspectorForWindow(wwin);
1173 wwin->flags.hidden = 1;
1174 wWindowUnmap(wwin);
1176 wClientSetState(wwin, IconicState, icon->icon_win);
1177 flushExpose();
1178 wSoundPlay(WSOUND_HIDE);
1179 #ifdef ANIMATIONS
1180 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1181 !wwin->flags.skip_next_animation && animate) {
1182 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1183 wwin->frame->core->width, wwin->frame->core->height,
1184 icon_x, icon_y, icon->core->width, icon->core->height, True);
1186 #endif
1187 wwin->flags.skip_next_animation = 0;
1189 WMPostNotificationName(WMNChangedState, wwin, "hide");
1192 void wHideOtherApplications(WWindow * awin)
1194 WWindow *wwin;
1195 WApplication *tapp;
1197 if (!awin)
1198 return;
1199 wwin = awin->screen_ptr->focused_window;
1201 while (wwin) {
1202 if (wwin != awin
1203 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1204 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1205 && !wwin->flags.internal_window
1206 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1208 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1209 if (!WFLAGP(wwin, no_miniaturizable)) {
1210 wwin->flags.skip_next_animation = 1;
1211 wIconifyWindow(wwin);
1213 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1214 tapp = wApplicationOf(wwin->main_window);
1215 if (tapp) {
1216 tapp->flags.skip_next_animation = 1;
1217 wHideApplication(tapp);
1218 } else {
1219 if (!WFLAGP(wwin, no_miniaturizable)) {
1220 wwin->flags.skip_next_animation = 1;
1221 wIconifyWindow(wwin);
1226 wwin = wwin->prev;
1229 wSetFocusTo(awin->screen_ptr, awin);
1233 void wHideApplication(WApplication * wapp)
1235 WScreen *scr;
1236 WWindow *wlist;
1237 int hadfocus;
1238 int animate;
1240 if (!wapp) {
1241 wwarning("trying to hide a non grouped window");
1242 return;
1244 if (!wapp->main_window_desc) {
1245 wwarning("group leader not found for window group");
1246 return;
1248 scr = wapp->main_window_desc->screen_ptr;
1249 hadfocus = 0;
1250 wlist = scr->focused_window;
1251 if (!wlist)
1252 return;
1254 if (wlist->main_window == wapp->main_window)
1255 wapp->last_focused = wlist;
1256 else
1257 wapp->last_focused = NULL;
1259 animate = !wapp->flags.skip_next_animation;
1261 while (wlist) {
1262 if (wlist->main_window == wapp->main_window) {
1263 if (wlist->flags.focused) {
1264 hadfocus = 1;
1266 if (wapp->app_icon) {
1267 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1268 wapp->app_icon->y_pos, wlist, animate);
1269 animate = False;
1272 wlist = wlist->prev;
1275 wapp->flags.skip_next_animation = 0;
1277 if (hadfocus) {
1278 if (wPreferences.focus_mode == WKF_CLICK) {
1279 wlist = scr->focused_window;
1280 while (wlist) {
1281 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1282 && (wlist->flags.mapped || wlist->flags.shaded))
1283 break;
1284 wlist = wlist->prev;
1286 wSetFocusTo(scr, wlist);
1287 } else {
1288 wSetFocusTo(scr, NULL);
1292 wapp->flags.hidden = 1;
1294 if (wPreferences.auto_arrange_icons) {
1295 wArrangeIcons(scr, True);
1297 #ifdef HIDDENDOT
1298 if (wapp->app_icon)
1299 wAppIconPaint(wapp->app_icon);
1300 #endif
1303 static void unhideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate, int bringToCurrentWS)
1305 if (bringToCurrentWS)
1306 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1308 wwin->flags.hidden = 0;
1310 wSoundPlay(WSOUND_UNHIDE);
1311 #ifdef ANIMATIONS
1312 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1313 animateResize(wwin->screen_ptr, icon_x, icon_y,
1314 icon->core->width, icon->core->height,
1315 wwin->frame_x, wwin->frame_y,
1316 wwin->frame->core->width, wwin->frame->core->height, True);
1318 #endif
1319 wwin->flags.skip_next_animation = 0;
1320 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1321 XMapWindow(dpy, wwin->client_win);
1322 XMapWindow(dpy, wwin->frame->core->window);
1323 wClientSetState(wwin, NormalState, None);
1324 wwin->flags.mapped = 1;
1325 wRaiseFrame(wwin->frame->core);
1327 if (wwin->flags.inspector_open) {
1328 wUnhideInspectorForWindow(wwin);
1331 WMPostNotificationName(WMNChangedState, wwin, "hide");
1334 void wUnhideApplication(WApplication * wapp, Bool miniwindows, Bool bringToCurrentWS)
1336 WScreen *scr;
1337 WWindow *wlist, *next;
1338 WWindow *focused = NULL;
1339 int animate;
1341 if (!wapp)
1342 return;
1344 scr = wapp->main_window_desc->screen_ptr;
1345 wlist = scr->focused_window;
1346 if (!wlist)
1347 return;
1349 /* goto beginning of list */
1350 while (wlist->prev)
1351 wlist = wlist->prev;
1353 animate = !wapp->flags.skip_next_animation;
1355 while (wlist) {
1356 next = wlist->next;
1358 if (wlist->main_window == wapp->main_window) {
1359 if (wlist->flags.focused)
1360 focused = wlist;
1361 else if (!focused || !focused->flags.focused)
1362 focused = wlist;
1364 if (wlist->flags.miniaturized) {
1365 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1366 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1367 if (!wlist->icon->mapped) {
1368 int x, y;
1370 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1371 if (wlist->icon_x != x || wlist->icon_y != y) {
1372 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1374 wlist->icon_x = x;
1375 wlist->icon_y = y;
1376 XMapWindow(dpy, wlist->icon->core->window);
1377 wlist->icon->mapped = 1;
1379 wRaiseFrame(wlist->icon->core);
1381 if (bringToCurrentWS)
1382 wWindowChangeWorkspace(wlist, scr->current_workspace);
1383 wlist->flags.hidden = 0;
1384 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1385 wDeiconifyWindow(wlist);
1387 WMPostNotificationName(WMNChangedState, wlist, "hide");
1388 } else if (wlist->flags.shaded) {
1389 if (bringToCurrentWS)
1390 wWindowChangeWorkspace(wlist, scr->current_workspace);
1391 wlist->flags.hidden = 0;
1392 if (wlist->frame->workspace == scr->current_workspace) {
1393 XMapWindow(dpy, wlist->frame->core->window);
1394 if (miniwindows) {
1395 wUnshadeWindow(wlist);
1396 wRaiseFrame(wlist->frame->core);
1399 WMPostNotificationName(WMNChangedState, wlist, "hide");
1400 } else if (wlist->flags.hidden) {
1401 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1402 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1403 animate = False;
1404 } else {
1405 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1406 wWindowChangeWorkspace(wlist, scr->current_workspace);
1408 wRaiseFrame(wlist->frame->core);
1411 wlist = next;
1414 wapp->flags.skip_next_animation = 0;
1415 wapp->flags.hidden = 0;
1417 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1418 wRaiseFrame(wapp->last_focused->frame->core);
1419 wSetFocusTo(scr, wapp->last_focused);
1420 } else if (focused) {
1421 wSetFocusTo(scr, focused);
1423 wapp->last_focused = NULL;
1424 if (wPreferences.auto_arrange_icons) {
1425 wArrangeIcons(scr, True);
1427 #ifdef HIDDENDOT
1428 wAppIconPaint(wapp->app_icon);
1429 #endif
1432 void wShowAllWindows(WScreen * scr)
1434 WWindow *wwin, *old_foc;
1435 WApplication *wapp;
1437 old_foc = wwin = scr->focused_window;
1438 while (wwin) {
1439 if (!wwin->flags.internal_window &&
1440 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1441 if (wwin->flags.miniaturized) {
1442 wwin->flags.skip_next_animation = 1;
1443 wDeiconifyWindow(wwin);
1444 } else if (wwin->flags.hidden) {
1445 wapp = wApplicationOf(wwin->main_window);
1446 if (wapp) {
1447 wUnhideApplication(wapp, False, False);
1448 } else {
1449 wwin->flags.skip_next_animation = 1;
1450 wDeiconifyWindow(wwin);
1454 wwin = wwin->prev;
1456 wSetFocusTo(scr, old_foc);
1457 /*wRaiseFrame(old_foc->frame->core); */
1460 void wRefreshDesktop(WScreen * scr)
1462 Window win;
1463 XSetWindowAttributes attr;
1465 attr.backing_store = NotUseful;
1466 attr.save_under = False;
1467 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1468 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1469 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1470 XMapRaised(dpy, win);
1471 XDestroyWindow(dpy, win);
1472 XFlush(dpy);
1475 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1477 WWindow *wwin;
1478 WAppIcon *aicon;
1480 int head;
1481 const int heads = wXineramaHeads(scr);
1483 struct HeadVars {
1484 int pf; /* primary axis */
1485 int sf; /* secondary axis */
1486 int fullW;
1487 int fullH;
1488 int pi, si;
1489 int sx1, sx2, sy1, sy2; /* screen boundary */
1490 int sw, sh;
1491 int xo, yo;
1492 int xs, ys;
1493 } *vars;
1495 int isize = wPreferences.icon_size;
1497 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1499 for (head = 0; head < heads; ++head) {
1500 #if 0
1501 WMRect rect = wGetRectForHead(scr, head);
1502 #else
1503 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1504 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1505 #endif
1507 vars[head].pi = vars[head].si = 0;
1508 vars[head].sx1 = rect.pos.x;
1509 vars[head].sy1 = rect.pos.y;
1510 vars[head].sw = rect.size.width;
1511 vars[head].sh = rect.size.height;
1512 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1513 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1515 #if 0
1516 if (scr->dock) {
1517 if (scr->dock->on_right_side)
1518 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1519 else
1520 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1522 #endif
1524 vars[head].sw = isize * (vars[head].sw / isize);
1525 vars[head].sh = isize * (vars[head].sh / isize);
1526 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1527 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1529 /* icon yard boundaries */
1530 if (wPreferences.icon_yard & IY_VERT) {
1531 vars[head].pf = vars[head].fullH;
1532 vars[head].sf = vars[head].fullW;
1533 } else {
1534 vars[head].pf = vars[head].fullW;
1535 vars[head].sf = vars[head].fullH;
1537 if (wPreferences.icon_yard & IY_RIGHT) {
1538 vars[head].xo = vars[head].sx2 - isize;
1539 vars[head].xs = -1;
1540 } else {
1541 vars[head].xo = vars[head].sx1;
1542 vars[head].xs = 1;
1544 if (wPreferences.icon_yard & IY_TOP) {
1545 vars[head].yo = vars[head].sy1;
1546 vars[head].ys = 1;
1547 } else {
1548 vars[head].yo = vars[head].sy2 - isize;
1549 vars[head].ys = -1;
1553 #define X ((wPreferences.icon_yard & IY_VERT) \
1554 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1555 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1557 #define Y ((wPreferences.icon_yard & IY_VERT) \
1558 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1559 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1561 /* arrange application icons */
1562 aicon = scr->app_icon_list;
1563 /* reverse them to avoid unnecessarily sliding of icons */
1564 while (aicon && aicon->next)
1565 aicon = aicon->next;
1567 while (aicon) {
1568 if (!aicon->docked) {
1569 /* CHECK: can icon be NULL here ? */
1570 /* The intention here is to place the AppIcon on the head that
1571 * contains most of the applications _main_ window. */
1572 head = wGetHeadForWindow(aicon->icon->owner);
1574 if (aicon->x_pos != X || aicon->y_pos != Y) {
1575 #ifdef ANIMATIONS
1576 if (!wPreferences.no_animations) {
1577 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1579 #endif /* ANIMATIONS */
1581 wAppIconMove(aicon, X, Y);
1582 vars[head].pi++;
1583 if (vars[head].pi >= vars[head].pf) {
1584 vars[head].pi = 0;
1585 vars[head].si++;
1588 aicon = aicon->prev;
1591 /* arrange miniwindows */
1592 wwin = scr->focused_window;
1593 /* reverse them to avoid unnecessarily shuffling */
1594 while (wwin && wwin->prev)
1595 wwin = wwin->prev;
1597 while (wwin) {
1598 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1599 (wwin->frame->workspace == scr->current_workspace ||
1600 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1602 head = wGetHeadForWindow(wwin);
1604 if (arrangeAll || !wwin->flags.icon_moved) {
1605 if (wwin->icon_x != X || wwin->icon_y != Y) {
1606 #ifdef ANIMATIONS
1607 if (wPreferences.no_animations) {
1608 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1609 } else {
1610 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1611 wwin->icon_y, X, Y);
1613 #else
1614 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1615 #endif /* ANIMATIONS */
1617 wwin->icon_x = X;
1618 wwin->icon_y = Y;
1620 vars[head].pi++;
1621 if (vars[head].pi >= vars[head].pf) {
1622 vars[head].pi = 0;
1623 vars[head].si++;
1627 if (arrangeAll) {
1628 wwin->flags.icon_moved = 0;
1630 /* we reversed the order, so we use next */
1631 wwin = wwin->next;
1634 wfree(vars);
1637 #if 0
1638 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1640 WWindow *wwin;
1641 WAppIcon *aicon;
1642 int pf; /* primary axis */
1643 int sf; /* secondary axis */
1644 int fullW;
1645 int fullH;
1646 int pi, si;
1647 int sx1, sx2, sy1, sy2; /* screen boundary */
1648 int sw, sh;
1649 int xo, yo;
1650 int xs, ys;
1651 int isize = wPreferences.icon_size;
1654 * Find out screen boundaries.
1658 * Allows each head to have miniwindows
1660 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1662 sx1 = rect.pos.x;
1663 sy1 = rect.pos.y;
1664 sw = rect.size.width;
1665 sh = rect.size.height;
1666 sx2 = sx1 + sw;
1667 sy2 = sy1 + sh;
1668 if (scr->dock) {
1669 if (scr->dock->on_right_side)
1670 sx2 -= isize + DOCK_EXTRA_SPACE;
1671 else
1672 sx1 += isize + DOCK_EXTRA_SPACE;
1674 #if 0
1675 sw = isize * (scr->scr_width / isize);
1676 sh = isize * (scr->scr_height / isize);
1677 #else
1678 sw = isize * (sw / isize);
1679 sh = isize * (sh / isize);
1680 #endif
1681 fullW = (sx2 - sx1) / isize;
1682 fullH = (sy2 - sy1) / isize;
1684 /* icon yard boundaries */
1685 if (wPreferences.icon_yard & IY_VERT) {
1686 pf = fullH;
1687 sf = fullW;
1688 } else {
1689 pf = fullW;
1690 sf = fullH;
1692 if (wPreferences.icon_yard & IY_RIGHT) {
1693 xo = sx2 - isize;
1694 xs = -1;
1695 } else {
1696 xo = sx1;
1697 xs = 1;
1699 if (wPreferences.icon_yard & IY_TOP) {
1700 yo = sy1;
1701 ys = 1;
1702 } else {
1703 yo = sy2 - isize;
1704 ys = -1;
1707 /* arrange icons putting the most recently focused window
1708 * as the last icon */
1709 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1710 : xo + xs*(pi*isize))
1711 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1712 : yo + ys*(si*isize))
1714 /* arrange application icons */
1715 aicon = scr->app_icon_list;
1716 /* reverse them to avoid unnecessarily sliding of icons */
1717 while (aicon && aicon->next)
1718 aicon = aicon->next;
1720 pi = 0;
1721 si = 0;
1722 while (aicon) {
1723 if (!aicon->docked) {
1724 if (aicon->x_pos != X || aicon->y_pos != Y) {
1725 #ifdef ANIMATIONS
1726 if (!wPreferences.no_animations) {
1727 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1729 #endif /* ANIMATIONS */
1731 wAppIconMove(aicon, X, Y);
1732 pi++;
1734 /* we reversed the order so we use prev */
1735 aicon = aicon->prev;
1736 if (pi >= pf) {
1737 pi = 0;
1738 si++;
1742 /* arrange miniwindows */
1744 wwin = scr->focused_window;
1745 /* reverse them to avoid unnecessarily shuffling */
1746 while (wwin && wwin->prev)
1747 wwin = wwin->prev;
1749 while (wwin) {
1750 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1751 (wwin->frame->workspace == scr->current_workspace ||
1752 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1754 if (arrangeAll || !wwin->flags.icon_moved) {
1755 if (wwin->icon_x != X || wwin->icon_y != Y) {
1756 #ifdef ANIMATIONS
1757 if (wPreferences.no_animations) {
1758 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1759 } else {
1760 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1761 wwin->icon_y, X, Y);
1763 #else
1764 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1765 #endif /* ANIMATIONS */
1767 wwin->icon_x = X;
1768 wwin->icon_y = Y;
1769 pi++;
1772 if (arrangeAll) {
1773 wwin->flags.icon_moved = 0;
1775 /* we reversed the order, so we use next */
1776 wwin = wwin->next;
1777 if (pi >= pf) {
1778 pi = 0;
1779 si++;
1783 #endif
1785 void wSelectWindow(WWindow * wwin, Bool flag)
1787 WScreen *scr = wwin->screen_ptr;
1789 if (flag) {
1790 wwin->flags.selected = 1;
1791 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1793 if (!HAS_BORDER(wwin)) {
1794 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1797 if (!scr->selected_windows)
1798 scr->selected_windows = WMCreateArray(4);
1799 WMAddToArray(scr->selected_windows, wwin);
1800 } else {
1801 wwin->flags.selected = 0;
1802 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1804 if (!HAS_BORDER(wwin)) {
1805 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1808 if (scr->selected_windows) {
1809 WMRemoveFromArray(scr->selected_windows, wwin);
1814 void wMakeWindowVisible(WWindow * wwin)
1816 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1817 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1819 if (wwin->flags.shaded) {
1820 wUnshadeWindow(wwin);
1822 if (wwin->flags.hidden) {
1823 WApplication *app;
1825 app = wApplicationOf(wwin->main_window);
1826 if (app) {
1827 /* trick to get focus to this window */
1828 app->last_focused = wwin;
1829 wUnhideApplication(app, False, False);
1832 if (wwin->flags.miniaturized) {
1833 wDeiconifyWindow(wwin);
1834 } else {
1835 if (!WFLAGP(wwin, no_focusable))
1836 wSetFocusTo(wwin->screen_ptr, wwin);
1837 wRaiseFrame(wwin->frame->core);
1842 * Do the animation while shading (called with what = SHADE)
1843 * or unshading (what = UNSHADE).
1845 #ifdef ANIMATIONS
1846 static void shade_animate(WWindow *wwin, Bool what)
1848 int y, s, w, h;
1849 time_t time0 = time(NULL);
1851 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1852 return;
1854 switch(what) {
1855 case SHADE:
1856 if (!wwin->screen_ptr->flags.startup) {
1857 /* do the shading animation */
1858 h = wwin->frame->core->height;
1859 s = h / SHADE_STEPS;
1860 if (s < 1)
1861 s = 1;
1862 w = wwin->frame->core->width;
1863 y = wwin->frame->top_width;
1864 while (h > wwin->frame->top_width + 1) {
1865 XMoveWindow(dpy, wwin->client_win, 0, y);
1866 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1867 XFlush(dpy);
1869 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1870 break;
1872 if (SHADE_DELAY > 0) {
1873 wusleep(SHADE_DELAY * 1000L);
1874 } else {
1875 wusleep(10);
1877 h -= s;
1878 y -= s;
1880 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1882 break;
1884 case UNSHADE:
1885 h = wwin->frame->top_width + wwin->frame->bottom_width;
1886 y = wwin->frame->top_width - wwin->client.height;
1887 s = abs(y) / SHADE_STEPS;
1888 if (s < 1)
1889 s = 1;
1890 w = wwin->frame->core->width;
1891 XMoveWindow(dpy, wwin->client_win, 0, y);
1892 if (s > 0) {
1893 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1894 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1895 XMoveWindow(dpy, wwin->client_win, 0, y);
1896 XFlush(dpy);
1897 if (SHADE_DELAY > 0) {
1898 wusleep(SHADE_DELAY * 2000L / 3);
1899 } else {
1900 wusleep(10);
1902 h += s;
1903 y += s;
1905 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1906 break;
1909 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1910 break;
1913 #else
1914 static void shade_animate(WWindow *wwin, Bool what) { return; }
1915 #endif /* ANIMATIONS */