- Removed support for legacy systems: OpenLook, KDE-2.x, Gnome-1.x
[wmaker-crm.git] / src / actions.c
blobe3d573b65f3e8ce0197c5e3118da470f81486fd2
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);
551 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
552 wFrameWindowPaint(wwin->frame);
554 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
558 #ifdef ANIMATIONS
559 static void
560 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
561 int fx, int fy, int fw, int fh, int steps)
563 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
564 float cx, cy, cw, ch;
565 float xstep, ystep, wstep, hstep;
566 XPoint points[5];
567 float dx, dch, midy;
568 float angle, final_angle, delta;
570 xstep = (float)(fx-x)/steps;
571 ystep = (float)(fy-y)/steps;
572 wstep = (float)(fw-w)/steps;
573 hstep = (float)(fh-h)/steps;
575 cx = (float)x;
576 cy = (float)y;
577 cw = (float)w;
578 ch = (float)h;
580 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
581 delta = (float)(final_angle/FRAMES);
582 for (angle=0;; angle+=delta) {
583 if (angle > final_angle)
584 angle = final_angle;
586 dx = (cw/10) - ((cw/5) * sin(angle));
587 dch = (ch/2) * cos(angle);
588 midy = cy + (ch/2);
590 points[0].x = cx + dx; points[0].y = midy - dch;
591 points[1].x = cx + cw - dx; points[1].y = points[0].y;
592 points[2].x = cx + cw + dx; points[2].y = midy + dch;
593 points[3].x = cx - dx; points[3].y = points[2].y;
594 points[4].x = points[0].x; points[4].y = points[0].y;
596 XGrabServer(dpy);
597 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
598 XFlush(dpy);
599 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
600 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
601 #else
602 wusleep(10);
603 #endif
605 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
606 XUngrabServer(dpy);
607 cx+=xstep;
608 cy+=ystep;
609 cw+=wstep;
610 ch+=hstep;
611 if (angle >= final_angle)
612 break;
615 XFlush(dpy);
617 #undef FRAMES
620 static void
621 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
622 int fx, int fy, int fw, int fh, int steps)
624 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
625 float cx, cy, cw, ch;
626 float xstep, ystep, wstep, hstep;
627 XPoint points[5];
628 float angle, final_angle, a, d, delta;
630 x += w/2;
631 y += h/2;
632 fx += fw/2;
633 fy += fh/2;
635 xstep = (float)(fx-x)/steps;
636 ystep = (float)(fy-y)/steps;
637 wstep = (float)(fw-w)/steps;
638 hstep = (float)(fh-h)/steps;
640 cx = (float)x;
641 cy = (float)y;
642 cw = (float)w;
643 ch = (float)h;
645 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
646 delta = (float)(final_angle/FRAMES);
647 for (angle=0;; angle+=delta) {
648 if (angle > final_angle)
649 angle = final_angle;
651 a = atan(ch/cw);
652 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
654 points[0].x = cx+cos(angle-a)*d;
655 points[0].y = cy+sin(angle-a)*d;
656 points[1].x = cx+cos(angle+a)*d;
657 points[1].y = cy+sin(angle+a)*d;
658 points[2].x = cx+cos(angle-a+WM_PI)*d;
659 points[2].y = cy+sin(angle-a+WM_PI)*d;
660 points[3].x = cx+cos(angle+a+WM_PI)*d;
661 points[3].y = cy+sin(angle+a+WM_PI)*d;
662 points[4].x = cx+cos(angle-a)*d;
663 points[4].y = cy+sin(angle-a)*d;
664 XGrabServer(dpy);
665 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
666 XFlush(dpy);
667 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
668 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
669 #else
670 wusleep(10);
671 #endif
673 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
674 XUngrabServer(dpy);
675 cx+=xstep;
676 cy+=ystep;
677 cw+=wstep;
678 ch+=hstep;
679 if (angle >= final_angle)
680 break;
683 XFlush(dpy);
685 #undef FRAMES
688 static void
689 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
690 int fx, int fy, int fw, int fh, int steps)
692 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
693 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
694 float xstep, ystep, wstep, hstep;
695 int i, j;
697 xstep = (float)(fx-x)/steps;
698 ystep = (float)(fy-y)/steps;
699 wstep = (float)(fw-w)/steps;
700 hstep = (float)(fh-h)/steps;
702 for (j=0; j<FRAMES; j++) {
703 cx[j] = (float)x;
704 cy[j] = (float)y;
705 cw[j] = (float)w;
706 ch[j] = (float)h;
708 XGrabServer(dpy);
709 for (i=0; i<steps; i++) {
710 for (j=0; j<FRAMES; j++) {
711 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
712 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
714 XFlush(dpy);
715 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
716 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
717 #else
718 wusleep(10);
719 #endif
720 for (j=0; j<FRAMES; j++) {
721 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
722 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
723 if (j<FRAMES-1) {
724 cx[j]=cx[j+1];
725 cy[j]=cy[j+1];
726 cw[j]=cw[j+1];
727 ch[j]=ch[j+1];
728 } else {
729 cx[j]+=xstep;
730 cy[j]+=ystep;
731 cw[j]+=wstep;
732 ch[j]+=hstep;
737 for (j=0; j<FRAMES; j++) {
738 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
739 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
741 XFlush(dpy);
742 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
743 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
744 #else
745 wusleep(10);
746 #endif
747 for (j=0; j<FRAMES; j++) {
748 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
749 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
752 XUngrabServer(dpy);
754 #undef FRAMES
757 void
758 animateResize(WScreen *scr, int x, int y, int w, int h,
759 int fx, int fy, int fw, int fh, int hiding)
761 int style = wPreferences.iconification_style; /* Catch the value */
762 int steps, k;
764 if (style == WIS_NONE)
765 return;
767 if (style == WIS_RANDOM) {
768 style = rand()%3;
771 k = (hiding ? 2 : 3);
772 switch(style) {
773 case WIS_TWIST:
774 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
775 if (steps>0)
776 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
777 break;
778 case WIS_FLIP:
779 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
780 if (steps>0)
781 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
782 break;
783 case WIS_ZOOM:
784 default:
785 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
786 if (steps>0)
787 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
788 break;
791 #endif /* ANIMATIONS */
794 static void
795 flushExpose()
797 XEvent tmpev;
799 while (XCheckTypedEvent(dpy, Expose, &tmpev))
800 WMHandleEvent(&tmpev);
801 XSync(dpy, 0);
804 static void
805 unmapTransientsFor(WWindow *wwin)
807 WWindow *tmp;
810 tmp = wwin->screen_ptr->focused_window;
811 while (tmp) {
812 /* unmap the transients for this transient */
813 if (tmp!=wwin && tmp->transient_for == wwin->client_win
814 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
815 || tmp->flags.shaded)) {
816 unmapTransientsFor(tmp);
817 tmp->flags.miniaturized = 1;
818 if (!tmp->flags.shaded) {
819 wWindowUnmap(tmp);
820 } else {
821 XUnmapWindow(dpy, tmp->frame->core->window);
824 if (!tmp->flags.shaded)
826 wClientSetState(tmp, IconicState, None);
828 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
830 tmp = tmp->prev;
835 static void
836 mapTransientsFor(WWindow *wwin)
838 WWindow *tmp;
840 tmp = wwin->screen_ptr->focused_window;
841 while (tmp) {
842 /* recursively map the transients for this transient */
843 if (tmp!=wwin && tmp->transient_for == wwin->client_win
844 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
845 && tmp->icon==NULL) {
846 mapTransientsFor(tmp);
847 tmp->flags.miniaturized = 0;
848 if (!tmp->flags.shaded) {
849 wWindowMap(tmp);
850 } else {
851 XMapWindow(dpy, tmp->frame->core->window);
853 tmp->flags.semi_focused = 0;
855 if (!tmp->flags.shaded)
857 wClientSetState(tmp, NormalState, None);
859 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
861 tmp = tmp->prev;
865 #if 0
866 static void
867 setupIconGrabs(WIcon *icon)
869 /* setup passive grabs on the icon */
870 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
871 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
872 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
873 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
874 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
875 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
876 XSync(dpy, 0);
878 #endif
880 static WWindow*
881 recursiveTransientFor(WWindow *wwin)
883 int i;
885 if (!wwin)
886 return None;
888 /* hackish way to detect transient_for cycle */
889 i = wwin->screen_ptr->window_count+1;
891 while (wwin && wwin->transient_for != None && i>0) {
892 wwin = wWindowFor(wwin->transient_for);
893 i--;
895 if (i==0 && wwin) {
896 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
897 wwin->frame->title);
898 return NULL;
901 return wwin;
904 #if 0
905 static void
906 removeIconGrabs(WIcon *icon)
908 /* remove passive grabs on the icon */
909 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
910 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
911 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
912 XSync(dpy, 0);
914 #endif
917 void
918 wIconifyWindow(WWindow *wwin)
920 XWindowAttributes attribs;
921 int present;
924 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
925 /* the window doesn't exist anymore */
926 return;
929 if (wwin->flags.miniaturized) {
930 return;
933 if (wwin->transient_for!=None &&
934 wwin->transient_for!=wwin->screen_ptr->root_win) {
935 WWindow *owner = wWindowFor(wwin->transient_for);
937 if (owner && owner->flags.miniaturized)
938 return;
941 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
943 /* if the window is in another workspace, simplify process */
944 if (present) {
945 /* icon creation may take a while */
946 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
947 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
948 GrabModeAsync, None, None, CurrentTime);
951 if (!wPreferences.disable_miniwindows
952 #ifdef NETWM_HINTS
953 && !wwin->flags.net_handle_icon
954 #endif
956 if (!wwin->flags.icon_moved) {
957 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
959 wwin->icon = wIconCreate(wwin);
961 wwin->icon->mapped = 1;
964 wwin->flags.miniaturized = 1;
965 wwin->flags.mapped = 0;
967 /* unmap transients */
969 unmapTransientsFor(wwin);
971 if (present) {
972 wSoundPlay(WSOUND_ICONIFY);
974 XUngrabPointer(dpy, CurrentTime);
975 wWindowUnmap(wwin);
976 /* let all Expose events arrive so that we can repaint
977 * something before the animation starts (and the server is grabbed) */
978 XSync(dpy, 0);
980 if (wPreferences.disable_miniwindows
981 #ifdef NETWM_HINTS
982 || wwin->flags.net_handle_icon
983 #endif
985 wClientSetState(wwin, IconicState, None);
986 else
987 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
989 flushExpose();
990 #ifdef ANIMATIONS
991 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
992 && !wPreferences.no_animations) {
993 int ix, iy, iw, ih;
995 if (!wPreferences.disable_miniwindows
996 #ifdef NETWM_HINTS
997 && !wwin->flags.net_handle_icon
998 #endif
1000 ix = wwin->icon_x;
1001 iy = wwin->icon_y;
1002 iw = wwin->icon->core->width;
1003 ih = wwin->icon->core->height;
1004 } else {
1005 #ifdef NETWM_HINTS
1006 if (wwin->flags.net_handle_icon) {
1007 ix = wwin->icon_x;
1008 iy = wwin->icon_y;
1009 iw = wwin->icon_w;
1010 ih = wwin->icon_h;
1011 } else
1012 #endif
1014 ix = 0;
1015 iy = 0;
1016 iw = wwin->screen_ptr->scr_width;
1017 ih = wwin->screen_ptr->scr_height;
1020 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1021 wwin->frame->core->width, wwin->frame->core->height,
1022 ix, iy, iw, ih, False);
1024 #endif
1027 wwin->flags.skip_next_animation = 0;
1029 if (!wPreferences.disable_miniwindows
1030 #ifdef NETWM_HINTS
1031 && !wwin->flags.net_handle_icon
1032 #endif
1035 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
1036 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1038 XMapWindow(dpy, wwin->icon->core->window);
1040 AddToStackList(wwin->icon->core);
1042 wLowerFrame(wwin->icon->core);
1045 if (present) {
1046 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1049 * It doesn't seem to be working and causes button event hangup
1050 * when deiconifying a transient window.
1051 setupIconGrabs(wwin->icon);
1053 if ((wwin->flags.focused
1054 || (owner && wwin->client_win == owner->client_win))
1055 && wPreferences.focus_mode==WKF_CLICK) {
1056 WWindow *tmp;
1058 tmp = wwin->prev;
1059 while (tmp) {
1060 if (!WFLAGP(tmp, no_focusable)
1061 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1062 && (wwin->frame->workspace == tmp->frame->workspace))
1063 break;
1064 tmp = tmp->prev;
1066 wSetFocusTo(wwin->screen_ptr, tmp);
1067 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1068 wSetFocusTo(wwin->screen_ptr, NULL);
1071 #ifdef ANIMATIONS
1072 if (!wwin->screen_ptr->flags.startup) {
1073 /* Catch up with events not processed while animation was running */
1074 Window clientwin = wwin->client_win;
1076 ProcessPendingEvents();
1078 /* the window can disappear while ProcessPendingEvents() runs */
1079 if (!wWindowFor(clientwin)) {
1080 return;
1083 #endif
1086 /* maybe we want to do this regardless of net_handle_icon
1087 * it seems to me we might break behaviour this way.
1089 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1090 #ifdef NETWM_HINTS
1091 && !wwin->flags.net_handle_icon
1092 #endif
1094 wIconSelect(wwin->icon);
1096 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1102 void
1103 wDeiconifyWindow(WWindow *wwin)
1105 #ifdef NETWM_HINTS
1106 /* we're hiding for show_desktop */
1107 int netwm_hidden = wwin->flags.net_show_desktop &&
1108 wwin->frame->workspace!=wwin->screen_ptr->current_workspace;
1109 #else
1110 int netwm_hidden = False;
1111 #endif
1113 if (!netwm_hidden)
1114 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1116 if (!wwin->flags.miniaturized)
1117 return;
1119 if (wwin->transient_for != None
1120 && wwin->transient_for != wwin->screen_ptr->root_win) {
1121 WWindow *owner = recursiveTransientFor(wwin);
1123 if (owner && owner->flags.miniaturized) {
1124 wDeiconifyWindow(owner);
1125 wSetFocusTo(wwin->screen_ptr, wwin);
1126 wRaiseFrame(wwin->frame->core);
1127 return;
1131 wwin->flags.miniaturized = 0;
1133 if (!netwm_hidden && !wwin->flags.shaded) {
1134 wwin->flags.mapped = 1;
1137 if (!netwm_hidden || wPreferences.sticky_icons) {
1138 /* maybe we want to do this regardless of net_handle_icon
1139 * it seems to me we might break behaviour this way.
1141 if (!wPreferences.disable_miniwindows
1142 #ifdef NETWM_HINTS
1143 && !wwin->flags.net_handle_icon
1144 #endif
1145 && wwin->icon != NULL) {
1146 if (wwin->icon->selected)
1147 wIconSelect(wwin->icon);
1149 XUnmapWindow(dpy, wwin->icon->core->window);
1153 if (!netwm_hidden)
1154 wSoundPlay(WSOUND_DEICONIFY);
1156 /* if the window is in another workspace, do it silently */
1157 if (!netwm_hidden) {
1158 #ifdef ANIMATIONS
1159 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1160 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1161 int ix, iy, iw, ih;
1163 if (!wPreferences.disable_miniwindows
1164 #ifdef NETWM_HINTS
1165 && !wwin->flags.net_handle_icon
1166 #endif
1168 ix = wwin->icon_x;
1169 iy = wwin->icon_y;
1170 iw = wwin->icon->core->width;
1171 ih = wwin->icon->core->height;
1172 } else {
1173 #ifdef NETWM_HINTS
1174 if (wwin->flags.net_handle_icon) {
1175 ix = wwin->icon_x;
1176 iy = wwin->icon_y;
1177 iw = wwin->icon_w;
1178 ih = wwin->icon_h;
1179 } else
1180 #endif
1182 ix = 0;
1183 iy = 0;
1184 iw = wwin->screen_ptr->scr_width;
1185 ih = wwin->screen_ptr->scr_height;
1188 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1189 wwin->frame_x, wwin->frame_y,
1190 wwin->frame->core->width, wwin->frame->core->height,
1191 False);
1193 #endif /* ANIMATIONS */
1194 wwin->flags.skip_next_animation = 0;
1195 XGrabServer(dpy);
1196 if (!wwin->flags.shaded) {
1197 XMapWindow(dpy, wwin->client_win);
1199 XMapWindow(dpy, wwin->frame->core->window);
1200 wRaiseFrame(wwin->frame->core);
1201 if (!wwin->flags.shaded) {
1202 wClientSetState(wwin, NormalState, None);
1204 mapTransientsFor(wwin);
1207 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1208 #ifdef NETWM_HINTS
1209 && !wwin->flags.net_handle_icon
1210 #endif
1212 RemoveFromStackList(wwin->icon->core);
1213 /* removeIconGrabs(wwin->icon);*/
1214 wIconDestroy(wwin->icon);
1215 wwin->icon = NULL;
1218 if (!netwm_hidden) {
1219 XUngrabServer(dpy);
1221 wSetFocusTo(wwin->screen_ptr, wwin);
1223 #ifdef ANIMATIONS
1224 if (!wwin->screen_ptr->flags.startup) {
1225 /* Catch up with events not processed while animation was running */
1226 Window clientwin = wwin->client_win;
1228 ProcessPendingEvents();
1230 /* the window can disappear while ProcessPendingEvents() runs */
1231 if (!wWindowFor(clientwin)) {
1232 return;
1235 #endif
1238 if (wPreferences.auto_arrange_icons) {
1239 wArrangeIcons(wwin->screen_ptr, True);
1242 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1244 /* In case we were shaded and iconified, also unshade */
1245 if (!netwm_hidden)
1246 wUnshadeWindow(wwin);
1251 static void
1252 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1254 if (wwin->flags.miniaturized) {
1255 if (wwin->icon) {
1256 XUnmapWindow(dpy, wwin->icon->core->window);
1257 wwin->icon->mapped = 0;
1259 wwin->flags.hidden = 1;
1261 WMPostNotificationName(WMNChangedState, wwin, "hide");
1262 return;
1265 if (wwin->flags.inspector_open) {
1266 wHideInspectorForWindow(wwin);
1269 wwin->flags.hidden = 1;
1270 wWindowUnmap(wwin);
1272 wClientSetState(wwin, IconicState, icon->icon_win);
1273 flushExpose();
1274 wSoundPlay(WSOUND_HIDE);
1275 #ifdef ANIMATIONS
1276 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1277 !wwin->flags.skip_next_animation && animate) {
1278 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1279 wwin->frame->core->width, wwin->frame->core->height,
1280 icon_x, icon_y, icon->core->width, icon->core->height,
1281 True);
1283 #endif
1284 wwin->flags.skip_next_animation = 0;
1286 WMPostNotificationName(WMNChangedState, wwin, "hide");
1291 void
1292 wHideOtherApplications(WWindow *awin)
1294 WWindow *wwin;
1295 WApplication *tapp;
1297 if (!awin)
1298 return;
1299 wwin = awin->screen_ptr->focused_window;
1302 while (wwin) {
1303 if (wwin!=awin
1304 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1305 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1306 && !wwin->flags.internal_window
1307 && wGetWindowOfInspectorForWindow(wwin) != awin
1308 && !WFLAGP(wwin, no_hide_others)) {
1310 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1311 if (!WFLAGP(wwin, no_miniaturizable)) {
1312 wwin->flags.skip_next_animation = 1;
1313 wIconifyWindow(wwin);
1315 } else if (wwin->main_window!=None
1316 && awin->main_window != wwin->main_window) {
1317 tapp = wApplicationOf(wwin->main_window);
1318 if (tapp) {
1319 tapp->flags.skip_next_animation = 1;
1320 wHideApplication(tapp);
1321 } else {
1322 if (!WFLAGP(wwin, no_miniaturizable)) {
1323 wwin->flags.skip_next_animation = 1;
1324 wIconifyWindow(wwin);
1329 wwin = wwin->prev;
1332 wSetFocusTo(awin->screen_ptr, awin);
1338 void
1339 wHideApplication(WApplication *wapp)
1341 WScreen *scr;
1342 WWindow *wlist;
1343 int hadfocus;
1345 if (!wapp) {
1346 wwarning("trying to hide a non grouped window");
1347 return;
1349 if (!wapp->main_window_desc) {
1350 wwarning("group leader not found for window group");
1351 return;
1353 scr = wapp->main_window_desc->screen_ptr;
1354 hadfocus = 0;
1355 wlist = scr->focused_window;
1356 if (!wlist)
1357 return;
1359 if (wlist->main_window == wapp->main_window)
1360 wapp->last_focused = wlist;
1361 else
1362 wapp->last_focused = NULL;
1363 while (wlist) {
1364 if (wlist->main_window == wapp->main_window) {
1365 if (wlist->flags.focused) {
1366 hadfocus = 1;
1368 if (wapp->app_icon)
1369 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1370 wapp->app_icon->y_pos, wlist,
1371 !wapp->flags.skip_next_animation);
1373 wlist = wlist->prev;
1376 wapp->flags.skip_next_animation = 0;
1378 if (hadfocus) {
1379 if (wPreferences.focus_mode==WKF_CLICK) {
1380 wlist = scr->focused_window;
1381 while (wlist) {
1382 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1383 && (wlist->flags.mapped || wlist->flags.shaded))
1384 break;
1385 wlist = wlist->prev;
1387 wSetFocusTo(scr, wlist);
1388 } else {
1389 wSetFocusTo(scr, NULL);
1393 wapp->flags.hidden = 1;
1395 if(wPreferences.auto_arrange_icons) {
1396 wArrangeIcons(scr, True);
1398 #ifdef HIDDENDOT
1399 if (wapp->app_icon)
1400 wAppIconPaint(wapp->app_icon);
1401 #endif
1407 static void
1408 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1409 int bringToCurrentWS)
1411 if (bringToCurrentWS)
1412 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1414 wwin->flags.hidden=0;
1416 wSoundPlay(WSOUND_UNHIDE);
1417 #ifdef ANIMATIONS
1418 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1419 && animate) {
1420 animateResize(wwin->screen_ptr, icon_x, icon_y,
1421 icon->core->width, icon->core->height,
1422 wwin->frame_x, wwin->frame_y,
1423 wwin->frame->core->width, wwin->frame->core->height,
1424 True);
1426 #endif
1427 wwin->flags.skip_next_animation = 0;
1428 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1429 XMapWindow(dpy, wwin->client_win);
1430 XMapWindow(dpy, wwin->frame->core->window);
1431 wClientSetState(wwin, NormalState, None);
1432 wwin->flags.mapped=1;
1433 wRaiseFrame(wwin->frame->core);
1435 if (wwin->flags.inspector_open) {
1436 wUnhideInspectorForWindow(wwin);
1439 WMPostNotificationName(WMNChangedState, wwin, "hide");
1443 void
1444 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1446 WScreen *scr;
1447 WWindow *wlist, *next;
1448 WWindow *focused=NULL;
1449 Bool shouldArrangeIcons = False;
1451 if (!wapp)
1452 return;
1454 scr = wapp->main_window_desc->screen_ptr;
1455 wlist = scr->focused_window;
1456 if (!wlist)
1457 return;
1459 /* goto beginning of list */
1460 while (wlist->prev)
1461 wlist = wlist->prev;
1463 while (wlist) {
1464 next = wlist->next;
1466 if (wlist->main_window == wapp->main_window) {
1467 if (wlist->flags.focused)
1468 focused = wlist;
1469 else if (!focused || !focused->flags.focused)
1470 focused = wlist;
1472 if (wlist->flags.miniaturized) {
1473 if (bringToCurrentWS || wPreferences.sticky_icons ||
1474 wlist->frame->workspace == scr->current_workspace) {
1475 if (wlist->icon && !wlist->icon->mapped) {
1476 XMapWindow(dpy, wlist->icon->core->window);
1477 wlist->icon->mapped = 1;
1480 if (bringToCurrentWS)
1481 wWindowChangeWorkspace(wlist, scr->current_workspace);
1482 wlist->flags.hidden = 0;
1483 if (miniwindows &&
1484 wlist->frame->workspace == scr->current_workspace) {
1485 wDeiconifyWindow(wlist);
1487 shouldArrangeIcons = True;
1488 WMPostNotificationName(WMNChangedState, wlist, "hide");
1489 } else if (wlist->flags.shaded) {
1490 if (bringToCurrentWS)
1491 wWindowChangeWorkspace(wlist, scr->current_workspace);
1492 wlist->flags.hidden = 0;
1493 if (wlist->frame->workspace == scr->current_workspace) {
1494 XMapWindow(dpy, wlist->frame->core->window);
1495 if (miniwindows) {
1496 wUnshadeWindow(wlist);
1497 wRaiseFrame(wlist->frame->core);
1500 WMPostNotificationName(WMNChangedState, wlist, "hide");
1501 } else if (wlist->flags.hidden) {
1502 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1503 wapp->app_icon->y_pos, wlist,
1504 !wapp->flags.skip_next_animation,
1505 bringToCurrentWS);
1506 } else {
1507 if (bringToCurrentWS
1508 && wlist->frame->workspace != scr->current_workspace) {
1509 wWindowChangeWorkspace(wlist, scr->current_workspace);
1511 wRaiseFrame(wlist->frame->core);
1514 wlist = next;
1517 wapp->flags.skip_next_animation = 0;
1518 wapp->flags.hidden = 0;
1520 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1521 wRaiseFrame(wapp->last_focused->frame->core);
1522 wSetFocusTo(scr, wapp->last_focused);
1523 } else if (focused) {
1524 wSetFocusTo(scr, focused);
1526 wapp->last_focused = NULL;
1527 if (shouldArrangeIcons || wPreferences.auto_arrange_icons) {
1528 wArrangeIcons(scr, True);
1530 #ifdef HIDDENDOT
1531 wAppIconPaint(wapp->app_icon);
1532 #endif
1537 void
1538 wShowAllWindows(WScreen *scr)
1540 WWindow *wwin, *old_foc;
1541 WApplication *wapp;
1543 old_foc = wwin = scr->focused_window;
1544 while (wwin) {
1545 if (!wwin->flags.internal_window &&
1546 (scr->current_workspace == wwin->frame->workspace
1547 || IS_OMNIPRESENT(wwin))) {
1548 if (wwin->flags.miniaturized) {
1549 wwin->flags.skip_next_animation = 1;
1550 wDeiconifyWindow(wwin);
1551 } else if (wwin->flags.hidden) {
1552 wapp = wApplicationOf(wwin->main_window);
1553 if (wapp) {
1554 wUnhideApplication(wapp, False, False);
1555 } else {
1556 wwin->flags.skip_next_animation = 1;
1557 wDeiconifyWindow(wwin);
1561 wwin = wwin->prev;
1563 wSetFocusTo(scr, old_foc);
1564 /*wRaiseFrame(old_foc->frame->core);*/
1568 void
1569 wRefreshDesktop(WScreen *scr)
1571 Window win;
1572 XSetWindowAttributes attr;
1574 attr.backing_store = NotUseful;
1575 attr.save_under = False;
1576 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1577 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1578 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1579 &attr);
1580 XMapRaised(dpy, win);
1581 XDestroyWindow(dpy, win);
1582 XFlush(dpy);
1586 void
1587 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1589 WWindow *wwin;
1590 WAppIcon *aicon;
1592 int head;
1593 const int heads = wXineramaHeads(scr);
1595 struct HeadVars {
1596 int pf; /* primary axis */
1597 int sf; /* secondary axis */
1598 int fullW;
1599 int fullH;
1600 int pi, si;
1601 int sx1, sx2, sy1, sy2; /* screen boundary */
1602 int sw, sh;
1603 int xo, yo;
1604 int xs, ys;
1605 } *vars;
1607 int isize = wPreferences.icon_size;
1609 vars = (struct HeadVars*)wmalloc(sizeof(struct HeadVars)*heads);
1611 for (head = 0; head < heads; ++head) {
1612 #if 0
1613 WMRect rect = wGetRectForHead(scr, head);
1614 #else
1615 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1616 WMRect rect = wmkrect(area.x1, area.y1, area.x2-area.x1, area.y2-area.y1);
1617 #endif
1619 vars[head].pi = vars[head].si = 0;
1620 vars[head].sx1 = rect.pos.x;
1621 vars[head].sy1 = rect.pos.y;
1622 vars[head].sw = rect.size.width;
1623 vars[head].sh = rect.size.height;
1624 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1625 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1627 #if 0
1628 if (scr->dock) {
1629 if (scr->dock->on_right_side)
1630 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1631 else
1632 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1634 #endif
1636 vars[head].sw = isize * (vars[head].sw/isize);
1637 vars[head].sh = isize * (vars[head].sh/isize);
1638 vars[head].fullW = (vars[head].sx2-vars[head].sx1)/isize;
1639 vars[head].fullH = (vars[head].sy2-vars[head].sy1)/isize;
1641 /* icon yard boundaries */
1642 if (wPreferences.icon_yard & IY_VERT) {
1643 vars[head].pf = vars[head].fullH;
1644 vars[head].sf = vars[head].fullW;
1645 } else {
1646 vars[head].pf = vars[head].fullW;
1647 vars[head].sf = vars[head].fullH;
1649 if (wPreferences.icon_yard & IY_RIGHT) {
1650 vars[head].xo = vars[head].sx2 - isize;
1651 vars[head].xs = -1;
1652 } else {
1653 vars[head].xo = vars[head].sx1;
1654 vars[head].xs = 1;
1656 if (wPreferences.icon_yard & IY_TOP) {
1657 vars[head].yo = vars[head].sy1;
1658 vars[head].ys = 1;
1659 } else {
1660 vars[head].yo = vars[head].sy2 - isize;
1661 vars[head].ys = -1;
1665 #define X ((wPreferences.icon_yard & IY_VERT) \
1666 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1667 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1669 #define Y ((wPreferences.icon_yard & IY_VERT) \
1670 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1671 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1674 /* arrange application icons */
1675 aicon = scr->app_icon_list;
1676 /* reverse them to avoid unnecessarily sliding of icons */
1677 while (aicon && aicon->next)
1678 aicon = aicon->next;
1680 while (aicon) {
1681 if (!aicon->docked) {
1682 /* CHECK: can icon be NULL here ? */
1683 /* The intention here is to place the AppIcon on the head that
1684 * contains most of the applications _main_ window. */
1685 head = wGetHeadForWindow(aicon->icon->owner);
1687 if (aicon->x_pos != X || aicon->y_pos != Y) {
1688 #ifdef ANIMATIONS
1689 if (!wPreferences.no_animations) {
1690 SlideWindow(aicon->icon->core->window,
1691 aicon->x_pos, aicon->y_pos, X, Y);
1693 #endif /* ANIMATIONS */
1695 wAppIconMove(aicon, X, Y);
1696 vars[head].pi++;
1697 if (vars[head].pi >= vars[head].pf) {
1698 vars[head].pi = 0;
1699 vars[head].si++;
1702 aicon = aicon->prev;
1705 /* arrange miniwindows */
1706 wwin = scr->focused_window;
1707 /* reverse them to avoid unnecessarily shuffling */
1708 while (wwin && wwin->prev)
1709 wwin = wwin->prev;
1711 while (wwin) {
1712 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1713 (wwin->frame->workspace==scr->current_workspace ||
1714 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1716 head = wGetHeadForWindow(wwin);
1718 if (arrangeAll || !wwin->flags.icon_moved) {
1719 if (wwin->icon_x != X || wwin->icon_y != Y) {
1720 #ifdef ANIMATIONS
1721 if (wPreferences.no_animations) {
1722 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1723 } else {
1724 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1725 wwin->icon_y, X, Y);
1727 #else
1728 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1729 #endif /* ANIMATIONS */
1731 wwin->icon_x = X;
1732 wwin->icon_y = Y;
1734 vars[head].pi++;
1735 if (vars[head].pi >= vars[head].pf) {
1736 vars[head].pi = 0;
1737 vars[head].si++;
1741 if (arrangeAll) {
1742 wwin->flags.icon_moved = 0;
1744 /* we reversed the order, so we use next */
1745 wwin = wwin->next;
1748 wfree(vars);
1751 #if 0
1752 void
1753 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1755 WWindow *wwin;
1756 WAppIcon *aicon;
1757 int pf; /* primary axis */
1758 int sf; /* secondary axis */
1759 int fullW;
1760 int fullH;
1761 int pi, si;
1762 int sx1, sx2, sy1, sy2; /* screen boundary */
1763 int sw, sh;
1764 int xo, yo;
1765 int xs, ys;
1766 int isize = wPreferences.icon_size;
1769 * Find out screen boundaries.
1773 * Allows each head to have miniwindows
1775 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1777 sx1 = rect.pos.x;
1778 sy1 = rect.pos.y;
1779 sw = rect.size.width;
1780 sh = rect.size.height;
1781 sx2 = sx1 + sw;
1782 sy2 = sy1 + sh;
1783 if (scr->dock) {
1784 if (scr->dock->on_right_side)
1785 sx2 -= isize + DOCK_EXTRA_SPACE;
1786 else
1787 sx1 += isize + DOCK_EXTRA_SPACE;
1790 #if 0
1791 sw = isize * (scr->scr_width/isize);
1792 sh = isize * (scr->scr_height/isize);
1793 #else
1794 sw = isize * (sw/isize);
1795 sh = isize * (sh/isize);
1796 #endif
1797 fullW = (sx2-sx1)/isize;
1798 fullH = (sy2-sy1)/isize;
1800 /* icon yard boundaries */
1801 if (wPreferences.icon_yard & IY_VERT) {
1802 pf = fullH;
1803 sf = fullW;
1804 } else {
1805 pf = fullW;
1806 sf = fullH;
1808 if (wPreferences.icon_yard & IY_RIGHT) {
1809 xo = sx2 - isize;
1810 xs = -1;
1811 } else {
1812 xo = sx1;
1813 xs = 1;
1815 if (wPreferences.icon_yard & IY_TOP) {
1816 yo = sy1;
1817 ys = 1;
1818 } else {
1819 yo = sy2 - isize;
1820 ys = -1;
1823 /* arrange icons putting the most recently focused window
1824 * as the last icon */
1825 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1826 : xo + xs*(pi*isize))
1827 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1828 : yo + ys*(si*isize))
1830 /* arrange application icons */
1831 aicon = scr->app_icon_list;
1832 /* reverse them to avoid unnecessarily sliding of icons */
1833 while (aicon && aicon->next)
1834 aicon = aicon->next;
1836 pi = 0;
1837 si = 0;
1838 while (aicon) {
1839 if (!aicon->docked) {
1840 if (aicon->x_pos != X || aicon->y_pos != Y) {
1841 #ifdef ANIMATIONS
1842 if (!wPreferences.no_animations) {
1843 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1844 X, Y);
1846 #endif /* ANIMATIONS */
1848 wAppIconMove(aicon, X, Y);
1849 pi++;
1851 /* we reversed the order so we use prev */
1852 aicon = aicon->prev;
1853 if (pi >= pf) {
1854 pi=0;
1855 si++;
1859 /* arrange miniwindows */
1861 wwin = scr->focused_window;
1862 /* reverse them to avoid unnecessarily shuffling */
1863 while (wwin && wwin->prev)
1864 wwin = wwin->prev;
1866 while (wwin) {
1867 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1868 (wwin->frame->workspace==scr->current_workspace ||
1869 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1871 if (arrangeAll || !wwin->flags.icon_moved) {
1872 if (wwin->icon_x != X || wwin->icon_y != Y) {
1873 #ifdef ANIMATIONS
1874 if (wPreferences.no_animations) {
1875 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1876 } else {
1877 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1878 wwin->icon_y, X, Y);
1880 #else
1881 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1882 #endif /* ANIMATIONS */
1884 wwin->icon_x = X;
1885 wwin->icon_y = Y;
1886 pi++;
1889 if (arrangeAll) {
1890 wwin->flags.icon_moved = 0;
1892 /* we reversed the order, so we use next */
1893 wwin = wwin->next;
1894 if (pi >= pf) {
1895 pi=0;
1896 si++;
1900 #endif
1902 void
1903 wSelectWindow(WWindow *wwin, Bool flag)
1905 WScreen *scr = wwin->screen_ptr;
1907 if (flag) {
1908 wwin->flags.selected = 1;
1909 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1911 if (!HAS_BORDER(wwin)) {
1912 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1913 FRAME_BORDER_WIDTH);
1916 if (!scr->selected_windows)
1917 scr->selected_windows = WMCreateArray(4);
1918 WMAddToArray(scr->selected_windows, wwin);
1919 } else {
1920 wwin->flags.selected = 0;
1921 XSetWindowBorder(dpy, wwin->frame->core->window,
1922 scr->frame_border_pixel);
1924 if (!HAS_BORDER(wwin)) {
1925 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1928 if (scr->selected_windows) {
1929 WMRemoveFromArray(scr->selected_windows, wwin);
1935 void
1936 wMakeWindowVisible(WWindow *wwin)
1938 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1939 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1941 if (wwin->flags.shaded) {
1942 wUnshadeWindow(wwin);
1944 if (wwin->flags.hidden) {
1945 WApplication *app;
1947 app = wApplicationOf(wwin->main_window);
1948 if (app) {
1949 /* trick to get focus to this window */
1950 app->last_focused = wwin;
1951 wUnhideApplication(app, False, False);
1954 if (wwin->flags.miniaturized) {
1955 wDeiconifyWindow(wwin);
1956 } else {
1957 if (!WFLAGP(wwin, no_focusable))
1958 wSetFocusTo(wwin->screen_ptr, wwin);
1959 wRaiseFrame(wwin->frame->core);