code review
[wmaker-crm.git] / src / actions.c
blobeb453ab3e9085b5090558a7f5d979c7efb94501d
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"
27 #include <X11/Xlib.h>
28 #include <X11/Xutil.h>
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <unistd.h>
32 #include <math.h>
33 #include <time.h>
35 #include "WindowMaker.h"
36 #include "wcore.h"
37 #include "framewin.h"
38 #include "window.h"
39 #include "client.h"
40 #include "icon.h"
41 #include "funcs.h"
42 #include "application.h"
43 #include "actions.h"
44 #include "stacking.h"
45 #include "appicon.h"
46 #include "dock.h"
47 #include "appmenu.h"
48 #include "winspector.h"
49 #include "workspace.h"
50 #include "wsound.h"
51 #include "xinerama.h"
54 /****** Global Variables ******/
55 extern Time LastTimestamp;
56 extern Time LastFocusChange;
58 extern Cursor wCursor[WCUR_LAST];
60 extern WPreferences wPreferences;
62 extern Atom _XA_WM_TAKE_FOCUS;
64 extern void ProcessPendingEvents();
67 /******* Local Variables *******/
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}};
78 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
79 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
83 *----------------------------------------------------------------------
84 * wSetFocusTo--
85 * Changes the window focus to the one passed as argument.
86 * If the window to focus is not already focused, it will be brought
87 * to the head of the list of windows. Previously focused window is
88 * unfocused.
90 * Side effects:
91 * Window list may be reordered and the window focus is changed.
93 *----------------------------------------------------------------------
95 void
96 wSetFocusTo(WScreen *scr, WWindow *wwin)
98 static WScreen *old_scr=NULL;
100 WWindow *old_focused;
101 WWindow *focused=scr->focused_window;
102 int timestamp=LastTimestamp;
103 WApplication *oapp=NULL, *napp=NULL;
104 int wasfocused;
106 if (scr->flags.ignore_focus_events || LastFocusChange > timestamp)
107 return;
109 if (!old_scr)
110 old_scr=scr;
111 old_focused=old_scr->focused_window;
113 LastFocusChange = timestamp;
115 if (old_focused)
116 oapp = wApplicationOf(old_focused->main_window);
118 if (wwin == NULL) {
119 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
120 if (old_focused) {
121 wWindowUnfocus(old_focused);
123 if (oapp) {
124 wAppMenuUnmap(oapp->menu);
125 #ifdef NEWAPPICON
126 wApplicationDeactivate(oapp);
127 #endif
130 WMPostNotificationName(WMNChangedFocus, NULL, (void*)True);
131 return;
132 } else if (old_scr != scr && old_focused) {
133 wWindowUnfocus(old_focused);
136 wasfocused = wwin->flags.focused;
137 napp = wApplicationOf(wwin->main_window);
139 /* remember last workspace where the app has been */
140 if (napp) {
141 /*napp->last_workspace = wwin->screen_ptr->current_workspace;*/
142 napp->last_workspace = wwin->frame->workspace;
145 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
146 /* install colormap if colormap mode is lock mode */
147 if (wPreferences.colormap_mode==WCM_CLICK)
148 wColormapInstallForWindow(scr, wwin);
150 /* set input focus */
151 switch (wwin->focus_mode) {
152 case WFM_NO_INPUT:
153 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
154 break;
156 case WFM_PASSIVE:
157 case WFM_LOCALLY_ACTIVE:
158 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
159 break;
161 case WFM_GLOBALLY_ACTIVE:
162 break;
164 XFlush(dpy);
165 if (wwin->protocols.TAKE_FOCUS) {
166 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
168 XSync(dpy, False);
169 } else {
170 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
172 if (WFLAGP(wwin, no_focusable))
173 return;
175 /* if this is not the focused window focus it */
176 if (focused!=wwin) {
177 /* change the focus window list order */
178 if (wwin->prev)
179 wwin->prev->next = wwin->next;
181 if (wwin->next)
182 wwin->next->prev = wwin->prev;
184 wwin->prev = focused;
185 focused->next = wwin;
186 wwin->next = NULL;
187 scr->focused_window = wwin;
189 if (oapp && oapp != napp) {
190 wAppMenuUnmap(oapp->menu);
191 #ifdef NEWAPPICON
192 wApplicationDeactivate(oapp);
193 #endif
197 wWindowFocus(wwin, focused);
199 if (napp && !wasfocused) {
200 #ifdef USER_MENU
201 wUserMenuRefreshInstances(napp->menu, wwin);
202 #endif /* USER_MENU */
204 if (wwin->flags.mapped)
205 wAppMenuMap(napp->menu, wwin);
206 #ifdef NEWAPPICON
207 wApplicationActivate(napp);
208 #endif
211 XFlush(dpy);
212 old_scr=scr;
216 void
217 wShadeWindow(WWindow *wwin)
219 time_t time0;
220 #ifdef ANIMATIONS
221 int y, s, w, h;
222 #endif
224 if (wwin->flags.shaded)
225 return;
227 time0 = time(NULL);
229 XLowerWindow(dpy, wwin->client_win);
231 wSoundPlay(WSOUND_SHADE);
233 #ifdef ANIMATIONS
234 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
235 && !wPreferences.no_animations) {
236 /* do the shading animation */
237 h = wwin->frame->core->height;
238 s = h/SHADE_STEPS;
239 if (s < 1) s=1;
240 w = wwin->frame->core->width;
241 y = wwin->frame->top_width;
242 while (h>wwin->frame->top_width+1) {
243 XMoveWindow(dpy, wwin->client_win, 0, y);
244 XResizeWindow(dpy, wwin->frame->core->window, w, h);
245 XFlush(dpy);
247 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
248 break;
250 if (SHADE_DELAY > 0) {
251 wusleep(SHADE_DELAY*1000L);
252 } else {
253 wusleep(10);
255 h-=s;
256 y-=s;
258 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
260 #endif /* ANIMATIONS */
262 wwin->flags.skip_next_animation = 0;
263 wwin->flags.shaded = 1;
264 wwin->flags.mapped = 0;
265 /* prevent window withdrawal when getting UnmapNotify */
266 XSelectInput(dpy, wwin->client_win,
267 wwin->event_mask & ~StructureNotifyMask);
268 XUnmapWindow(dpy, wwin->client_win);
269 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
271 /* for the client it's just like iconification */
272 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
273 wwin->frame->top_width - 1);
275 wwin->client.y = wwin->frame_y - wwin->client.height
276 + wwin->frame->top_width;
277 wWindowSynthConfigureNotify(wwin);
280 wClientSetState(wwin, IconicState, None);
283 WMPostNotificationName(WMNChangedState, wwin, "shade");
285 #ifdef ANIMATIONS
286 if (!wwin->screen_ptr->flags.startup) {
287 /* Catch up with events not processed while animation was running */
288 ProcessPendingEvents();
290 #endif
294 void
295 wUnshadeWindow(WWindow *wwin)
297 time_t time0;
298 #ifdef ANIMATIONS
299 int y, s, w, h;
300 #endif /* ANIMATIONS */
303 if (!wwin->flags.shaded)
304 return;
306 time0 = time(NULL);
308 wwin->flags.shaded = 0;
309 wwin->flags.mapped = 1;
310 XMapWindow(dpy, wwin->client_win);
312 wSoundPlay(WSOUND_UNSHADE);
314 #ifdef ANIMATIONS
315 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
316 /* do the shading animation */
317 h = wwin->frame->top_width + wwin->frame->bottom_width;
318 y = wwin->frame->top_width - wwin->client.height;
319 s = abs(y)/SHADE_STEPS;
320 if (s<1) s=1;
321 w = wwin->frame->core->width;
322 XMoveWindow(dpy, wwin->client_win, 0, y);
323 if (s>0) {
324 while (h < wwin->client.height + wwin->frame->top_width
325 + wwin->frame->bottom_width) {
326 XResizeWindow(dpy, wwin->frame->core->window, w, h);
327 XMoveWindow(dpy, wwin->client_win, 0, y);
328 XFlush(dpy);
329 if (SHADE_DELAY > 0) {
330 wusleep(SHADE_DELAY*2000L/3);
331 } else {
332 wusleep(10);
334 h+=s;
335 y+=s;
337 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
338 break;
341 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
343 #endif /* ANIMATIONS */
345 wwin->flags.skip_next_animation = 0;
346 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
347 wwin->frame->top_width + wwin->client.height
348 + wwin->frame->bottom_width);
350 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
351 wWindowSynthConfigureNotify(wwin);
354 wClientSetState(wwin, NormalState, None);
356 /* if the window is focused, set the focus again as it was disabled during
357 * shading */
358 if (wwin->flags.focused)
359 wSetFocusTo(wwin->screen_ptr, wwin);
361 WMPostNotificationName(WMNChangedState, wwin, "shade");
365 void
366 wMaximizeWindow(WWindow *wwin, int directions)
368 int new_width, new_height, new_x, new_y;
369 int changed_h, changed_v, shrink_h, shrink_v;
370 WArea usableArea, totalArea;
372 if (!IS_RESIZABLE(wwin))
373 return;
375 totalArea.x1 = 0;
376 totalArea.y1 = 0;
377 totalArea.x2 = wwin->screen_ptr->scr_width;
378 totalArea.y2 = wwin->screen_ptr->scr_height;
379 usableArea = totalArea;
381 if (!(directions & MAX_IGNORE_XINERAMA)) {
382 WScreen *scr = wwin->screen_ptr;
383 int head;
385 if (directions & MAX_KEYBOARD)
386 head = wGetHeadForWindow(wwin);
387 else
388 head = wGetHeadForPointerLocation(scr);
390 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
393 if (WFLAGP(wwin, full_maximize)) {
394 usableArea = totalArea;
397 if (wwin->flags.shaded) {
398 wwin->flags.skip_next_animation = 1;
399 wUnshadeWindow(wwin);
401 /* Only save directions, not kbd or xinerama hints */
402 directions &= (MAX_HORIZONTAL|MAX_VERTICAL);
404 changed_h = ((wwin->flags.maximized ^ directions) & MAX_HORIZONTAL);
405 changed_v = ((wwin->flags.maximized ^ directions) & MAX_VERTICAL);
406 shrink_h = (changed_h && (directions & MAX_HORIZONTAL)==0);
407 shrink_v = (changed_v && (directions & MAX_VERTICAL)==0);
409 if (wwin->flags.maximized) {
410 /* if already maximized in some direction, we only update the
411 * appropriate old x, old y coordinates. This is necessary to
412 * allow succesive maximizations in different directions without
413 * the need to first do an un-maximize (to avoid flicker).
415 if (!(wwin->flags.maximized & MAX_HORIZONTAL)) {
416 wwin->old_geometry.x = wwin->frame_x;
418 if (!(wwin->flags.maximized & MAX_VERTICAL)) {
419 wwin->old_geometry.y = wwin->frame_y;
421 } else {
422 wwin->old_geometry.width = wwin->client.width;
423 wwin->old_geometry.height = wwin->client.height;
424 wwin->old_geometry.x = wwin->frame_x;
425 wwin->old_geometry.y = wwin->frame_y;
427 wwin->flags.maximized = directions;
429 if (directions & MAX_HORIZONTAL) {
430 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
431 new_x = usableArea.x1;
432 } else if (shrink_h) {
433 new_x = wwin->old_geometry.x;
434 new_width = wwin->old_geometry.width;
435 } else {
436 new_x = wwin->frame_x;
437 new_width = wwin->frame->core->width;
440 if (directions & MAX_VERTICAL) {
441 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
442 new_y = usableArea.y1;
443 if (WFLAGP(wwin, full_maximize)) {
444 new_y -= wwin->frame->top_width;
445 new_height += wwin->frame->bottom_width - 1;
447 } else if (shrink_v) {
448 new_y = wwin->old_geometry.y;
449 new_height = wwin->old_geometry.height;
450 } else {
451 new_y = wwin->frame_y;
452 new_height = wwin->frame->core->height;
455 if (!WFLAGP(wwin, full_maximize)) {
456 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
459 wWindowConstrainSize(wwin, &new_width, &new_height);
461 wWindowCropSize(wwin, usableArea.x2-usableArea.x1,
462 usableArea.y2-usableArea.y1,
463 &new_width, &new_height);
465 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
468 WMPostNotificationName(WMNChangedState, wwin, "maximize");
470 wSoundPlay(WSOUND_MAXIMIZE);
474 void
475 wUnmaximizeWindow(WWindow *wwin)
477 int restore_x, restore_y;
479 if (!wwin->flags.maximized)
480 return;
482 if (wwin->flags.shaded) {
483 wwin->flags.skip_next_animation = 1;
484 wUnshadeWindow(wwin);
486 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
487 wwin->old_geometry.x : wwin->frame_x;
488 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
489 wwin->old_geometry.y : wwin->frame_y;
490 wwin->flags.maximized = 0;
491 wWindowConfigure(wwin, restore_x, restore_y,
492 wwin->old_geometry.width, wwin->old_geometry.height);
494 WMPostNotificationName(WMNChangedState, wwin, "maximize");
496 wSoundPlay(WSOUND_UNMAXIMIZE);
500 void
501 wFullscreenWindow(WWindow *wwin)
503 int head;
504 WMRect rect;
506 if (wwin->flags.fullscreen)
507 return;
509 wwin->flags.fullscreen = True;
511 wWindowConfigureBorders(wwin);
513 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
515 wwin->bfs_geometry.x = wwin->frame_x;
516 wwin->bfs_geometry.y = wwin->frame_y;
517 wwin->bfs_geometry.width = wwin->frame->core->width;
518 wwin->bfs_geometry.height = wwin->frame->core->height;
520 head = wGetHeadForWindow(wwin);
521 rect = wGetRectForHead(wwin->screen_ptr, head);
522 wWindowConfigure(wwin, rect.pos.x, rect.pos.y,
523 rect.size.width, rect.size.height);
525 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
529 void
530 wUnfullscreenWindow(WWindow *wwin)
532 if (!wwin->flags.fullscreen)
533 return;
535 wwin->flags.fullscreen = False;
537 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
538 if (WFLAGP(wwin, sunken)) {
539 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
540 } else if (WFLAGP(wwin, floating)) {
541 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
542 } else {
543 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
547 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
548 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
550 wWindowConfigureBorders(wwin);
552 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
553 wFrameWindowPaint(wwin->frame);
556 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
560 #ifdef ANIMATIONS
561 static void
562 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
563 int fx, int fy, int fw, int fh, int steps)
565 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
566 float cx, cy, cw, ch;
567 float xstep, ystep, wstep, hstep;
568 XPoint points[5];
569 float dx, dch, midy;
570 float angle, final_angle, delta;
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_F;
583 delta = (float)(final_angle/FRAMES);
584 for (angle=0;; angle+=delta) {
585 if (angle > final_angle)
586 angle = final_angle;
588 dx = (cw/10) - ((cw/5) * sin(angle));
589 dch = (ch/2) * cos(angle);
590 midy = cy + (ch/2);
592 points[0].x = cx + dx; points[0].y = midy - dch;
593 points[1].x = cx + cw - dx; points[1].y = points[0].y;
594 points[2].x = cx + cw + dx; points[2].y = midy + dch;
595 points[3].x = cx - dx; points[3].y = points[2].y;
596 points[4].x = points[0].x; points[4].y = points[0].y;
598 XGrabServer(dpy);
599 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
600 XFlush(dpy);
601 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
602 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
603 #else
604 wusleep(10);
605 #endif
607 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
608 XUngrabServer(dpy);
609 cx+=xstep;
610 cy+=ystep;
611 cw+=wstep;
612 ch+=hstep;
613 if (angle >= final_angle)
614 break;
617 XFlush(dpy);
619 #undef FRAMES
622 static void
623 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
624 int fx, int fy, int fw, int fh, int steps)
626 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
627 float cx, cy, cw, ch;
628 float xstep, ystep, wstep, hstep;
629 XPoint points[5];
630 float angle, final_angle, a, d, delta;
632 x += w/2;
633 y += h/2;
634 fx += fw/2;
635 fy += fh/2;
637 xstep = (float)(fx-x)/steps;
638 ystep = (float)(fy-y)/steps;
639 wstep = (float)(fw-w)/steps;
640 hstep = (float)(fh-h)/steps;
642 cx = (float)x;
643 cy = (float)y;
644 cw = (float)w;
645 ch = (float)h;
647 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
648 delta = (float)(final_angle/FRAMES);
649 for (angle=0;; angle+=delta) {
650 if (angle > final_angle)
651 angle = final_angle;
653 a = atan(ch/cw);
654 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
656 points[0].x = cx+cos(angle-a)*d;
657 points[0].y = cy+sin(angle-a)*d;
658 points[1].x = cx+cos(angle+a)*d;
659 points[1].y = cy+sin(angle+a)*d;
660 points[2].x = cx+cos(angle-a+WM_PI)*d;
661 points[2].y = cy+sin(angle-a+WM_PI)*d;
662 points[3].x = cx+cos(angle+a+WM_PI)*d;
663 points[3].y = cy+sin(angle+a+WM_PI)*d;
664 points[4].x = cx+cos(angle-a)*d;
665 points[4].y = cy+sin(angle-a)*d;
666 XGrabServer(dpy);
667 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
668 XFlush(dpy);
669 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
670 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
671 #else
672 wusleep(10);
673 #endif
675 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
676 XUngrabServer(dpy);
677 cx+=xstep;
678 cy+=ystep;
679 cw+=wstep;
680 ch+=hstep;
681 if (angle >= final_angle)
682 break;
685 XFlush(dpy);
687 #undef FRAMES
690 static void
691 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
692 int fx, int fy, int fw, int fh, int steps)
694 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
695 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
696 float xstep, ystep, wstep, hstep;
697 int i, j;
699 xstep = (float)(fx-x)/steps;
700 ystep = (float)(fy-y)/steps;
701 wstep = (float)(fw-w)/steps;
702 hstep = (float)(fh-h)/steps;
704 for (j=0; j<FRAMES; j++) {
705 cx[j] = (float)x;
706 cy[j] = (float)y;
707 cw[j] = (float)w;
708 ch[j] = (float)h;
710 XGrabServer(dpy);
711 for (i=0; i<steps; i++) {
712 for (j=0; j<FRAMES; j++) {
713 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
714 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
716 XFlush(dpy);
717 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
718 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
719 #else
720 wusleep(10);
721 #endif
722 for (j=0; j<FRAMES; j++) {
723 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
724 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
725 if (j<FRAMES-1) {
726 cx[j]=cx[j+1];
727 cy[j]=cy[j+1];
728 cw[j]=cw[j+1];
729 ch[j]=ch[j+1];
730 } else {
731 cx[j]+=xstep;
732 cy[j]+=ystep;
733 cw[j]+=wstep;
734 ch[j]+=hstep;
739 for (j=0; j<FRAMES; j++) {
740 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
741 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
743 XFlush(dpy);
744 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
745 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
746 #else
747 wusleep(10);
748 #endif
749 for (j=0; j<FRAMES; j++) {
750 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
751 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
754 XUngrabServer(dpy);
756 #undef FRAMES
759 void
760 animateResize(WScreen *scr, int x, int y, int w, int h,
761 int fx, int fy, int fw, int fh, int hiding)
763 int style = wPreferences.iconification_style; /* Catch the value */
764 int steps, k;
766 if (style == WIS_NONE)
767 return;
769 if (style == WIS_RANDOM) {
770 style = rand()%3;
773 k = (hiding ? 2 : 3);
774 switch(style) {
775 case WIS_TWIST:
776 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
777 if (steps>0)
778 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
779 break;
780 case WIS_FLIP:
781 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
782 if (steps>0)
783 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
784 break;
785 case WIS_ZOOM:
786 default:
787 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
788 if (steps>0)
789 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
790 break;
793 #endif /* ANIMATIONS */
796 static void
797 flushExpose()
799 XEvent tmpev;
801 while (XCheckTypedEvent(dpy, Expose, &tmpev))
802 WMHandleEvent(&tmpev);
803 XSync(dpy, 0);
806 static void
807 unmapTransientsFor(WWindow *wwin)
809 WWindow *tmp;
812 tmp = wwin->screen_ptr->focused_window;
813 while (tmp) {
814 /* unmap the transients for this transient */
815 if (tmp!=wwin && tmp->transient_for == wwin->client_win
816 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
817 || tmp->flags.shaded)) {
818 unmapTransientsFor(tmp);
819 tmp->flags.miniaturized = 1;
820 if (!tmp->flags.shaded) {
821 wWindowUnmap(tmp);
822 } else {
823 XUnmapWindow(dpy, tmp->frame->core->window);
826 if (!tmp->flags.shaded)
828 wClientSetState(tmp, IconicState, None);
830 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
832 tmp = tmp->prev;
837 static void
838 mapTransientsFor(WWindow *wwin)
840 WWindow *tmp;
842 tmp = wwin->screen_ptr->focused_window;
843 while (tmp) {
844 /* recursively map the transients for this transient */
845 if (tmp!=wwin && tmp->transient_for == wwin->client_win
846 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
847 && tmp->icon==NULL) {
848 mapTransientsFor(tmp);
849 tmp->flags.miniaturized = 0;
850 if (!tmp->flags.shaded) {
851 wWindowMap(tmp);
852 } else {
853 XMapWindow(dpy, tmp->frame->core->window);
855 tmp->flags.semi_focused = 0;
857 if (!tmp->flags.shaded)
859 wClientSetState(tmp, NormalState, None);
861 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
863 tmp = tmp->prev;
867 #if 0
868 static void
869 setupIconGrabs(WIcon *icon)
871 /* setup passive grabs on the icon */
872 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
873 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
874 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
875 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
876 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
877 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
878 XSync(dpy, 0);
880 #endif
882 static WWindow*
883 recursiveTransientFor(WWindow *wwin)
885 int i;
887 if (!wwin)
888 return None;
890 /* hackish way to detect transient_for cycle */
891 i = wwin->screen_ptr->window_count+1;
893 while (wwin && wwin->transient_for != None && i>0) {
894 wwin = wWindowFor(wwin->transient_for);
895 i--;
897 if (i==0 && wwin) {
898 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
899 wwin->frame->title);
900 return NULL;
903 return wwin;
906 #if 0
907 static void
908 removeIconGrabs(WIcon *icon)
910 /* remove passive grabs on the icon */
911 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
912 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
913 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
914 XSync(dpy, 0);
916 #endif
919 void
920 wIconifyWindow(WWindow *wwin)
922 XWindowAttributes attribs;
923 int present;
926 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
927 /* the window doesn't exist anymore */
928 return;
931 if (wwin->flags.miniaturized) {
932 return;
935 if (wwin->transient_for!=None &&
936 wwin->transient_for!=wwin->screen_ptr->root_win) {
937 WWindow *owner = wWindowFor(wwin->transient_for);
939 if (owner && owner->flags.miniaturized)
940 return;
943 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
945 /* if the window is in another workspace, simplify process */
946 if (present) {
947 /* icon creation may take a while */
948 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
949 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
950 GrabModeAsync, None, None, CurrentTime);
953 if (!wPreferences.disable_miniwindows
954 #ifdef NETWM_HINTS
955 && !wwin->flags.net_handle_icon
956 #endif
958 if (!wwin->flags.icon_moved) {
959 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
961 wwin->icon = wIconCreate(wwin);
963 wwin->icon->mapped = 1;
966 wwin->flags.miniaturized = 1;
967 wwin->flags.mapped = 0;
969 /* unmap transients */
971 unmapTransientsFor(wwin);
973 if (present) {
974 wSoundPlay(WSOUND_ICONIFY);
976 XUngrabPointer(dpy, CurrentTime);
977 wWindowUnmap(wwin);
978 /* let all Expose events arrive so that we can repaint
979 * something before the animation starts (and the server is grabbed) */
980 XSync(dpy, 0);
982 if (wPreferences.disable_miniwindows
983 #ifdef NETWM_HINTS
984 || wwin->flags.net_handle_icon
985 #endif
987 wClientSetState(wwin, IconicState, None);
988 else
989 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
991 flushExpose();
992 #ifdef ANIMATIONS
993 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
994 && !wPreferences.no_animations) {
995 int ix, iy, iw, ih;
997 if (!wPreferences.disable_miniwindows
998 #ifdef NETWM_HINTS
999 && !wwin->flags.net_handle_icon
1000 #endif
1002 ix = wwin->icon_x;
1003 iy = wwin->icon_y;
1004 iw = wwin->icon->core->width;
1005 ih = wwin->icon->core->height;
1006 } else {
1007 #ifdef NETWM_HINTS
1008 if (wwin->flags.net_handle_icon) {
1009 ix = wwin->icon_x;
1010 iy = wwin->icon_y;
1011 iw = wwin->icon_w;
1012 ih = wwin->icon_h;
1013 } else
1014 #endif
1016 ix = 0;
1017 iy = 0;
1018 iw = wwin->screen_ptr->scr_width;
1019 ih = wwin->screen_ptr->scr_height;
1022 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1023 wwin->frame->core->width, wwin->frame->core->height,
1024 ix, iy, iw, ih, False);
1026 #endif
1029 wwin->flags.skip_next_animation = 0;
1031 if (!wPreferences.disable_miniwindows
1032 #ifdef NETWM_HINTS
1033 && !wwin->flags.net_handle_icon
1034 #endif
1037 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
1038 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1040 XMapWindow(dpy, wwin->icon->core->window);
1042 AddToStackList(wwin->icon->core);
1044 wLowerFrame(wwin->icon->core);
1047 if (present) {
1048 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1051 * It doesn't seem to be working and causes button event hangup
1052 * when deiconifying a transient window.
1053 setupIconGrabs(wwin->icon);
1055 if ((wwin->flags.focused
1056 || (owner && wwin->client_win == owner->client_win))
1057 && wPreferences.focus_mode==WKF_CLICK) {
1058 WWindow *tmp;
1060 tmp = wwin->prev;
1061 while (tmp) {
1062 if (!WFLAGP(tmp, no_focusable)
1063 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1064 && (wwin->frame->workspace == tmp->frame->workspace))
1065 break;
1066 tmp = tmp->prev;
1068 wSetFocusTo(wwin->screen_ptr, tmp);
1069 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1070 wSetFocusTo(wwin->screen_ptr, NULL);
1073 #ifdef ANIMATIONS
1074 if (!wwin->screen_ptr->flags.startup) {
1075 /* Catch up with events not processed while animation was running */
1076 Window clientwin = wwin->client_win;
1078 ProcessPendingEvents();
1080 /* the window can disappear while ProcessPendingEvents() runs */
1081 if (!wWindowFor(clientwin)) {
1082 return;
1085 #endif
1088 /* maybe we want to do this regardless of net_handle_icon
1089 * it seems to me we might break behaviour this way.
1091 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1092 #ifdef NETWM_HINTS
1093 && !wwin->flags.net_handle_icon
1094 #endif
1096 wIconSelect(wwin->icon);
1098 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1104 void
1105 wDeiconifyWindow(WWindow *wwin)
1107 #ifdef NETWM_HINTS
1108 /* we're hiding for show_desktop */
1109 int netwm_hidden = wwin->flags.net_show_desktop &&
1110 wwin->frame->workspace!=wwin->screen_ptr->current_workspace;
1111 #else
1112 int netwm_hidden = False;
1113 #endif
1115 if (!netwm_hidden)
1116 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1118 if (!wwin->flags.miniaturized)
1119 return;
1121 if (wwin->transient_for != None
1122 && wwin->transient_for != wwin->screen_ptr->root_win) {
1123 WWindow *owner = recursiveTransientFor(wwin);
1125 if (owner && owner->flags.miniaturized) {
1126 wDeiconifyWindow(owner);
1127 wSetFocusTo(wwin->screen_ptr, wwin);
1128 wRaiseFrame(wwin->frame->core);
1129 return;
1133 wwin->flags.miniaturized = 0;
1135 if (!netwm_hidden && !wwin->flags.shaded) {
1136 wwin->flags.mapped = 1;
1139 if (!netwm_hidden || wPreferences.sticky_icons) {
1140 /* maybe we want to do this regardless of net_handle_icon
1141 * it seems to me we might break behaviour this way.
1143 if (!wPreferences.disable_miniwindows
1144 #ifdef NETWM_HINTS
1145 && !wwin->flags.net_handle_icon
1146 #endif
1147 && wwin->icon != NULL) {
1148 if (wwin->icon->selected)
1149 wIconSelect(wwin->icon);
1151 XUnmapWindow(dpy, wwin->icon->core->window);
1155 if (!netwm_hidden)
1156 wSoundPlay(WSOUND_DEICONIFY);
1158 /* if the window is in another workspace, do it silently */
1159 if (!netwm_hidden) {
1160 #ifdef ANIMATIONS
1161 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1162 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1163 int ix, iy, iw, ih;
1165 if (!wPreferences.disable_miniwindows
1166 #ifdef NETWM_HINTS
1167 && !wwin->flags.net_handle_icon
1168 #endif
1170 ix = wwin->icon_x;
1171 iy = wwin->icon_y;
1172 iw = wwin->icon->core->width;
1173 ih = wwin->icon->core->height;
1174 } else {
1175 #ifdef NETWM_HINTS
1176 if (wwin->flags.net_handle_icon) {
1177 ix = wwin->icon_x;
1178 iy = wwin->icon_y;
1179 iw = wwin->icon_w;
1180 ih = wwin->icon_h;
1181 } else
1182 #endif
1184 ix = 0;
1185 iy = 0;
1186 iw = wwin->screen_ptr->scr_width;
1187 ih = wwin->screen_ptr->scr_height;
1190 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1191 wwin->frame_x, wwin->frame_y,
1192 wwin->frame->core->width, wwin->frame->core->height,
1193 False);
1195 #endif /* ANIMATIONS */
1196 wwin->flags.skip_next_animation = 0;
1197 XGrabServer(dpy);
1198 if (!wwin->flags.shaded) {
1199 XMapWindow(dpy, wwin->client_win);
1201 XMapWindow(dpy, wwin->frame->core->window);
1202 wRaiseFrame(wwin->frame->core);
1203 if (!wwin->flags.shaded) {
1204 wClientSetState(wwin, NormalState, None);
1206 mapTransientsFor(wwin);
1209 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1210 #ifdef NETWM_HINTS
1211 && !wwin->flags.net_handle_icon
1212 #endif
1214 RemoveFromStackList(wwin->icon->core);
1215 /* removeIconGrabs(wwin->icon);*/
1216 wIconDestroy(wwin->icon);
1217 wwin->icon = NULL;
1220 if (!netwm_hidden) {
1221 XUngrabServer(dpy);
1223 wSetFocusTo(wwin->screen_ptr, wwin);
1225 #ifdef ANIMATIONS
1226 if (!wwin->screen_ptr->flags.startup) {
1227 /* Catch up with events not processed while animation was running */
1228 Window clientwin = wwin->client_win;
1230 ProcessPendingEvents();
1232 /* the window can disappear while ProcessPendingEvents() runs */
1233 if (!wWindowFor(clientwin)) {
1234 return;
1237 #endif
1240 if (wPreferences.auto_arrange_icons) {
1241 wArrangeIcons(wwin->screen_ptr, True);
1244 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1246 /* In case we were shaded and iconified, also unshade */
1247 if (!netwm_hidden)
1248 wUnshadeWindow(wwin);
1253 static void
1254 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1256 if (wwin->flags.miniaturized) {
1257 if (wwin->icon) {
1258 XUnmapWindow(dpy, wwin->icon->core->window);
1259 wwin->icon->mapped = 0;
1261 wwin->flags.hidden = 1;
1263 WMPostNotificationName(WMNChangedState, wwin, "hide");
1264 return;
1267 if (wwin->flags.inspector_open) {
1268 wHideInspectorForWindow(wwin);
1271 wwin->flags.hidden = 1;
1272 wWindowUnmap(wwin);
1274 wClientSetState(wwin, IconicState, icon->icon_win);
1275 flushExpose();
1276 wSoundPlay(WSOUND_HIDE);
1277 #ifdef ANIMATIONS
1278 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1279 !wwin->flags.skip_next_animation && animate) {
1280 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1281 wwin->frame->core->width, wwin->frame->core->height,
1282 icon_x, icon_y, icon->core->width, icon->core->height,
1283 True);
1285 #endif
1286 wwin->flags.skip_next_animation = 0;
1288 WMPostNotificationName(WMNChangedState, wwin, "hide");
1293 void
1294 wHideOtherApplications(WWindow *awin)
1296 WWindow *wwin;
1297 WApplication *tapp;
1299 if (!awin)
1300 return;
1301 wwin = awin->screen_ptr->focused_window;
1304 while (wwin) {
1305 if (wwin!=awin
1306 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1307 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1308 && !wwin->flags.internal_window
1309 && wGetWindowOfInspectorForWindow(wwin) != awin
1310 && !WFLAGP(wwin, no_hide_others)) {
1312 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1313 if (!WFLAGP(wwin, no_miniaturizable)) {
1314 wwin->flags.skip_next_animation = 1;
1315 wIconifyWindow(wwin);
1317 } else if (wwin->main_window!=None
1318 && awin->main_window != wwin->main_window) {
1319 tapp = wApplicationOf(wwin->main_window);
1320 if (tapp) {
1321 tapp->flags.skip_next_animation = 1;
1322 wHideApplication(tapp);
1323 } else {
1324 if (!WFLAGP(wwin, no_miniaturizable)) {
1325 wwin->flags.skip_next_animation = 1;
1326 wIconifyWindow(wwin);
1331 wwin = wwin->prev;
1334 wSetFocusTo(awin->screen_ptr, awin);
1340 void
1341 wHideApplication(WApplication *wapp)
1343 WScreen *scr;
1344 WWindow *wlist;
1345 int hadfocus;
1347 if (!wapp) {
1348 wwarning("trying to hide a non grouped window");
1349 return;
1351 if (!wapp->main_window_desc) {
1352 wwarning("group leader not found for window group");
1353 return;
1355 scr = wapp->main_window_desc->screen_ptr;
1356 hadfocus = 0;
1357 wlist = scr->focused_window;
1358 if (!wlist)
1359 return;
1361 if (wlist->main_window == wapp->main_window)
1362 wapp->last_focused = wlist;
1363 else
1364 wapp->last_focused = NULL;
1365 while (wlist) {
1366 if (wlist->main_window == wapp->main_window) {
1367 if (wlist->flags.focused) {
1368 hadfocus = 1;
1370 if (wapp->app_icon)
1371 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1372 wapp->app_icon->y_pos, wlist,
1373 !wapp->flags.skip_next_animation);
1375 wlist = wlist->prev;
1378 wapp->flags.skip_next_animation = 0;
1380 if (hadfocus) {
1381 if (wPreferences.focus_mode==WKF_CLICK) {
1382 wlist = scr->focused_window;
1383 while (wlist) {
1384 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1385 && (wlist->flags.mapped || wlist->flags.shaded))
1386 break;
1387 wlist = wlist->prev;
1389 wSetFocusTo(scr, wlist);
1390 } else {
1391 wSetFocusTo(scr, NULL);
1395 wapp->flags.hidden = 1;
1397 if(wPreferences.auto_arrange_icons) {
1398 wArrangeIcons(scr, True);
1400 #ifdef HIDDENDOT
1401 if (wapp->app_icon)
1402 wAppIconPaint(wapp->app_icon);
1403 #endif
1409 static void
1410 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1411 int bringToCurrentWS)
1413 if (bringToCurrentWS)
1414 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1416 wwin->flags.hidden=0;
1418 wSoundPlay(WSOUND_UNHIDE);
1419 #ifdef ANIMATIONS
1420 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1421 && animate) {
1422 animateResize(wwin->screen_ptr, icon_x, icon_y,
1423 icon->core->width, icon->core->height,
1424 wwin->frame_x, wwin->frame_y,
1425 wwin->frame->core->width, wwin->frame->core->height,
1426 True);
1428 #endif
1429 wwin->flags.skip_next_animation = 0;
1430 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1431 XMapWindow(dpy, wwin->client_win);
1432 XMapWindow(dpy, wwin->frame->core->window);
1433 wClientSetState(wwin, NormalState, None);
1434 wwin->flags.mapped=1;
1435 wRaiseFrame(wwin->frame->core);
1437 if (wwin->flags.inspector_open) {
1438 wUnhideInspectorForWindow(wwin);
1441 WMPostNotificationName(WMNChangedState, wwin, "hide");
1445 void
1446 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1448 WScreen *scr;
1449 WWindow *wlist, *next;
1450 WWindow *focused=NULL;
1451 Bool shouldArrangeIcons = False;
1453 if (!wapp)
1454 return;
1456 scr = wapp->main_window_desc->screen_ptr;
1457 wlist = scr->focused_window;
1458 if (!wlist)
1459 return;
1461 /* goto beginning of list */
1462 while (wlist->prev)
1463 wlist = wlist->prev;
1465 while (wlist) {
1466 next = wlist->next;
1468 if (wlist->main_window == wapp->main_window) {
1469 if (wlist->flags.focused)
1470 focused = wlist;
1471 else if (!focused || !focused->flags.focused)
1472 focused = wlist;
1474 if (wlist->flags.miniaturized) {
1475 if (bringToCurrentWS || wPreferences.sticky_icons ||
1476 wlist->frame->workspace == scr->current_workspace) {
1477 if (wlist->icon && !wlist->icon->mapped) {
1478 XMapWindow(dpy, wlist->icon->core->window);
1479 wlist->icon->mapped = 1;
1482 if (bringToCurrentWS)
1483 wWindowChangeWorkspace(wlist, scr->current_workspace);
1484 wlist->flags.hidden = 0;
1485 if (miniwindows &&
1486 wlist->frame->workspace == scr->current_workspace) {
1487 wDeiconifyWindow(wlist);
1489 shouldArrangeIcons = True;
1490 WMPostNotificationName(WMNChangedState, wlist, "hide");
1491 } else if (wlist->flags.shaded) {
1492 if (bringToCurrentWS)
1493 wWindowChangeWorkspace(wlist, scr->current_workspace);
1494 wlist->flags.hidden = 0;
1495 if (wlist->frame->workspace == scr->current_workspace) {
1496 XMapWindow(dpy, wlist->frame->core->window);
1497 if (miniwindows) {
1498 wUnshadeWindow(wlist);
1499 wRaiseFrame(wlist->frame->core);
1502 WMPostNotificationName(WMNChangedState, wlist, "hide");
1503 } else if (wlist->flags.hidden) {
1504 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1505 wapp->app_icon->y_pos, wlist,
1506 !wapp->flags.skip_next_animation,
1507 bringToCurrentWS);
1508 } else {
1509 if (bringToCurrentWS
1510 && wlist->frame->workspace != scr->current_workspace) {
1511 wWindowChangeWorkspace(wlist, scr->current_workspace);
1513 wRaiseFrame(wlist->frame->core);
1516 wlist = next;
1519 wapp->flags.skip_next_animation = 0;
1520 wapp->flags.hidden = 0;
1522 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1523 wRaiseFrame(wapp->last_focused->frame->core);
1524 wSetFocusTo(scr, wapp->last_focused);
1525 } else if (focused) {
1526 wSetFocusTo(scr, focused);
1528 wapp->last_focused = NULL;
1529 if (shouldArrangeIcons || wPreferences.auto_arrange_icons) {
1530 wArrangeIcons(scr, True);
1532 #ifdef HIDDENDOT
1533 wAppIconPaint(wapp->app_icon);
1534 #endif
1539 void
1540 wShowAllWindows(WScreen *scr)
1542 WWindow *wwin, *old_foc;
1543 WApplication *wapp;
1545 old_foc = wwin = scr->focused_window;
1546 while (wwin) {
1547 if (!wwin->flags.internal_window &&
1548 (scr->current_workspace == wwin->frame->workspace
1549 || IS_OMNIPRESENT(wwin))) {
1550 if (wwin->flags.miniaturized) {
1551 wwin->flags.skip_next_animation = 1;
1552 wDeiconifyWindow(wwin);
1553 } else if (wwin->flags.hidden) {
1554 wapp = wApplicationOf(wwin->main_window);
1555 if (wapp) {
1556 wUnhideApplication(wapp, False, False);
1557 } else {
1558 wwin->flags.skip_next_animation = 1;
1559 wDeiconifyWindow(wwin);
1563 wwin = wwin->prev;
1565 wSetFocusTo(scr, old_foc);
1566 /*wRaiseFrame(old_foc->frame->core);*/
1570 void
1571 wRefreshDesktop(WScreen *scr)
1573 Window win;
1574 XSetWindowAttributes attr;
1576 attr.backing_store = NotUseful;
1577 attr.save_under = False;
1578 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1579 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1580 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1581 &attr);
1582 XMapRaised(dpy, win);
1583 XDestroyWindow(dpy, win);
1584 XFlush(dpy);
1588 void
1589 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1591 WWindow *wwin;
1592 WAppIcon *aicon;
1594 int head;
1595 const int heads = wXineramaHeads(scr);
1597 struct HeadVars {
1598 int pf; /* primary axis */
1599 int sf; /* secondary axis */
1600 int fullW;
1601 int fullH;
1602 int pi, si;
1603 int sx1, sx2, sy1, sy2; /* screen boundary */
1604 int sw, sh;
1605 int xo, yo;
1606 int xs, ys;
1607 } *vars;
1609 int isize = wPreferences.icon_size;
1611 vars = (struct HeadVars*)wmalloc(sizeof(struct HeadVars)*heads);
1613 for (head = 0; head < heads; ++head) {
1614 #if 0
1615 WMRect rect = wGetRectForHead(scr, head);
1616 #else
1617 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1618 WMRect rect = wmkrect(area.x1, area.y1, area.x2-area.x1, area.y2-area.y1);
1619 #endif
1621 vars[head].pi = vars[head].si = 0;
1622 vars[head].sx1 = rect.pos.x;
1623 vars[head].sy1 = rect.pos.y;
1624 vars[head].sw = rect.size.width;
1625 vars[head].sh = rect.size.height;
1626 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1627 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1629 #if 0
1630 if (scr->dock) {
1631 if (scr->dock->on_right_side)
1632 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1633 else
1634 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1636 #endif
1638 vars[head].sw = isize * (vars[head].sw/isize);
1639 vars[head].sh = isize * (vars[head].sh/isize);
1640 vars[head].fullW = (vars[head].sx2-vars[head].sx1)/isize;
1641 vars[head].fullH = (vars[head].sy2-vars[head].sy1)/isize;
1643 /* icon yard boundaries */
1644 if (wPreferences.icon_yard & IY_VERT) {
1645 vars[head].pf = vars[head].fullH;
1646 vars[head].sf = vars[head].fullW;
1647 } else {
1648 vars[head].pf = vars[head].fullW;
1649 vars[head].sf = vars[head].fullH;
1651 if (wPreferences.icon_yard & IY_RIGHT) {
1652 vars[head].xo = vars[head].sx2 - isize;
1653 vars[head].xs = -1;
1654 } else {
1655 vars[head].xo = vars[head].sx1;
1656 vars[head].xs = 1;
1658 if (wPreferences.icon_yard & IY_TOP) {
1659 vars[head].yo = vars[head].sy1;
1660 vars[head].ys = 1;
1661 } else {
1662 vars[head].yo = vars[head].sy2 - isize;
1663 vars[head].ys = -1;
1667 #define X ((wPreferences.icon_yard & IY_VERT) \
1668 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1669 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1671 #define Y ((wPreferences.icon_yard & IY_VERT) \
1672 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1673 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1676 /* arrange application icons */
1677 aicon = scr->app_icon_list;
1678 /* reverse them to avoid unnecessarily sliding of icons */
1679 while (aicon && aicon->next)
1680 aicon = aicon->next;
1682 while (aicon) {
1683 if (!aicon->docked) {
1684 /* CHECK: can icon be NULL here ? */
1685 /* The intention here is to place the AppIcon on the head that
1686 * contains most of the applications _main_ window. */
1687 head = wGetHeadForWindow(aicon->icon->owner);
1689 if (aicon->x_pos != X || aicon->y_pos != Y) {
1690 #ifdef ANIMATIONS
1691 if (!wPreferences.no_animations) {
1692 SlideWindow(aicon->icon->core->window,
1693 aicon->x_pos, aicon->y_pos, X, Y);
1695 #endif /* ANIMATIONS */
1697 wAppIconMove(aicon, X, Y);
1698 vars[head].pi++;
1699 if (vars[head].pi >= vars[head].pf) {
1700 vars[head].pi = 0;
1701 vars[head].si++;
1704 aicon = aicon->prev;
1707 /* arrange miniwindows */
1708 wwin = scr->focused_window;
1709 /* reverse them to avoid unnecessarily shuffling */
1710 while (wwin && wwin->prev)
1711 wwin = wwin->prev;
1713 while (wwin) {
1714 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1715 (wwin->frame->workspace==scr->current_workspace ||
1716 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1718 head = wGetHeadForWindow(wwin);
1720 if (arrangeAll || !wwin->flags.icon_moved) {
1721 if (wwin->icon_x != X || wwin->icon_y != Y) {
1722 #ifdef ANIMATIONS
1723 if (wPreferences.no_animations) {
1724 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1725 } else {
1726 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1727 wwin->icon_y, X, Y);
1729 #else
1730 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1731 #endif /* ANIMATIONS */
1733 wwin->icon_x = X;
1734 wwin->icon_y = Y;
1736 vars[head].pi++;
1737 if (vars[head].pi >= vars[head].pf) {
1738 vars[head].pi = 0;
1739 vars[head].si++;
1743 if (arrangeAll) {
1744 wwin->flags.icon_moved = 0;
1746 /* we reversed the order, so we use next */
1747 wwin = wwin->next;
1750 wfree(vars);
1753 #if 0
1754 void
1755 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1757 WWindow *wwin;
1758 WAppIcon *aicon;
1759 int pf; /* primary axis */
1760 int sf; /* secondary axis */
1761 int fullW;
1762 int fullH;
1763 int pi, si;
1764 int sx1, sx2, sy1, sy2; /* screen boundary */
1765 int sw, sh;
1766 int xo, yo;
1767 int xs, ys;
1768 int isize = wPreferences.icon_size;
1771 * Find out screen boundaries.
1775 * Allows each head to have miniwindows
1777 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1779 sx1 = rect.pos.x;
1780 sy1 = rect.pos.y;
1781 sw = rect.size.width;
1782 sh = rect.size.height;
1783 sx2 = sx1 + sw;
1784 sy2 = sy1 + sh;
1785 if (scr->dock) {
1786 if (scr->dock->on_right_side)
1787 sx2 -= isize + DOCK_EXTRA_SPACE;
1788 else
1789 sx1 += isize + DOCK_EXTRA_SPACE;
1792 #if 0
1793 sw = isize * (scr->scr_width/isize);
1794 sh = isize * (scr->scr_height/isize);
1795 #else
1796 sw = isize * (sw/isize);
1797 sh = isize * (sh/isize);
1798 #endif
1799 fullW = (sx2-sx1)/isize;
1800 fullH = (sy2-sy1)/isize;
1802 /* icon yard boundaries */
1803 if (wPreferences.icon_yard & IY_VERT) {
1804 pf = fullH;
1805 sf = fullW;
1806 } else {
1807 pf = fullW;
1808 sf = fullH;
1810 if (wPreferences.icon_yard & IY_RIGHT) {
1811 xo = sx2 - isize;
1812 xs = -1;
1813 } else {
1814 xo = sx1;
1815 xs = 1;
1817 if (wPreferences.icon_yard & IY_TOP) {
1818 yo = sy1;
1819 ys = 1;
1820 } else {
1821 yo = sy2 - isize;
1822 ys = -1;
1825 /* arrange icons putting the most recently focused window
1826 * as the last icon */
1827 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1828 : xo + xs*(pi*isize))
1829 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1830 : yo + ys*(si*isize))
1832 /* arrange application icons */
1833 aicon = scr->app_icon_list;
1834 /* reverse them to avoid unnecessarily sliding of icons */
1835 while (aicon && aicon->next)
1836 aicon = aicon->next;
1838 pi = 0;
1839 si = 0;
1840 while (aicon) {
1841 if (!aicon->docked) {
1842 if (aicon->x_pos != X || aicon->y_pos != Y) {
1843 #ifdef ANIMATIONS
1844 if (!wPreferences.no_animations) {
1845 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1846 X, Y);
1848 #endif /* ANIMATIONS */
1850 wAppIconMove(aicon, X, Y);
1851 pi++;
1853 /* we reversed the order so we use prev */
1854 aicon = aicon->prev;
1855 if (pi >= pf) {
1856 pi=0;
1857 si++;
1861 /* arrange miniwindows */
1863 wwin = scr->focused_window;
1864 /* reverse them to avoid unnecessarily shuffling */
1865 while (wwin && wwin->prev)
1866 wwin = wwin->prev;
1868 while (wwin) {
1869 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1870 (wwin->frame->workspace==scr->current_workspace ||
1871 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1873 if (arrangeAll || !wwin->flags.icon_moved) {
1874 if (wwin->icon_x != X || wwin->icon_y != Y) {
1875 #ifdef ANIMATIONS
1876 if (wPreferences.no_animations) {
1877 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1878 } else {
1879 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1880 wwin->icon_y, X, Y);
1882 #else
1883 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1884 #endif /* ANIMATIONS */
1886 wwin->icon_x = X;
1887 wwin->icon_y = Y;
1888 pi++;
1891 if (arrangeAll) {
1892 wwin->flags.icon_moved = 0;
1894 /* we reversed the order, so we use next */
1895 wwin = wwin->next;
1896 if (pi >= pf) {
1897 pi=0;
1898 si++;
1902 #endif
1904 void
1905 wSelectWindow(WWindow *wwin, Bool flag)
1907 WScreen *scr = wwin->screen_ptr;
1909 if (flag) {
1910 wwin->flags.selected = 1;
1911 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1913 if (!HAS_BORDER(wwin)) {
1914 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1915 FRAME_BORDER_WIDTH);
1918 if (!scr->selected_windows)
1919 scr->selected_windows = WMCreateArray(4);
1920 WMAddToArray(scr->selected_windows, wwin);
1921 } else {
1922 wwin->flags.selected = 0;
1923 XSetWindowBorder(dpy, wwin->frame->core->window,
1924 scr->frame_border_pixel);
1926 if (!HAS_BORDER(wwin)) {
1927 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1930 if (scr->selected_windows) {
1931 WMRemoveFromArray(scr->selected_windows, wwin);
1937 void
1938 wMakeWindowVisible(WWindow *wwin)
1940 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1941 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1943 if (wwin->flags.shaded) {
1944 wUnshadeWindow(wwin);
1946 if (wwin->flags.hidden) {
1947 WApplication *app;
1949 app = wApplicationOf(wwin->main_window);
1950 if (app) {
1951 /* trick to get focus to this window */
1952 app->last_focused = wwin;
1953 wUnhideApplication(app, False, False);
1956 if (wwin->flags.miniaturized) {
1957 wDeiconifyWindow(wwin);
1958 } else {
1959 if (!WFLAGP(wwin, no_focusable))
1960 wSetFocusTo(wwin->screen_ptr, wwin);
1961 wRaiseFrame(wwin->frame->core);