Update for 0.51.0
[wmaker-crm.git] / src / actions.c
blobe7132aff5323b0ebc7da30c0f94aec84b8241094
1 /* action.c- misc. window commands (miniaturize, hide etc.)
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
23 #include "wconfig.h"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <math.h>
32 #include <time.h>
34 #include "WindowMaker.h"
35 #include "wcore.h"
36 #include "framewin.h"
37 #include "window.h"
38 #include "client.h"
39 #include "icon.h"
40 #include "funcs.h"
41 #include "application.h"
42 #include "actions.h"
43 #include "stacking.h"
44 #include "appicon.h"
45 #include "dock.h"
46 #include "appmenu.h"
47 #include "winspector.h"
48 #include "list.h"
49 #include "workspace.h"
51 #ifdef GNOME_STUFF
52 # include "gnome.h"
53 #endif
54 #ifdef KWM_HINTS
55 # include "kwm.h"
56 #endif
58 #ifdef WMSOUND
59 #include "wmsound.h"
60 #endif
63 /****** Global Variables ******/
64 extern Time LastTimestamp;
65 extern Time LastFocusChange;
67 extern Cursor wCursor[WCUR_LAST];
69 extern WPreferences wPreferences;
71 extern Atom _XA_WM_TAKE_FOCUS;
73 /******* Local Variables *******/
74 static struct {
75 int steps;
76 int delay;
77 } shadePars[5] = {
78 {SHADE_STEPS_UF, SHADE_DELAY_UF},
79 {SHADE_STEPS_F, SHADE_DELAY_F},
80 {SHADE_STEPS_M, SHADE_DELAY_M},
81 {SHADE_STEPS_S, SHADE_DELAY_S},
82 {SHADE_STEPS_U, SHADE_DELAY_U}};
84 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
85 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
88 static int ignoreTimestamp=0;
91 #ifdef ANIMATIONS
92 static void
93 processEvents(int event_count)
95 XEvent event;
98 * This is a hack. When animations are enabled, processing of
99 * events ocurred during a animation are delayed until it's end.
100 * Calls that consider the TimeStamp, like XSetInputFocus(), will
101 * fail because the TimeStamp is too old. Then, for example, if
102 * the user changes window focus while a miniaturize animation is
103 * in course, the window will not get focus properly after the end
104 * of the animation. This tries to workaround it by passing CurrentTime
105 * as the TimeStamp for XSetInputFocus() for all events ocurred during
106 * the animation.
108 ignoreTimestamp=1;
109 while (XPending(dpy) && event_count--) {
110 WMNextEvent(dpy, &event);
111 WMHandleEvent(&event);
113 ignoreTimestamp=0;
115 #endif /* ANIMATIONS */
120 *----------------------------------------------------------------------
121 * wSetFocusTo--
122 * Changes the window focus to the one passed as argument.
123 * If the window to focus is not already focused, it will be brought
124 * to the head of the list of windows. Previously focused window is
125 * unfocused.
127 * Side effects:
128 * Window list may be reordered and the window focus is changed.
130 *----------------------------------------------------------------------
132 void
133 wSetFocusTo(WScreen *scr, WWindow *wwin)
135 WWindow *focused=scr->focused_window;
136 WWindow *owner = NULL;
137 int timestamp=LastTimestamp;
138 WApplication *oapp=NULL, *napp=NULL;
139 int wasfocused;
141 LastFocusChange = timestamp;
144 * This is a hack, because XSetInputFocus() should have a proper
145 * timestamp instead of CurrentTime but it seems that some times
146 * clients will not receive focus properly that way.
147 if (ignoreTimestamp)
149 timestamp = CurrentTime;
151 if (focused)
152 oapp = wApplicationOf(focused->main_window);
154 if (wwin==NULL) {
155 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
156 if (focused) {
157 wWindowUnfocus(focused);
159 if (oapp) {
160 wAppMenuUnmap(oapp->menu);
161 #ifdef NEWAPPICON
162 wApplicationDeactivate(oapp);
163 #endif
165 #ifdef KWM_HINTS
166 wKWMUpdateActiveWindowHint(scr);
167 wKWMSendEventMessage(NULL, WKWMFocusWindow);
168 #endif
169 return;
171 wasfocused = wwin->flags.focused;
172 napp = wApplicationOf(wwin->main_window);
174 /* remember last workspace where the app has been */
175 if (napp)
176 napp->last_workspace = wwin->screen_ptr->current_workspace;
178 if (WFLAGP(wwin, no_focusable))
179 return;
181 if (wwin->flags.mapped) {
182 /* install colormap if colormap mode is lock mode */
183 if (wPreferences.colormap_mode==WKF_CLICK)
184 wColormapInstallForWindow(scr, wwin);
186 /* set input focus */
187 switch (wwin->focus_mode) {
188 case WFM_NO_INPUT:
189 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
190 break;
192 case WFM_PASSIVE:
193 case WFM_LOCALLY_ACTIVE:
194 XSetInputFocus(dpy, wwin->client_win, RevertToParent, timestamp);
195 break;
197 case WFM_GLOBALLY_ACTIVE:
198 break;
200 XFlush(dpy);
201 if (wwin->protocols.TAKE_FOCUS) {
202 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
204 XSync(dpy, False);
205 } else {
206 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
209 /* if this is not the focused window focus it */
210 if (focused!=wwin) {
211 int foo=0;
213 if (wwin->client_win == focused->transient_for)
214 wwin->flags.semi_focused = 0;
215 else if (wwin->transient_for == focused->client_win)
216 focused->flags.semi_focused = 1;
218 if (wwin->transient_for
219 && wwin->transient_for == focused->transient_for) {
220 owner = wWindowFor(wwin->transient_for);
221 if (owner && owner->flags.semi_focused) {
222 foo=1;
223 /* this is to override the unfocusing of the mainwindow
224 * in the next wWindowUnfocus() and avoid flickering */
225 owner->flags.semi_focused = 0;
228 /* unfocus previous window */
229 wWindowUnfocus(focused);
230 if (foo) {
231 owner->flags.semi_focused = 1;
233 /* change the focus window list order */
234 if (wwin->prev)
235 wwin->prev->next=wwin->next;
236 if (wwin->next)
237 wwin->next->prev=wwin->prev;
239 wwin->prev = focused;
240 focused->next = wwin;
241 wwin->next = NULL;
242 scr->focused_window = wwin;
244 if (oapp && oapp != napp) {
245 wAppMenuUnmap(oapp->menu);
246 #ifdef NEWAPPICON
247 wApplicationDeactivate(oapp);
248 #endif
251 if ((owner=wWindowFor(wwin->transient_for))
252 && !owner->flags.semi_focused) {
253 owner->flags.semi_focused = 1;
254 wWindowUnfocus(owner);
256 wWindowFocus(wwin);
257 if (napp && !wasfocused) {
258 wAppMenuMap(napp->menu, wwin);
259 #ifdef NEWAPPICON
260 wApplicationActivate(napp);
261 #endif
263 #ifdef KWM_HINTS
264 wKWMUpdateActiveWindowHint(scr);
265 wKWMSendEventMessage(wwin, WKWMFocusWindow);
266 #endif
267 XFlush(dpy);
271 void
272 wShadeWindow(WWindow *wwin)
274 XWindowAttributes attribs;
275 time_t time0 = time(NULL);
276 #ifdef ANIMATIONS
277 int y, s, w, h;
278 #endif
280 if (wwin->flags.shaded)
281 return;
283 XLowerWindow(dpy, wwin->client_win);
285 #ifdef WMSOUND
286 wSoundPlay(WMSOUND_SHADE);
287 #endif
289 #ifdef ANIMATIONS
290 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
291 && !wPreferences.no_animations) {
292 /* do the shading animation */
293 h = wwin->frame->core->height;
294 s = h/SHADE_STEPS;
295 if (s < 1) s=1;
296 w = wwin->frame->core->width;
297 y = wwin->frame->top_width;
298 while (h>wwin->frame->top_width+1) {
299 XMoveWindow(dpy, wwin->client_win, 0, y);
300 XResizeWindow(dpy, wwin->frame->core->window, w, h);
301 XFlush(dpy);
303 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
304 break;
306 if (SHADE_DELAY > 0)
307 wusleep(SHADE_DELAY*1000L);
308 h-=s;
309 y-=s;
311 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
313 #endif /* ANIMATIONS */
315 wwin->flags.skip_next_animation = 0;
316 wwin->flags.shaded = 1;
317 wwin->flags.mapped=0;
318 XGetWindowAttributes(dpy, wwin->client_win, &attribs);
319 /* prevent window withdrawal when getting UnmapNotify */
320 XSelectInput(dpy, wwin->client_win,
321 attribs.your_event_mask & ~StructureNotifyMask);
322 XUnmapWindow(dpy, wwin->client_win);
323 XSelectInput(dpy, wwin->client_win, attribs.your_event_mask);
325 /* for the client it's just like iconification */
326 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
327 wwin->frame->top_width - 1);
329 wwin->client.y = wwin->frame_y - wwin->client.height
330 + wwin->frame->top_width;
331 wWindowSynthConfigureNotify(wwin);
334 wClientSetState(wwin, IconicState, None);
337 #ifdef GNOME_STUFF
338 wGNOMEUpdateClientStateHint(wwin, False);
339 #endif
340 #ifdef KWM_HINTS
341 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
342 wKWMSendEventMessage(wwin, WKWMChangedClient);
343 #endif
344 /* update window list to reflect shaded state */
345 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
347 #ifdef ANIMATIONS
348 if (!wwin->screen_ptr->flags.startup) {
349 /* Look at processEvents() for reason of this code. */
350 XSync(dpy, 0);
351 processEvents(XPending(dpy));
353 #endif
357 void
358 wUnshadeWindow(WWindow *wwin)
360 time_t time0 = time(NULL);
361 #ifdef ANIMATIONS
362 int y, s, w, h;
363 #endif /* ANIMATIONS */
366 if (!wwin->flags.shaded)
367 return;
369 wwin->flags.shaded = 0;
370 wwin->flags.mapped = 1;
371 XMapWindow(dpy, wwin->client_win);
373 #ifdef WMSOUND
374 wSoundPlay(WMSOUND_UNSHADE);
375 #endif
377 #ifdef ANIMATIONS
378 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
379 /* do the shading animation */
380 h = wwin->frame->top_width + wwin->frame->bottom_width;
381 y = wwin->frame->top_width - wwin->client.height;
382 s = abs(y)/SHADE_STEPS;
383 if (s<1) s=1;
384 w = wwin->frame->core->width;
385 XMoveWindow(dpy, wwin->client_win, 0, y);
386 if (s>0) {
387 while (h < wwin->client.height + wwin->frame->top_width
388 + wwin->frame->bottom_width) {
389 XResizeWindow(dpy, wwin->frame->core->window, w, h);
390 XMoveWindow(dpy, wwin->client_win, 0, y);
391 XSync(dpy, 0);
392 if (SHADE_DELAY > 0)
393 wusleep(SHADE_DELAY*2000L/3);
394 h+=s;
395 y+=s;
397 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
398 break;
401 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
403 #endif /* ANIMATIONS */
405 wwin->flags.skip_next_animation = 0;
406 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
407 wwin->frame->top_width + wwin->client.height
408 + wwin->frame->bottom_width);
410 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
411 wWindowSynthConfigureNotify(wwin);
414 wClientSetState(wwin, NormalState, None);
416 /* if the window is focused, set the focus again as it was disabled during
417 * shading */
418 if (wwin->flags.focused)
419 wSetFocusTo(wwin->screen_ptr, wwin);
421 #ifdef GNOME_STUFF
422 wGNOMEUpdateClientStateHint(wwin, False);
423 #endif
424 #ifdef KWM_HINTS
425 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
426 wKWMSendEventMessage(wwin, WKWMChangedClient);
427 #endif
429 /* update window list to reflect unshaded state */
430 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
435 void
436 wMaximizeWindow(WWindow *wwin, int directions)
438 int new_width, new_height, new_x, new_y;
439 WArea usableArea = wwin->screen_ptr->totalUsableArea;
441 if (wwin->flags.shaded) {
442 wwin->flags.skip_next_animation = 1;
443 wUnshadeWindow(wwin);
445 wwin->flags.maximized = directions;
446 wwin->old_geometry.width = wwin->client.width;
447 wwin->old_geometry.height = wwin->client.height;
448 wwin->old_geometry.x = wwin->frame_x;
449 wwin->old_geometry.y = wwin->frame_y;
451 #ifdef KWM_HINTS
452 wKWMUpdateClientGeometryRestore(wwin);
453 #endif
455 if (directions & MAX_HORIZONTAL) {
457 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
458 new_x = usableArea.x1;
460 } else {
462 new_x = wwin->frame_x;
463 new_width = wwin->frame->core->width;
467 if (directions & MAX_VERTICAL) {
469 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
470 new_y = usableArea.y1;
472 } else {
474 new_y = wwin->frame_y;
475 new_height = wwin->frame->core->height;
478 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
480 wWindowConstrainSize(wwin, &new_width, &new_height);
481 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
483 #ifdef GNOME_STUFF
484 wGNOMEUpdateClientStateHint(wwin, False);
485 #endif
486 #ifdef KWM_HINTS
487 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
488 wKWMSendEventMessage(wwin, WKWMChangedClient);
489 #endif
491 #ifdef WMSOUND
492 wSoundPlay(WMSOUND_MAXIMIZE);
493 #endif
497 void
498 wUnmaximizeWindow(WWindow *wwin)
500 int restore_x, restore_y;
502 if (!wwin->flags.maximized)
503 return;
505 if (wwin->flags.shaded) {
506 wwin->flags.skip_next_animation = 1;
507 wUnshadeWindow(wwin);
509 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
510 wwin->old_geometry.x : wwin->frame_x;
511 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
512 wwin->old_geometry.y : wwin->frame_y;
513 wwin->flags.maximized = 0;
514 wWindowConfigure(wwin, restore_x, restore_y,
515 wwin->old_geometry.width, wwin->old_geometry.height);
517 #ifdef GNOME_STUFF
518 wGNOMEUpdateClientStateHint(wwin, False);
519 #endif
520 #ifdef KWM_HINTS
521 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
522 wKWMSendEventMessage(wwin, WKWMChangedClient);
523 #endif
525 #ifdef WMSOUND
526 wSoundPlay(WMSOUND_UNMAXIMIZE);
527 #endif
530 #ifdef ANIMATIONS
531 static void
532 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
533 int fx, int fy, int fw, int fh, int steps)
535 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
536 float cx, cy, cw, ch;
537 float xstep, ystep, wstep, hstep;
538 XPoint points[5];
539 float dx, dch, midy;
540 float angle, final_angle, delta;
542 xstep = (float)(fx-x)/steps;
543 ystep = (float)(fy-y)/steps;
544 wstep = (float)(fw-w)/steps;
545 hstep = (float)(fh-h)/steps;
547 cx = (float)x;
548 cy = (float)y;
549 cw = (float)w;
550 ch = (float)h;
552 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
553 delta = (float)(final_angle/FRAMES);
554 for (angle=0;; angle+=delta) {
555 if (angle > final_angle)
556 angle = final_angle;
558 dx = (cw/10) - ((cw/5) * sin(angle));
559 dch = (ch/2) * cos(angle);
560 midy = cy + (ch/2);
562 points[0].x = cx + dx; points[0].y = midy - dch;
563 points[1].x = cx + cw - dx; points[1].y = points[0].y;
564 points[2].x = cx + cw + dx; points[2].y = midy + dch;
565 points[3].x = cx - dx; points[3].y = points[2].y;
566 points[4].x = points[0].x; points[4].y = points[0].y;
568 XGrabServer(dpy);
569 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
570 XFlush(dpy);
571 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
572 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
573 #endif
575 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
576 XUngrabServer(dpy);
577 cx+=xstep;
578 cy+=ystep;
579 cw+=wstep;
580 ch+=hstep;
581 if (angle >= final_angle)
582 break;
585 XFlush(dpy);
587 #undef FRAMES
590 static void
591 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
592 int fx, int fy, int fw, int fh, int steps)
594 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
595 float cx, cy, cw, ch;
596 float xstep, ystep, wstep, hstep;
597 XPoint points[5];
598 float angle, final_angle, a, d, delta;
600 x += w/2;
601 y += h/2;
602 fx += fw/2;
603 fy += fh/2;
605 xstep = (float)(fx-x)/steps;
606 ystep = (float)(fy-y)/steps;
607 wstep = (float)(fw-w)/steps;
608 hstep = (float)(fh-h)/steps;
610 cx = (float)x;
611 cy = (float)y;
612 cw = (float)w;
613 ch = (float)h;
615 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
616 delta = (float)(final_angle/FRAMES);
617 for (angle=0;; angle+=delta) {
618 if (angle > final_angle)
619 angle = final_angle;
621 a = atan(ch/cw);
622 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
624 points[0].x = cx+cos(angle-a)*d;
625 points[0].y = cy+sin(angle-a)*d;
626 points[1].x = cx+cos(angle+a)*d;
627 points[1].y = cy+sin(angle+a)*d;
628 points[2].x = cx+cos(angle-a+WM_PI)*d;
629 points[2].y = cy+sin(angle-a+WM_PI)*d;
630 points[3].x = cx+cos(angle+a+WM_PI)*d;
631 points[3].y = cy+sin(angle+a+WM_PI)*d;
632 points[4].x = cx+cos(angle-a)*d;
633 points[4].y = cy+sin(angle-a)*d;
634 XGrabServer(dpy);
635 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
636 XFlush(dpy);
637 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
638 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
639 #endif
641 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
642 XUngrabServer(dpy);
643 cx+=xstep;
644 cy+=ystep;
645 cw+=wstep;
646 ch+=hstep;
647 if (angle >= final_angle)
648 break;
651 XFlush(dpy);
653 #undef FRAMES
656 static void
657 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
658 int fx, int fy, int fw, int fh, int steps)
660 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
661 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
662 float xstep, ystep, wstep, hstep;
663 int i, j;
665 xstep = (float)(fx-x)/steps;
666 ystep = (float)(fy-y)/steps;
667 wstep = (float)(fw-w)/steps;
668 hstep = (float)(fh-h)/steps;
670 for (j=0; j<FRAMES; j++) {
671 cx[j] = (float)x;
672 cy[j] = (float)y;
673 cw[j] = (float)w;
674 ch[j] = (float)h;
676 XGrabServer(dpy);
677 for (i=0; i<steps; i++) {
678 for (j=0; j<FRAMES; j++) {
679 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
680 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
682 XFlush(dpy);
683 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
684 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
685 #endif
686 for (j=0; j<FRAMES; j++) {
687 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
688 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
689 if (j<FRAMES-1) {
690 cx[j]=cx[j+1];
691 cy[j]=cy[j+1];
692 cw[j]=cw[j+1];
693 ch[j]=ch[j+1];
694 } else {
695 cx[j]+=xstep;
696 cy[j]+=ystep;
697 cw[j]+=wstep;
698 ch[j]+=hstep;
703 for (j=0; j<FRAMES; j++) {
704 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
705 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
707 XFlush(dpy);
708 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
709 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
710 #endif
711 for (j=0; j<FRAMES; j++) {
712 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
713 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
716 XUngrabServer(dpy);
718 #undef FRAMES
721 static void
722 animateResize(WScreen *scr, int x, int y, int w, int h,
723 int fx, int fy, int fw, int fh, int hiding)
725 int style = wPreferences.iconification_style; /* Catch the value */
726 int steps, k;
728 if (style == WIS_NONE)
729 return;
731 if (style == WIS_RANDOM) {
732 style = rand()%3;
735 k = (hiding ? 2 : 3);
736 switch(style) {
737 case WIS_TWIST:
738 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
739 if (steps>0)
740 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
741 break;
742 case WIS_FLIP:
743 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
744 if (steps>0)
745 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
746 break;
747 case WIS_ZOOM:
748 default:
749 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
750 if (steps>0)
751 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
752 break;
755 #endif /* ANIMATIONS */
758 static void
759 flushExpose()
761 XEvent tmpev;
763 while (XCheckTypedEvent(dpy, Expose, &tmpev))
764 WMHandleEvent(&tmpev);
765 XSync(dpy, 0);
768 static void
769 unmapTransientsFor(WWindow *wwin)
771 WWindow *tmp;
772 XWindowAttributes attribs;
775 tmp = wwin->screen_ptr->focused_window;
776 while (tmp) {
777 /* unmap the transients for this transient */
778 if (tmp!=wwin && tmp->transient_for == wwin->client_win
779 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
780 || tmp->flags.shaded)) {
781 unmapTransientsFor(tmp);
782 XGetWindowAttributes(dpy, tmp->client_win, &attribs);
783 tmp->flags.miniaturized=1;
784 if (!tmp->flags.shaded) {
785 wWindowUnmap(tmp);
786 } else {
787 XUnmapWindow(dpy, tmp->frame->core->window);
790 if (!tmp->flags.shaded)
792 wClientSetState(tmp, IconicState, None);
793 #ifdef KWM_HINTS
794 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
795 wKWMSendEventMessage(tmp, WKWMRemoveWindow);
796 tmp->flags.kwm_hidden_for_modules = 1;
797 #endif
799 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
802 tmp = tmp->prev;
807 static void
808 mapTransientsFor(WWindow *wwin)
810 WWindow *tmp;
812 tmp = wwin->screen_ptr->focused_window;
813 while (tmp) {
814 /* recursively map the transients for this transient */
815 if (tmp!=wwin && tmp->transient_for == wwin->client_win
816 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
817 && tmp->icon==NULL) {
818 mapTransientsFor(tmp);
819 tmp->flags.miniaturized = 0;
820 if (!tmp->flags.shaded) {
821 wWindowMap(tmp);
822 } else {
823 XMapWindow(dpy, tmp->frame->core->window);
825 tmp->flags.semi_focused = 0;
827 if (!tmp->flags.shaded)
829 wClientSetState(tmp, NormalState, None);
830 #ifdef KWM_HINTS
831 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
832 if (tmp->flags.kwm_hidden_for_modules) {
833 wKWMSendEventMessage(tmp, WKWMAddWindow);
834 tmp->flags.kwm_hidden_for_modules = 0;
836 #endif
838 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
841 tmp = tmp->prev;
846 static void
847 setupIconGrabs(WIcon *icon)
849 /* setup passive grabs on the icon */
850 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
851 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
852 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
853 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
854 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
855 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
856 XSync(dpy, 0);
860 static WWindow*
861 recursiveTransientFor(WWindow *wwin)
863 int i;
865 if (!wwin)
866 return None;
868 /* hackish way to detect transient_for cycle */
869 i = wwin->screen_ptr->window_count+1;
871 while (wwin && wwin->transient_for != None && i>0) {
872 wwin = wWindowFor(wwin->transient_for);
873 i--;
875 if (i==0 && wwin) {
876 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
877 wwin->frame->title);
878 return NULL;
881 return wwin;
885 static void
886 removeIconGrabs(WIcon *icon)
888 /* remove passive grabs on the icon */
889 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
890 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
891 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
892 XSync(dpy, 0);
896 void
897 wIconifyWindow(WWindow *wwin)
899 XWindowAttributes attribs;
900 int present;
903 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
904 /* the window doesn't exist anymore */
905 return;
908 if (wwin->flags.miniaturized) {
909 return;
913 if (wwin->transient_for!=None) {
914 WWindow *owner = wWindowFor(wwin->transient_for);
916 if (owner && owner->flags.miniaturized)
917 return;
920 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
922 /* if the window is in another workspace, simplify process */
923 if (present) {
924 /* icon creation may take a while */
925 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
926 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
927 GrabModeAsync, None, None, CurrentTime);
930 if (!wwin->flags.icon_moved) {
931 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y);
933 wwin->icon = wIconCreate(wwin);
935 wwin->flags.miniaturized=1;
936 wwin->flags.mapped=0;
938 /* unmap transients */
940 unmapTransientsFor(wwin);
942 if (present) {
943 #ifdef WMSOUND
944 wSoundPlay(WMSOUND_ICONIFY);
945 #endif
947 XUngrabPointer(dpy, CurrentTime);
948 wWindowUnmap(wwin);
949 /* let all Expose events arrive so that we can repaint
950 * something before the animation starts (and the server is grabbed) */
951 XSync(dpy, 0);
952 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
953 flushExpose();
954 #ifdef ANIMATIONS
955 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
956 && !wPreferences.no_animations) {
957 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
958 wwin->frame->core->width, wwin->frame->core->height,
959 wwin->icon_x, wwin->icon_y,
960 wwin->icon->core->width, wwin->icon->core->height,
961 False);
963 #endif
966 wwin->flags.skip_next_animation = 0;
967 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
968 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
970 XMapWindow(dpy, wwin->icon->core->window);
971 AddToStackList(wwin->icon->core);
973 wLowerFrame(wwin->icon->core);
975 if (present) {
976 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
979 * It doesn't seem to be working and causes button event hangup
980 * when deiconifying a transient window.
981 setupIconGrabs(wwin->icon);
983 if ((wwin->flags.focused
984 || (owner && wwin->client_win == owner->client_win))
985 && wPreferences.focus_mode==WKF_CLICK) {
986 WWindow *tmp;
988 tmp = wwin->prev;
989 while (tmp) {
990 if (!WFLAGP(tmp, no_focusable)
991 && !(tmp->flags.hidden||tmp->flags.miniaturized))
992 break;
993 tmp = tmp->prev;
995 wSetFocusTo(wwin->screen_ptr, tmp);
996 } else if (wPreferences.focus_mode!=WKF_CLICK) {
997 wSetFocusTo(wwin->screen_ptr, NULL);
1000 #ifdef ANIMATIONS
1001 if (!wwin->screen_ptr->flags.startup) {
1002 Window clientwin = wwin->client_win;
1004 XSync(dpy, 0);
1005 processEvents(XPending(dpy));
1007 /* the window can disappear while doing the processEvents() */
1008 if (!wWindowFor(clientwin))
1009 return;
1011 #endif
1015 if (wwin->flags.selected)
1016 wIconSelect(wwin->icon);
1018 #ifdef GNOME_STUFF
1019 wGNOMEUpdateClientStateHint(wwin, False);
1020 #endif
1021 #ifdef KWM_HINTS
1022 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1023 wKWMSendEventMessage(wwin, WKWMChangedClient);
1024 #endif
1026 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1031 void
1032 wDeiconifyWindow(WWindow *wwin)
1034 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1036 if (!wwin->flags.miniaturized)
1037 return;
1039 if (wwin->transient_for != None) {
1040 WWindow *owner = recursiveTransientFor(wwin);
1042 if (wwin->flags.miniaturized) {
1043 wDeiconifyWindow(owner);
1044 wSetFocusTo(wwin->screen_ptr, wwin);
1045 wRaiseFrame(wwin->frame->core);
1046 return;
1050 wwin->flags.miniaturized = 0;
1051 if (!wwin->flags.shaded)
1052 wwin->flags.mapped = 1;
1054 if (wwin->icon->selected)
1055 wIconSelect(wwin->icon);
1057 XUnmapWindow(dpy, wwin->icon->core->window);
1059 #ifdef WMSOUND
1060 wSoundPlay(WMSOUND_DEICONIFY);
1061 #endif
1063 /* if the window is in another workspace, do it silently */
1064 #ifdef ANIMATIONS
1065 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1066 && !wwin->flags.skip_next_animation) {
1067 animateResize(wwin->screen_ptr, wwin->icon_x, wwin->icon_y,
1068 wwin->icon->core->width, wwin->icon->core->height,
1069 wwin->frame_x, wwin->frame_y,
1070 wwin->frame->core->width, wwin->frame->core->height,
1071 False);
1073 #endif /* ANIMATIONS */
1074 wwin->flags.skip_next_animation = 0;
1075 XGrabServer(dpy);
1076 if (!wwin->flags.shaded) {
1077 XMapWindow(dpy, wwin->client_win);
1079 XMapWindow(dpy, wwin->frame->core->window);
1080 wRaiseFrame(wwin->frame->core);
1081 if (!wwin->flags.shaded) {
1082 wClientSetState(wwin, NormalState, None);
1084 mapTransientsFor(wwin);
1085 RemoveFromStackList(wwin->icon->core);
1086 /* removeIconGrabs(wwin->icon);*/
1087 wIconDestroy(wwin->icon);
1088 wwin->icon = NULL;
1090 XUngrabServer(dpy);
1091 if (wPreferences.focus_mode==WKF_CLICK
1092 || wPreferences.focus_mode==WKF_SLOPPY)
1093 wSetFocusTo(wwin->screen_ptr, wwin);
1095 #ifdef ANIMATIONS
1096 if (!wwin->screen_ptr->flags.startup) {
1097 Window clientwin = wwin->client_win;
1099 XSync(dpy, 0);
1100 processEvents(XPending(dpy));
1102 if (!wWindowFor(clientwin))
1103 return;
1105 #endif
1107 if (wPreferences.auto_arrange_icons) {
1108 wArrangeIcons(wwin->screen_ptr, True);
1111 #ifdef GNOME_STUFF
1112 wGNOMEUpdateClientStateHint(wwin, False);
1113 #endif
1114 #ifdef KWM_HINTS
1115 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1116 wKWMSendEventMessage(wwin, WKWMChangedClient);
1117 #endif
1119 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1124 static void
1125 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1127 if (wwin->flags.miniaturized) {
1128 XUnmapWindow(dpy, wwin->icon->core->window);
1129 wwin->flags.hidden = 1;
1130 wwin->icon->mapped = 0;
1131 #ifdef GNOME_STUFF
1132 wGNOMEUpdateClientStateHint(wwin, False);
1133 #endif
1135 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1137 return;
1140 if (wwin->flags.inspector_open) {
1141 WWindow *pwin = wwin->inspector->frame;
1143 wWindowUnmap(pwin);
1144 pwin->flags.hidden = 1;
1146 wClientSetState(pwin, IconicState, icon->icon_win);
1149 wwin->flags.hidden = 1;
1150 wWindowUnmap(wwin);
1152 wClientSetState(wwin, IconicState, icon->icon_win);
1153 flushExpose();
1154 #ifdef WMSOUND
1155 wSoundPlay(WMSOUND_HIDE);
1156 #endif
1157 #ifdef ANIMATIONS
1158 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1159 !wwin->flags.skip_next_animation && animate) {
1160 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1161 wwin->frame->core->width, wwin->frame->core->height,
1162 icon_x, icon_y, icon->core->width, icon->core->height,
1163 True);
1165 #endif
1166 wwin->flags.skip_next_animation = 0;
1168 #ifdef GNOME_STUFF
1169 wGNOMEUpdateClientStateHint(wwin, False);
1170 #endif
1172 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1178 void
1179 wHideOtherApplications(WWindow *awin)
1181 WWindow *wwin;
1182 WApplication *tapp;
1183 #ifdef REDUCE_APPICONS
1184 char *tinstance, *tclass;
1185 unsigned int brokenwin = 0, match = 0;
1186 #endif
1188 if (!awin)
1189 return;
1190 wwin = awin->screen_ptr->focused_window;
1192 #ifdef REDUCE_APPICONS
1193 if (awin->wm_instance == NULL || awin->wm_class == NULL)
1194 brokenwin++;
1195 #endif
1197 while (wwin) {
1198 if (wwin!=awin
1199 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1200 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1201 && !wwin->flags.internal_window
1202 && (!wwin->flags.inspector_open || wwin->inspector->frame!=awin)
1203 && !WFLAGP(wwin, no_hide_others)) {
1205 #ifdef REDUCE_APPICONS
1206 match = 0;
1207 if (!brokenwin) {
1208 if ((tinstance = wwin->wm_instance) == NULL)
1209 tinstance = "";
1210 if ((tclass = wwin->wm_class) == NULL)
1211 tclass = "";
1212 if ((strcmp(awin->wm_instance, tinstance) == 0) &&
1213 (strcmp(awin->wm_class, tclass) == 0) )
1214 match++;
1216 #endif
1218 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1219 if (!WFLAGP(wwin, no_miniaturizable)) {
1220 wwin->flags.skip_next_animation = 1;
1221 wIconifyWindow(wwin);
1223 } else if (wwin->main_window!=None
1224 #ifndef REDUCE_APPICONS
1225 && awin->main_window != wwin->main_window) {
1226 #else
1227 && (awin->main_window != wwin->main_window && !match)) {
1228 #endif
1229 tapp = wApplicationOf(wwin->main_window);
1230 if (tapp) {
1231 tapp->flags.skip_next_animation = 1;
1232 wHideApplication(tapp);
1233 } else {
1234 if (!WFLAGP(wwin, no_miniaturizable)) {
1235 wwin->flags.skip_next_animation = 1;
1236 wIconifyWindow(wwin);
1241 wwin = wwin->prev;
1244 wSetFocusTo(awin->screen_ptr, awin);
1250 void
1251 wHideApplication(WApplication *wapp)
1253 #ifdef REDUCE_APPICONS
1254 WApplication *tapp;
1255 char *tinstance, *tclass;
1256 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1257 #endif
1258 WScreen *scr;
1259 WWindow *wlist;
1260 int hadfocus;
1262 if (!wapp) {
1263 wwarning("trying to hide a non grouped window");
1264 return;
1266 if (!wapp->main_window_desc) {
1267 wwarning("group leader not found for window group");
1268 return;
1270 #ifdef REDUCE_APPICONS
1271 if ((wapp->main_window_desc->wm_instance == NULL) ||
1272 (wapp->main_window_desc->wm_class == NULL))
1273 nowmhints++;
1274 #endif
1275 scr = wapp->main_window_desc->screen_ptr;
1276 hadfocus = 0;
1277 wlist = scr->focused_window;
1278 if (!wlist)
1279 return;
1281 if (wlist->main_window == wapp->main_window)
1282 wapp->last_focused = wlist;
1283 else
1284 wapp->last_focused = NULL;
1285 while (wlist) {
1286 #ifdef REDUCE_APPICONS
1287 matchwmhints = matchworkspace = 0;
1288 if (!nowmhints) {
1289 tapp = wApplicationOf(wlist->main_window);
1290 tinstance = tclass = NULL;
1291 if (tapp) {
1292 if (tapp->main_window_desc) {
1293 tinstance = tapp->main_window_desc->wm_instance;
1294 tclass = tapp->main_window_desc->wm_class;
1297 if (tapp == NULL || tinstance == NULL || tclass == NULL) {
1298 /* Should never reach here */
1299 tinstance = "";
1300 tclass = "";
1302 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0) &&
1303 (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1304 matchwmhints++;
1306 if (wlist->frame) {
1307 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1308 matchworkspace++;
1310 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1311 matchworkspace) {
1312 #ifdef I_HATE_THIS
1314 #endif
1315 #else
1316 if (wlist->main_window == wapp->main_window) {
1317 #endif
1318 if (wlist->flags.focused) {
1319 hadfocus = 1;
1321 if (wapp->app_icon)
1322 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1323 wapp->app_icon->y_pos, wlist,
1324 !wapp->flags.skip_next_animation);
1326 wlist = wlist->prev;
1329 wapp->flags.skip_next_animation = 0;
1331 if (hadfocus) {
1332 if (wPreferences.focus_mode==WKF_CLICK) {
1333 wlist = scr->focused_window;
1334 while (wlist) {
1335 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1336 && (wlist->flags.mapped || wlist->flags.shaded))
1337 break;
1338 wlist = wlist->prev;
1340 wSetFocusTo(scr, wlist);
1341 } else {
1342 wSetFocusTo(scr, NULL);
1346 wapp->flags.hidden = 1;
1348 if(wPreferences.auto_arrange_icons) {
1349 wArrangeIcons(scr, True);
1356 static void
1357 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1358 int bringToCurrentWS)
1360 if (bringToCurrentWS)
1361 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1363 wwin->flags.hidden=0;
1364 wwin->flags.mapped=1;
1366 #ifdef WMSOUND
1367 wSoundPlay(WMSOUND_UNHIDE);
1368 #endif
1369 #ifdef ANIMATIONS
1370 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1371 && animate) {
1372 animateResize(wwin->screen_ptr, icon_x, icon_y,
1373 icon->core->width, icon->core->height,
1374 wwin->frame_x, wwin->frame_y,
1375 wwin->frame->core->width, wwin->frame->core->height,
1376 True);
1378 #endif
1379 wwin->flags.skip_next_animation = 0;
1380 XMapWindow(dpy, wwin->client_win);
1381 XMapWindow(dpy, wwin->frame->core->window);
1382 wClientSetState(wwin, NormalState, None);
1383 wRaiseFrame(wwin->frame->core);
1384 if (wwin->flags.inspector_open) {
1385 WWindow *pwin = wwin->inspector->frame;
1387 pwin->flags.hidden = 0;
1388 pwin->flags.mapped = 1;
1389 XMapWindow(dpy, pwin->client_win);
1390 XMapWindow(dpy, pwin->frame->core->window);
1391 wClientSetState(pwin, NormalState, None);
1394 #ifdef GNOME_STUFF
1395 wGNOMEUpdateClientStateHint(wwin, False);
1396 #endif
1398 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1403 void
1404 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1406 WScreen *scr;
1407 WWindow *wlist, *next;
1408 WWindow *focused=NULL;
1409 #ifdef REDUCE_APPICONS
1410 char *tinstance, *tclass;
1411 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1412 #endif
1414 if (!wapp) {
1415 return;
1418 #ifdef REDUCE_APPICONS
1419 if ((wapp->main_window_desc->wm_class == NULL) ||
1420 (wapp->main_window_desc->wm_instance == NULL))
1421 nowmhints++;
1422 #endif
1424 scr = wapp->main_window_desc->screen_ptr;
1425 wlist = scr->focused_window;
1426 if (!wlist) return;
1427 /* goto beginning of list */
1428 while (wlist->prev)
1429 wlist = wlist->prev;
1431 while (wlist) {
1432 next = wlist->next;
1434 #ifndef REDUCE_APPICONS
1435 if (wlist->main_window == wapp->main_window) {
1436 #else
1437 matchwmhints = matchworkspace = 0;
1438 if (!nowmhints) {
1439 if ((tinstance = wlist->wm_instance) == NULL)
1440 tinstance = "";
1441 if ((tclass = wlist->wm_class) == NULL)
1442 tclass = "";
1443 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0)
1444 && (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1445 matchwmhints++;
1447 if (wlist->frame) {
1448 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1449 matchworkspace++;
1452 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1453 matchworkspace) {
1454 #endif
1455 if (wlist->flags.focused)
1456 focused = wlist;
1457 else if (!focused || !focused->flags.focused)
1458 focused = wlist;
1460 if (wlist->flags.miniaturized && wlist->icon) {
1461 if (bringToCurrentWS || wPreferences.sticky_icons
1462 || wlist->frame->workspace == scr->current_workspace) {
1463 if (!wlist->icon->mapped) {
1464 XMapWindow(dpy, wlist->icon->core->window);
1465 wlist->icon->mapped = 1;
1467 wlist->flags.hidden = 0;
1469 UpdateSwitchMenu(scr, wlist, ACTION_CHANGE_STATE);
1471 if (wlist->frame->workspace != scr->current_workspace)
1472 wWindowChangeWorkspace(wlist, scr->current_workspace);
1474 if (miniwindows) {
1475 wDeiconifyWindow(wlist);
1477 } else if (wlist->flags.hidden) {
1478 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1479 wapp->app_icon->y_pos, wlist,
1480 !wapp->flags.skip_next_animation,
1481 bringToCurrentWS);
1482 } else {
1483 if (bringToCurrentWS
1484 && wlist->frame->workspace != scr->current_workspace) {
1485 wWindowChangeWorkspace(wlist, scr->current_workspace);
1487 wRaiseFrame(wlist->frame->core);
1490 wlist = next;
1493 wapp->flags.skip_next_animation = 0;
1494 wapp->flags.hidden = 0;
1496 if (focused)
1497 wSetFocusTo(scr, focused);
1498 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1499 wSetFocusTo(scr, wapp->last_focused);
1500 wapp->last_focused = NULL;
1501 if (wPreferences.auto_arrange_icons) {
1502 wArrangeIcons(scr, True);
1508 void
1509 wShowAllWindows(WScreen *scr)
1511 WWindow *wwin, *old_foc;
1512 WApplication *wapp;
1514 old_foc = wwin = scr->focused_window;
1515 while (wwin) {
1516 if (!wwin->flags.internal_window &&
1517 (scr->current_workspace == wwin->frame->workspace
1518 || IS_OMNIPRESENT(wwin))) {
1519 if (wwin->flags.miniaturized) {
1520 wwin->flags.skip_next_animation = 1;
1521 wDeiconifyWindow(wwin);
1522 } else if (wwin->flags.hidden) {
1523 wapp = wApplicationOf(wwin->main_window);
1524 if (wapp) {
1525 wUnhideApplication(wapp, False, False);
1526 } else {
1527 wwin->flags.skip_next_animation = 1;
1528 wDeiconifyWindow(wwin);
1532 wwin = wwin->prev;
1534 wSetFocusTo(scr, old_foc);
1535 /*wRaiseFrame(old_foc->frame->core);*/
1539 void
1540 wRefreshDesktop(WScreen *scr)
1542 Window win;
1543 XSetWindowAttributes attr;
1545 attr.backing_store = NotUseful;
1546 attr.save_under = False;
1547 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1548 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1549 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1550 &attr);
1551 XMapRaised(dpy, win);
1552 XDestroyWindow(dpy, win);
1553 XFlush(dpy);
1557 void
1558 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1560 WWindow *wwin;
1561 WAppIcon *aicon;
1562 int pf; /* primary axis */
1563 int sf; /* secondary axis */
1564 int fullW;
1565 int fullH;
1566 int pi, si;
1567 int sx1, sx2, sy1, sy2; /* screen boundary */
1568 int sw, sh;
1569 int xo, yo;
1570 int xs, ys;
1571 int isize = wPreferences.icon_size;
1574 * Find out screen boundaries.
1576 sx1 = 0;
1577 sy1 = 0;
1578 sx2 = scr->scr_width;
1579 sy2 = scr->scr_height;
1580 if (scr->dock) {
1581 if (scr->dock->on_right_side)
1582 sx2 -= isize + DOCK_EXTRA_SPACE;
1583 else
1584 sx1 += isize + DOCK_EXTRA_SPACE;
1587 sw = isize * (scr->scr_width/isize);
1588 sh = isize * (scr->scr_height/isize);
1589 fullW = (sx2-sx1)/isize;
1590 fullH = (sy2-sy1)/isize;
1592 /* icon yard boundaries */
1593 if (wPreferences.icon_yard & IY_VERT) {
1594 pf = fullH;
1595 sf = fullW;
1596 } else {
1597 pf = fullW;
1598 sf = fullH;
1600 if (wPreferences.icon_yard & IY_RIGHT) {
1601 xo = sx2 - isize;
1602 xs = -1;
1603 } else {
1604 xo = sx1;
1605 xs = 1;
1607 if (wPreferences.icon_yard & IY_TOP) {
1608 yo = sy1;
1609 ys = 1;
1610 } else {
1611 yo = sy2 - isize;
1612 ys = -1;
1615 /* arrange icons putting the most recently focused window
1616 * as the last icon */
1617 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1618 : xo + xs*(pi*isize))
1619 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1620 : yo + ys*(si*isize))
1622 /* arrange application icons */
1623 aicon = scr->app_icon_list;
1624 /* reverse them to avoid unnecessarily sliding of icons */
1625 while (aicon && aicon->next)
1626 aicon = aicon->next;
1628 pi = 0;
1629 si = 0;
1630 while (aicon) {
1631 if (!aicon->docked) {
1632 if (aicon->x_pos != X || aicon->y_pos != Y) {
1633 #ifdef ANIMATIONS
1634 if (!wPreferences.no_animations) {
1635 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1636 X, Y);
1638 #endif /* ANIMATIONS */
1640 wAppIconMove(aicon, X, Y);
1641 pi++;
1643 /* we reversed the order so we use prev */
1644 aicon = aicon->prev;
1645 if (pi >= pf) {
1646 pi=0;
1647 si++;
1651 /* arrange miniwindows */
1653 wwin = scr->focused_window;
1654 /* reverse them to avoid unnecessarily shuffling */
1655 while (wwin && wwin->prev)
1656 wwin = wwin->prev;
1658 while (wwin) {
1659 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1660 (wwin->frame->workspace==scr->current_workspace ||
1661 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1663 if (arrangeAll || !wwin->flags.icon_moved) {
1664 if (wwin->icon_x != X || wwin->icon_y != Y) {
1665 #ifdef ANIMATIONS
1666 if (wPreferences.no_animations) {
1667 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1668 } else {
1669 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1670 wwin->icon_y, X, Y);
1672 #else
1673 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1674 #endif /* ANIMATIONS */
1676 wwin->icon_x = X;
1677 wwin->icon_y = Y;
1678 wwin->flags.icon_moved = 0;
1679 pi++;
1682 /* we reversed the order, so we use next */
1683 wwin = wwin->next;
1684 if (pi >= pf) {
1685 pi=0;
1686 si++;
1692 void
1693 wSelectWindow(WWindow *wwin, Bool flag)
1695 WScreen *scr = wwin->screen_ptr;
1696 if (flag) {
1697 wwin->flags.selected = 1;
1698 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1699 scr->selected_windows = list_cons(wwin, scr->selected_windows);
1700 } else {
1701 wwin->flags.selected = 0;
1702 XSetWindowBorder(dpy, wwin->frame->core->window,
1703 scr->frame_border_pixel);
1704 scr->selected_windows = list_remove_elem(scr->selected_windows, wwin);
1709 void
1710 wMakeWindowVisible(WWindow *wwin)
1712 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1714 if (wwin->flags.shaded) {
1715 wUnshadeWindow(wwin);
1717 if (wwin->flags.hidden) {
1718 wUnhideApplication(wApplicationOf(wwin->main_window), False, False);
1719 } else if (wwin->flags.miniaturized) {
1720 wDeiconifyWindow(wwin);
1721 } else {
1722 wSetFocusTo(wwin->screen_ptr, wwin);
1723 wRaiseFrame(wwin->frame->core);