removed FocusFollowMouse
[wmaker-crm.git] / src / actions.c
blob11f09e5363e8ce47c755e951103c8ffefdc8db1e
1 /* action.c- misc. window commands (miniaturize, hide etc.)
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998, 1999 Alfredo K. Kojima
6 * Copyright (c) 1998 Dan Pascu
7 *
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"
52 #ifdef GNOME_STUFF
53 # include "gnome.h"
54 #endif
55 #ifdef KWM_HINTS
56 # include "kwm.h"
57 #endif
61 /****** Global Variables ******/
62 extern Time LastTimestamp;
63 extern Time LastFocusChange;
65 extern Cursor wCursor[WCUR_LAST];
67 extern WPreferences wPreferences;
69 extern Atom _XA_WM_TAKE_FOCUS;
72 /******* Local Variables *******/
73 static struct {
74 int steps;
75 int delay;
76 } shadePars[5] = {
77 {SHADE_STEPS_UF, SHADE_DELAY_UF},
78 {SHADE_STEPS_F, SHADE_DELAY_F},
79 {SHADE_STEPS_M, SHADE_DELAY_M},
80 {SHADE_STEPS_S, SHADE_DELAY_S},
81 {SHADE_STEPS_U, SHADE_DELAY_U}};
83 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
84 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
87 static int ignoreTimestamp=0;
90 #ifdef ANIMATIONS
91 static void
92 processEvents(int event_count)
94 XEvent event;
97 * This is a hack. When animations are enabled, processing of
98 * events ocurred during a animation are delayed until it's end.
99 * Calls that consider the TimeStamp, like XSetInputFocus(), will
100 * fail because the TimeStamp is too old. Then, for example, if
101 * the user changes window focus while a miniaturize animation is
102 * in course, the window will not get focus properly after the end
103 * of the animation. This tries to workaround it by passing CurrentTime
104 * as the TimeStamp for XSetInputFocus() for all events ocurred during
105 * the animation.
107 ignoreTimestamp=1;
108 while (XPending(dpy) && event_count--) {
109 WMNextEvent(dpy, &event);
110 WMHandleEvent(&event);
112 ignoreTimestamp=0;
114 #endif /* ANIMATIONS */
119 *----------------------------------------------------------------------
120 * wSetFocusTo--
121 * Changes the window focus to the one passed as argument.
122 * If the window to focus is not already focused, it will be brought
123 * to the head of the list of windows. Previously focused window is
124 * unfocused.
126 * Side effects:
127 * Window list may be reordered and the window focus is changed.
129 *----------------------------------------------------------------------
131 void
132 wSetFocusTo(WScreen *scr, WWindow *wwin)
134 static WScreen *old_scr=NULL;
136 WWindow *old_focused;
137 WWindow *focused=scr->focused_window;
138 int timestamp=LastTimestamp;
139 WApplication *oapp=NULL, *napp=NULL;
140 int wasfocused;
142 if (!old_scr)
143 old_scr=scr;
144 old_focused=old_scr->focused_window;
146 LastFocusChange = timestamp;
149 * This is a hack, because XSetInputFocus() should have a proper
150 * timestamp instead of CurrentTime but it seems that some times
151 * clients will not receive focus properly that way.
152 if (ignoreTimestamp)
154 timestamp = CurrentTime;
156 if (old_focused)
157 oapp = wApplicationOf(old_focused->main_window);
159 if (wwin == NULL) {
160 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
161 if (old_focused) {
162 wWindowUnfocus(old_focused);
164 if (oapp) {
165 wAppMenuUnmap(oapp->menu);
166 #ifdef NEWAPPICON
167 wApplicationDeactivate(oapp);
168 #endif
170 #ifdef KWM_HINTS
171 wKWMUpdateActiveWindowHint(scr);
172 wKWMSendEventMessage(NULL, WKWMFocusWindow);
173 #endif
174 return;
175 } else if (old_scr != scr && old_focused) {
176 wWindowUnfocus(old_focused);
179 wasfocused = wwin->flags.focused;
180 napp = wApplicationOf(wwin->main_window);
182 /* remember last workspace where the app has been */
183 if (napp)
184 napp->last_workspace = wwin->screen_ptr->current_workspace;
186 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
187 /* install colormap if colormap mode is lock mode */
188 if (wPreferences.colormap_mode==WCM_CLICK)
189 wColormapInstallForWindow(scr, wwin);
191 /* set input focus */
192 switch (wwin->focus_mode) {
193 case WFM_NO_INPUT:
194 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
195 break;
197 case WFM_PASSIVE:
198 case WFM_LOCALLY_ACTIVE:
199 XSetInputFocus(dpy, wwin->client_win, RevertToParent, timestamp);
200 break;
202 case WFM_GLOBALLY_ACTIVE:
203 break;
205 XFlush(dpy);
206 if (wwin->protocols.TAKE_FOCUS) {
207 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
209 XSync(dpy, False);
210 } else {
211 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
213 if (WFLAGP(wwin, no_focusable))
214 return;
216 /* if this is not the focused window focus it */
217 if (focused!=wwin) {
218 /* change the focus window list order */
219 if (wwin->prev)
220 wwin->prev->next = wwin->next;
222 if (wwin->next)
223 wwin->next->prev = wwin->prev;
225 wwin->prev = focused;
226 focused->next = wwin;
227 wwin->next = NULL;
228 scr->focused_window = wwin;
230 if (oapp && oapp != napp) {
231 wAppMenuUnmap(oapp->menu);
232 #ifdef NEWAPPICON
233 wApplicationDeactivate(oapp);
234 #endif
238 wWindowFocus(wwin, focused);
240 if (napp && !wasfocused) {
241 #ifdef USER_MENU
242 wUserMenuRefreshInstances(napp->menu, wwin);
243 #endif /* USER_MENU */
245 if (wwin->flags.mapped)
246 wAppMenuMap(napp->menu, wwin);
247 #ifdef NEWAPPICON
248 wApplicationActivate(napp);
249 #endif
251 #ifdef KWM_HINTS
252 wKWMUpdateActiveWindowHint(scr);
253 wKWMSendEventMessage(wwin, WKWMFocusWindow);
254 #endif
255 XFlush(dpy);
256 old_scr=scr;
260 void
261 wShadeWindow(WWindow *wwin)
263 time_t time0 = time(NULL);
264 #ifdef ANIMATIONS
265 int y, s, w, h;
266 #endif
268 if (wwin->flags.shaded)
269 return;
271 XLowerWindow(dpy, wwin->client_win);
273 wSoundPlay(WSOUND_SHADE);
275 #ifdef ANIMATIONS
276 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
277 && !wPreferences.no_animations) {
278 /* do the shading animation */
279 h = wwin->frame->core->height;
280 s = h/SHADE_STEPS;
281 if (s < 1) s=1;
282 w = wwin->frame->core->width;
283 y = wwin->frame->top_width;
284 while (h>wwin->frame->top_width+1) {
285 XMoveWindow(dpy, wwin->client_win, 0, y);
286 XResizeWindow(dpy, wwin->frame->core->window, w, h);
287 XFlush(dpy);
289 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
290 break;
292 if (SHADE_DELAY > 0)
293 wusleep(SHADE_DELAY*1000L);
294 h-=s;
295 y-=s;
297 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
299 #endif /* ANIMATIONS */
301 wwin->flags.skip_next_animation = 0;
302 wwin->flags.shaded = 1;
303 wwin->flags.mapped = 0;
304 /* prevent window withdrawal when getting UnmapNotify */
305 XSelectInput(dpy, wwin->client_win,
306 wwin->event_mask & ~StructureNotifyMask);
307 XUnmapWindow(dpy, wwin->client_win);
308 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
310 /* for the client it's just like iconification */
311 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
312 wwin->frame->top_width - 1);
314 wwin->client.y = wwin->frame_y - wwin->client.height
315 + wwin->frame->top_width;
316 wWindowSynthConfigureNotify(wwin);
319 wClientSetState(wwin, IconicState, None);
322 #ifdef GNOME_STUFF
323 wGNOMEUpdateClientStateHint(wwin, False);
324 #endif
325 #ifdef KWM_HINTS
326 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
327 wKWMSendEventMessage(wwin, WKWMChangedClient);
328 #endif
329 /* update window list to reflect shaded state */
330 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
332 #ifdef ANIMATIONS
333 if (!wwin->screen_ptr->flags.startup) {
334 /* Look at processEvents() for reason of this code. */
335 XSync(dpy, 0);
336 processEvents(XPending(dpy));
338 #endif
342 void
343 wUnshadeWindow(WWindow *wwin)
345 time_t time0 = time(NULL);
346 #ifdef ANIMATIONS
347 int y, s, w, h;
348 #endif /* ANIMATIONS */
351 if (!wwin->flags.shaded)
352 return;
354 wwin->flags.shaded = 0;
355 wwin->flags.mapped = 1;
356 XMapWindow(dpy, wwin->client_win);
358 wSoundPlay(WSOUND_UNSHADE);
360 #ifdef ANIMATIONS
361 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
362 /* do the shading animation */
363 h = wwin->frame->top_width + wwin->frame->bottom_width;
364 y = wwin->frame->top_width - wwin->client.height;
365 s = abs(y)/SHADE_STEPS;
366 if (s<1) s=1;
367 w = wwin->frame->core->width;
368 XMoveWindow(dpy, wwin->client_win, 0, y);
369 if (s>0) {
370 while (h < wwin->client.height + wwin->frame->top_width
371 + wwin->frame->bottom_width) {
372 XResizeWindow(dpy, wwin->frame->core->window, w, h);
373 XMoveWindow(dpy, wwin->client_win, 0, y);
374 XFlush(dpy);
375 if (SHADE_DELAY > 0)
376 wusleep(SHADE_DELAY*2000L/3);
377 h+=s;
378 y+=s;
380 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
381 break;
384 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
386 #endif /* ANIMATIONS */
388 wwin->flags.skip_next_animation = 0;
389 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
390 wwin->frame->top_width + wwin->client.height
391 + wwin->frame->bottom_width);
393 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
394 wWindowSynthConfigureNotify(wwin);
397 wClientSetState(wwin, NormalState, None);
399 /* if the window is focused, set the focus again as it was disabled during
400 * shading */
401 if (wwin->flags.focused)
402 wSetFocusTo(wwin->screen_ptr, wwin);
404 #ifdef GNOME_STUFF
405 wGNOMEUpdateClientStateHint(wwin, False);
406 #endif
407 #ifdef KWM_HINTS
408 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
409 wKWMSendEventMessage(wwin, WKWMChangedClient);
410 #endif
412 /* update window list to reflect unshaded state */
413 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
418 void
419 wMaximizeWindow(WWindow *wwin, int directions)
421 int new_width, new_height, new_x, new_y;
422 WArea usableArea = wwin->screen_ptr->totalUsableArea;
423 WArea totalArea;
426 if (WFLAGP(wwin, no_resizable))
427 return;
429 totalArea.x1 = 0;
430 totalArea.y1 = 0;
431 totalArea.x2 = wwin->screen_ptr->scr_width;
432 totalArea.y2 = wwin->screen_ptr->scr_height;
434 #ifdef XINERAMA
435 if (wwin->screen_ptr->xine_count > 0
436 && !(directions & MAX_IGNORE_XINERAMA)) {
437 WScreen *scr = wwin->screen_ptr;
438 WMRect rect;
440 rect = wGetRectForHead(scr, wGetHeadForWindow(wwin));
441 totalArea.x1 = rect.pos.x;
442 totalArea.y1 = rect.pos.y;
443 totalArea.x2 = totalArea.x1 + rect.size.width;
444 totalArea.y2 = totalArea.y1 + rect.size.height;
446 usableArea.x1 = WMAX(totalArea.x1, usableArea.x1);
447 usableArea.y1 = WMAX(totalArea.y1, usableArea.y1);
448 usableArea.x2 = WMIN(totalArea.x2, usableArea.x2);
449 usableArea.y2 = WMIN(totalArea.y2, usableArea.y2);
451 #endif /* XINERAMA */
453 if (WFLAGP(wwin, full_maximize)) {
454 usableArea = totalArea;
457 if (wwin->flags.shaded) {
458 wwin->flags.skip_next_animation = 1;
459 wUnshadeWindow(wwin);
461 wwin->flags.maximized = directions;
462 wwin->old_geometry.width = wwin->client.width;
463 wwin->old_geometry.height = wwin->client.height;
464 wwin->old_geometry.x = wwin->frame_x;
465 wwin->old_geometry.y = wwin->frame_y;
467 #ifdef KWM_HINTS
468 wKWMUpdateClientGeometryRestore(wwin);
469 #endif
471 if (directions & MAX_HORIZONTAL) {
473 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
474 new_x = usableArea.x1;
476 } else {
478 new_x = wwin->frame_x;
479 new_width = wwin->frame->core->width;
483 if (directions & MAX_VERTICAL) {
485 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
486 new_y = usableArea.y1;
487 if (WFLAGP(wwin, full_maximize)) {
488 new_y -= wwin->frame->top_width;
489 new_height += wwin->frame->bottom_width - 1;
491 } else {
492 new_y = wwin->frame_y;
493 new_height = wwin->frame->core->height;
496 if (!WFLAGP(wwin, full_maximize)) {
497 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
500 wWindowConstrainSize(wwin, &new_width, &new_height);
501 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
503 #ifdef GNOME_STUFF
504 wGNOMEUpdateClientStateHint(wwin, False);
505 #endif
506 #ifdef KWM_HINTS
507 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
508 wKWMSendEventMessage(wwin, WKWMChangedClient);
509 #endif
511 wSoundPlay(WSOUND_MAXIMIZE);
515 void
516 wUnmaximizeWindow(WWindow *wwin)
518 int restore_x, restore_y;
520 if (!wwin->flags.maximized)
521 return;
523 if (wwin->flags.shaded) {
524 wwin->flags.skip_next_animation = 1;
525 wUnshadeWindow(wwin);
527 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
528 wwin->old_geometry.x : wwin->frame_x;
529 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
530 wwin->old_geometry.y : wwin->frame_y;
531 wwin->flags.maximized = 0;
532 wWindowConfigure(wwin, restore_x, restore_y,
533 wwin->old_geometry.width, wwin->old_geometry.height);
535 #ifdef GNOME_STUFF
536 wGNOMEUpdateClientStateHint(wwin, False);
537 #endif
538 #ifdef KWM_HINTS
539 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
540 wKWMSendEventMessage(wwin, WKWMChangedClient);
541 #endif
543 wSoundPlay(WSOUND_UNMAXIMIZE);
546 #ifdef ANIMATIONS
547 static void
548 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
549 int fx, int fy, int fw, int fh, int steps)
551 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
552 float cx, cy, cw, ch;
553 float xstep, ystep, wstep, hstep;
554 XPoint points[5];
555 float dx, dch, midy;
556 float angle, final_angle, delta;
558 xstep = (float)(fx-x)/steps;
559 ystep = (float)(fy-y)/steps;
560 wstep = (float)(fw-w)/steps;
561 hstep = (float)(fh-h)/steps;
563 cx = (float)x;
564 cy = (float)y;
565 cw = (float)w;
566 ch = (float)h;
568 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
569 delta = (float)(final_angle/FRAMES);
570 for (angle=0;; angle+=delta) {
571 if (angle > final_angle)
572 angle = final_angle;
574 dx = (cw/10) - ((cw/5) * sin(angle));
575 dch = (ch/2) * cos(angle);
576 midy = cy + (ch/2);
578 points[0].x = cx + dx; points[0].y = midy - dch;
579 points[1].x = cx + cw - dx; points[1].y = points[0].y;
580 points[2].x = cx + cw + dx; points[2].y = midy + dch;
581 points[3].x = cx - dx; points[3].y = points[2].y;
582 points[4].x = points[0].x; points[4].y = points[0].y;
584 XGrabServer(dpy);
585 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
586 XFlush(dpy);
587 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
588 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
589 #endif
591 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
592 XUngrabServer(dpy);
593 cx+=xstep;
594 cy+=ystep;
595 cw+=wstep;
596 ch+=hstep;
597 if (angle >= final_angle)
598 break;
601 XFlush(dpy);
603 #undef FRAMES
606 static void
607 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
608 int fx, int fy, int fw, int fh, int steps)
610 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
611 float cx, cy, cw, ch;
612 float xstep, ystep, wstep, hstep;
613 XPoint points[5];
614 float angle, final_angle, a, d, delta;
616 x += w/2;
617 y += h/2;
618 fx += fw/2;
619 fy += fh/2;
621 xstep = (float)(fx-x)/steps;
622 ystep = (float)(fy-y)/steps;
623 wstep = (float)(fw-w)/steps;
624 hstep = (float)(fh-h)/steps;
626 cx = (float)x;
627 cy = (float)y;
628 cw = (float)w;
629 ch = (float)h;
631 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
632 delta = (float)(final_angle/FRAMES);
633 for (angle=0;; angle+=delta) {
634 if (angle > final_angle)
635 angle = final_angle;
637 a = atan(ch/cw);
638 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
640 points[0].x = cx+cos(angle-a)*d;
641 points[0].y = cy+sin(angle-a)*d;
642 points[1].x = cx+cos(angle+a)*d;
643 points[1].y = cy+sin(angle+a)*d;
644 points[2].x = cx+cos(angle-a+WM_PI)*d;
645 points[2].y = cy+sin(angle-a+WM_PI)*d;
646 points[3].x = cx+cos(angle+a+WM_PI)*d;
647 points[3].y = cy+sin(angle+a+WM_PI)*d;
648 points[4].x = cx+cos(angle-a)*d;
649 points[4].y = cy+sin(angle-a)*d;
650 XGrabServer(dpy);
651 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
652 XFlush(dpy);
653 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
654 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
655 #endif
657 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
658 XUngrabServer(dpy);
659 cx+=xstep;
660 cy+=ystep;
661 cw+=wstep;
662 ch+=hstep;
663 if (angle >= final_angle)
664 break;
667 XFlush(dpy);
669 #undef FRAMES
672 static void
673 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
674 int fx, int fy, int fw, int fh, int steps)
676 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
677 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
678 float xstep, ystep, wstep, hstep;
679 int i, j;
681 xstep = (float)(fx-x)/steps;
682 ystep = (float)(fy-y)/steps;
683 wstep = (float)(fw-w)/steps;
684 hstep = (float)(fh-h)/steps;
686 for (j=0; j<FRAMES; j++) {
687 cx[j] = (float)x;
688 cy[j] = (float)y;
689 cw[j] = (float)w;
690 ch[j] = (float)h;
692 XGrabServer(dpy);
693 for (i=0; i<steps; i++) {
694 for (j=0; j<FRAMES; j++) {
695 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
696 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
698 XFlush(dpy);
699 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
700 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
701 #endif
702 for (j=0; j<FRAMES; j++) {
703 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
704 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
705 if (j<FRAMES-1) {
706 cx[j]=cx[j+1];
707 cy[j]=cy[j+1];
708 cw[j]=cw[j+1];
709 ch[j]=ch[j+1];
710 } else {
711 cx[j]+=xstep;
712 cy[j]+=ystep;
713 cw[j]+=wstep;
714 ch[j]+=hstep;
719 for (j=0; j<FRAMES; j++) {
720 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
721 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
723 XFlush(dpy);
724 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
725 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
726 #endif
727 for (j=0; j<FRAMES; j++) {
728 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
729 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
732 XUngrabServer(dpy);
734 #undef FRAMES
737 static void
738 animateResize(WScreen *scr, int x, int y, int w, int h,
739 int fx, int fy, int fw, int fh, int hiding)
741 int style = wPreferences.iconification_style; /* Catch the value */
742 int steps, k;
744 if (style == WIS_NONE)
745 return;
747 if (style == WIS_RANDOM) {
748 style = rand()%3;
751 k = (hiding ? 2 : 3);
752 switch(style) {
753 case WIS_TWIST:
754 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
755 if (steps>0)
756 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
757 break;
758 case WIS_FLIP:
759 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
760 if (steps>0)
761 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
762 break;
763 case WIS_ZOOM:
764 default:
765 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
766 if (steps>0)
767 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
768 break;
771 #endif /* ANIMATIONS */
774 static void
775 flushExpose()
777 XEvent tmpev;
779 while (XCheckTypedEvent(dpy, Expose, &tmpev))
780 WMHandleEvent(&tmpev);
781 XSync(dpy, 0);
784 static void
785 unmapTransientsFor(WWindow *wwin)
787 WWindow *tmp;
790 tmp = wwin->screen_ptr->focused_window;
791 while (tmp) {
792 /* unmap the transients for this transient */
793 if (tmp!=wwin && tmp->transient_for == wwin->client_win
794 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
795 || tmp->flags.shaded)) {
796 unmapTransientsFor(tmp);
797 tmp->flags.miniaturized = 1;
798 if (!tmp->flags.shaded) {
799 wWindowUnmap(tmp);
800 } else {
801 XUnmapWindow(dpy, tmp->frame->core->window);
804 if (!tmp->flags.shaded)
806 wClientSetState(tmp, IconicState, None);
807 #ifdef KWM_HINTS
808 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
809 wKWMSendEventMessage(tmp, WKWMRemoveWindow);
810 tmp->flags.kwm_hidden_for_modules = 1;
811 #endif
813 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
816 tmp = tmp->prev;
821 static void
822 mapTransientsFor(WWindow *wwin)
824 WWindow *tmp;
826 tmp = wwin->screen_ptr->focused_window;
827 while (tmp) {
828 /* recursively map the transients for this transient */
829 if (tmp!=wwin && tmp->transient_for == wwin->client_win
830 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
831 && tmp->icon==NULL) {
832 mapTransientsFor(tmp);
833 tmp->flags.miniaturized = 0;
834 if (!tmp->flags.shaded) {
835 wWindowMap(tmp);
836 } else {
837 XMapWindow(dpy, tmp->frame->core->window);
839 tmp->flags.semi_focused = 0;
841 if (!tmp->flags.shaded)
843 wClientSetState(tmp, NormalState, None);
844 #ifdef KWM_HINTS
845 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
846 if (tmp->flags.kwm_hidden_for_modules) {
847 wKWMSendEventMessage(tmp, WKWMAddWindow);
848 tmp->flags.kwm_hidden_for_modules = 0;
850 #endif
852 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
855 tmp = tmp->prev;
859 #if 0
860 static void
861 setupIconGrabs(WIcon *icon)
863 /* setup passive grabs on the icon */
864 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
865 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
866 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
867 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
868 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
869 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
870 XSync(dpy, 0);
872 #endif
874 static WWindow*
875 recursiveTransientFor(WWindow *wwin)
877 int i;
879 if (!wwin)
880 return None;
882 /* hackish way to detect transient_for cycle */
883 i = wwin->screen_ptr->window_count+1;
885 while (wwin && wwin->transient_for != None && i>0) {
886 wwin = wWindowFor(wwin->transient_for);
887 i--;
889 if (i==0 && wwin) {
890 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
891 wwin->frame->title);
892 return NULL;
895 return wwin;
898 #if 0
899 static void
900 removeIconGrabs(WIcon *icon)
902 /* remove passive grabs on the icon */
903 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
904 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
905 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
906 XSync(dpy, 0);
908 #endif
911 void
912 wIconifyWindow(WWindow *wwin)
914 XWindowAttributes attribs;
915 int present;
918 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
919 /* the window doesn't exist anymore */
920 return;
923 if (wwin->flags.miniaturized) {
924 return;
928 if (wwin->transient_for!=None) {
929 WWindow *owner = wWindowFor(wwin->transient_for);
931 if (owner && owner->flags.miniaturized)
932 return;
935 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
937 /* if the window is in another workspace, simplify process */
938 if (present) {
939 /* icon creation may take a while */
940 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
941 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
942 GrabModeAsync, None, None, CurrentTime);
945 if (!wPreferences.disable_miniwindows) {
946 if (!wwin->flags.icon_moved) {
947 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y);
949 wwin->icon = wIconCreate(wwin);
951 wwin->icon->mapped = 1;
954 wwin->flags.miniaturized = 1;
955 wwin->flags.mapped = 0;
957 /* unmap transients */
959 unmapTransientsFor(wwin);
961 if (present) {
962 wSoundPlay(WSOUND_ICONIFY);
964 XUngrabPointer(dpy, CurrentTime);
965 wWindowUnmap(wwin);
966 /* let all Expose events arrive so that we can repaint
967 * something before the animation starts (and the server is grabbed) */
968 XSync(dpy, 0);
970 if (wPreferences.disable_miniwindows)
971 wClientSetState(wwin, IconicState, None);
972 else
973 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
975 flushExpose();
976 #ifdef ANIMATIONS
977 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
978 && !wPreferences.no_animations) {
979 int ix, iy, iw, ih;
981 if (!wPreferences.disable_miniwindows) {
982 ix = wwin->icon_x;
983 iy = wwin->icon_y;
984 iw = wwin->icon->core->width;
985 ih = wwin->icon->core->height;
986 } else {
987 #ifdef KWM_HINTS
988 WArea area;
990 if (wKWMGetIconGeometry(wwin, &area)) {
991 ix = area.x1;
992 iy = area.y1;
993 iw = area.x2 - ix;
994 ih = area.y2 - iy;
995 } else
996 #endif /* KWM_HINTS */
998 ix = 0;
999 iy = 0;
1000 iw = wwin->screen_ptr->scr_width;
1001 ih = wwin->screen_ptr->scr_height;
1004 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1005 wwin->frame->core->width, wwin->frame->core->height,
1006 ix, iy, iw, ih, False);
1008 #endif
1011 wwin->flags.skip_next_animation = 0;
1013 if (!wPreferences.disable_miniwindows) {
1015 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
1016 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1018 XMapWindow(dpy, wwin->icon->core->window);
1020 AddToStackList(wwin->icon->core);
1022 wLowerFrame(wwin->icon->core);
1025 if (present) {
1026 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1029 * It doesn't seem to be working and causes button event hangup
1030 * when deiconifying a transient window.
1031 setupIconGrabs(wwin->icon);
1033 if ((wwin->flags.focused
1034 || (owner && wwin->client_win == owner->client_win))
1035 && wPreferences.focus_mode==WKF_CLICK) {
1036 WWindow *tmp;
1038 tmp = wwin->prev;
1039 while (tmp) {
1040 if (!WFLAGP(tmp, no_focusable)
1041 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1042 && (wwin->frame->workspace == tmp->frame->workspace))
1043 break;
1044 tmp = tmp->prev;
1046 wSetFocusTo(wwin->screen_ptr, tmp);
1047 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1048 wSetFocusTo(wwin->screen_ptr, NULL);
1051 #ifdef ANIMATIONS
1052 if (!wwin->screen_ptr->flags.startup) {
1053 Window clientwin = wwin->client_win;
1055 XSync(dpy, 0);
1056 processEvents(XPending(dpy));
1058 /* the window can disappear while doing the processEvents() */
1059 if (!wWindowFor(clientwin))
1060 return;
1062 #endif
1066 if (wwin->flags.selected && !wPreferences.disable_miniwindows)
1067 wIconSelect(wwin->icon);
1069 #ifdef GNOME_STUFF
1070 wGNOMEUpdateClientStateHint(wwin, False);
1071 #endif
1072 #ifdef KWM_HINTS
1073 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1074 wKWMSendEventMessage(wwin, WKWMChangedClient);
1075 #endif
1077 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1083 void
1084 wDeiconifyWindow(WWindow *wwin)
1086 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1088 if (!wwin->flags.miniaturized)
1089 return;
1091 if (wwin->transient_for != None
1092 && wwin->transient_for != wwin->screen_ptr->root_win) {
1093 WWindow *owner = recursiveTransientFor(wwin);
1095 if (owner && owner->flags.miniaturized) {
1096 wDeiconifyWindow(owner);
1097 wSetFocusTo(wwin->screen_ptr, wwin);
1098 wRaiseFrame(wwin->frame->core);
1099 return;
1103 wwin->flags.miniaturized = 0;
1104 if (!wwin->flags.shaded)
1105 wwin->flags.mapped = 1;
1107 if (!wPreferences.disable_miniwindows) {
1108 if (wwin->icon->selected)
1109 wIconSelect(wwin->icon);
1111 XUnmapWindow(dpy, wwin->icon->core->window);
1114 wSoundPlay(WSOUND_DEICONIFY);
1116 /* if the window is in another workspace, do it silently */
1117 #ifdef ANIMATIONS
1118 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1119 && !wwin->flags.skip_next_animation) {
1120 int ix, iy, iw, ih;
1122 if (!wPreferences.disable_miniwindows) {
1123 ix = wwin->icon_x;
1124 iy = wwin->icon_y;
1125 iw = wwin->icon->core->width;
1126 ih = wwin->icon->core->height;
1127 } else {
1128 #ifdef KWM_HINTS
1129 WArea area;
1131 if (wKWMGetIconGeometry(wwin, &area)) {
1132 ix = area.x1;
1133 iy = area.y1;
1134 iw = area.x2 - ix;
1135 ih = area.y2 - iy;
1136 } else
1137 #endif /* KWM_HINTS */
1139 ix = 0;
1140 iy = 0;
1141 iw = wwin->screen_ptr->scr_width;
1142 ih = wwin->screen_ptr->scr_height;
1145 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1146 wwin->frame_x, wwin->frame_y,
1147 wwin->frame->core->width, wwin->frame->core->height,
1148 False);
1150 #endif /* ANIMATIONS */
1151 wwin->flags.skip_next_animation = 0;
1152 XGrabServer(dpy);
1153 if (!wwin->flags.shaded) {
1154 XMapWindow(dpy, wwin->client_win);
1156 XMapWindow(dpy, wwin->frame->core->window);
1157 wRaiseFrame(wwin->frame->core);
1158 if (!wwin->flags.shaded) {
1159 wClientSetState(wwin, NormalState, None);
1161 mapTransientsFor(wwin);
1163 if (!wPreferences.disable_miniwindows) {
1164 RemoveFromStackList(wwin->icon->core);
1165 /* removeIconGrabs(wwin->icon);*/
1166 wIconDestroy(wwin->icon);
1167 wwin->icon = NULL;
1169 XUngrabServer(dpy);
1171 if (wPreferences.focus_mode==WKF_CLICK)
1172 wSetFocusTo(wwin->screen_ptr, wwin);
1174 #ifdef ANIMATIONS
1175 if (!wwin->screen_ptr->flags.startup) {
1176 Window clientwin = wwin->client_win;
1178 XSync(dpy, 0);
1179 processEvents(XPending(dpy));
1181 if (!wWindowFor(clientwin))
1182 return;
1184 #endif
1186 if (wPreferences.auto_arrange_icons) {
1187 wArrangeIcons(wwin->screen_ptr, True);
1190 #ifdef GNOME_STUFF
1191 wGNOMEUpdateClientStateHint(wwin, False);
1192 #endif
1193 #ifdef KWM_HINTS
1194 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1195 wKWMSendEventMessage(wwin, WKWMChangedClient);
1196 #endif
1198 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1203 static void
1204 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1206 if (wwin->flags.miniaturized) {
1207 if (wwin->icon) {
1208 XUnmapWindow(dpy, wwin->icon->core->window);
1209 wwin->icon->mapped = 0;
1211 wwin->flags.hidden = 1;
1212 #ifdef GNOME_STUFF
1213 wGNOMEUpdateClientStateHint(wwin, False);
1214 #endif
1216 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1218 return;
1221 if (wwin->flags.inspector_open) {
1222 wHideInspectorForWindow(wwin);
1225 wwin->flags.hidden = 1;
1226 wWindowUnmap(wwin);
1228 wClientSetState(wwin, IconicState, icon->icon_win);
1229 flushExpose();
1230 wSoundPlay(WSOUND_HIDE);
1231 #ifdef ANIMATIONS
1232 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1233 !wwin->flags.skip_next_animation && animate) {
1234 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1235 wwin->frame->core->width, wwin->frame->core->height,
1236 icon_x, icon_y, icon->core->width, icon->core->height,
1237 True);
1239 #endif
1240 wwin->flags.skip_next_animation = 0;
1242 #ifdef GNOME_STUFF
1243 wGNOMEUpdateClientStateHint(wwin, False);
1244 #endif
1246 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1251 void
1252 wHideOtherApplications(WWindow *awin)
1254 WWindow *wwin;
1255 WApplication *tapp;
1257 if (!awin)
1258 return;
1259 wwin = awin->screen_ptr->focused_window;
1262 while (wwin) {
1263 if (wwin!=awin
1264 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1265 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1266 && !wwin->flags.internal_window
1267 && wGetWindowOfInspectorForWindow(wwin) != awin
1268 && !WFLAGP(wwin, no_hide_others)) {
1270 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1271 if (!WFLAGP(wwin, no_miniaturizable)) {
1272 wwin->flags.skip_next_animation = 1;
1273 wIconifyWindow(wwin);
1275 } else if (wwin->main_window!=None
1276 && awin->main_window != wwin->main_window) {
1277 tapp = wApplicationOf(wwin->main_window);
1278 if (tapp) {
1279 tapp->flags.skip_next_animation = 1;
1280 wHideApplication(tapp);
1281 } else {
1282 if (!WFLAGP(wwin, no_miniaturizable)) {
1283 wwin->flags.skip_next_animation = 1;
1284 wIconifyWindow(wwin);
1289 wwin = wwin->prev;
1292 wSetFocusTo(awin->screen_ptr, awin);
1298 void
1299 wHideApplication(WApplication *wapp)
1301 WScreen *scr;
1302 WWindow *wlist;
1303 int hadfocus;
1305 if (!wapp) {
1306 wwarning("trying to hide a non grouped window");
1307 return;
1309 if (!wapp->main_window_desc) {
1310 wwarning("group leader not found for window group");
1311 return;
1313 scr = wapp->main_window_desc->screen_ptr;
1314 hadfocus = 0;
1315 wlist = scr->focused_window;
1316 if (!wlist)
1317 return;
1319 if (wlist->main_window == wapp->main_window)
1320 wapp->last_focused = wlist;
1321 else
1322 wapp->last_focused = NULL;
1323 while (wlist) {
1324 if (wlist->main_window == wapp->main_window) {
1325 if (wlist->flags.focused) {
1326 hadfocus = 1;
1328 if (wapp->app_icon)
1329 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1330 wapp->app_icon->y_pos, wlist,
1331 !wapp->flags.skip_next_animation);
1333 wlist = wlist->prev;
1336 wapp->flags.skip_next_animation = 0;
1338 if (hadfocus) {
1339 if (wPreferences.focus_mode==WKF_CLICK) {
1340 wlist = scr->focused_window;
1341 while (wlist) {
1342 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1343 && (wlist->flags.mapped || wlist->flags.shaded))
1344 break;
1345 wlist = wlist->prev;
1347 wSetFocusTo(scr, wlist);
1348 } else {
1349 wSetFocusTo(scr, NULL);
1353 wapp->flags.hidden = 1;
1355 if(wPreferences.auto_arrange_icons) {
1356 wArrangeIcons(scr, True);
1358 #ifdef HIDDENDOT
1359 if (wapp->app_icon)
1360 wAppIconPaint(wapp->app_icon);
1361 #endif
1367 static void
1368 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1369 int bringToCurrentWS)
1371 if (bringToCurrentWS)
1372 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1374 wwin->flags.hidden=0;
1375 wwin->flags.mapped=1;
1377 wSoundPlay(WSOUND_UNHIDE);
1378 #ifdef ANIMATIONS
1379 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1380 && animate) {
1381 animateResize(wwin->screen_ptr, icon_x, icon_y,
1382 icon->core->width, icon->core->height,
1383 wwin->frame_x, wwin->frame_y,
1384 wwin->frame->core->width, wwin->frame->core->height,
1385 True);
1387 #endif
1388 wwin->flags.skip_next_animation = 0;
1389 XMapWindow(dpy, wwin->client_win);
1390 XMapWindow(dpy, wwin->frame->core->window);
1391 wClientSetState(wwin, NormalState, None);
1392 wRaiseFrame(wwin->frame->core);
1393 if (wwin->flags.inspector_open) {
1394 wUnhideInspectorForWindow(wwin);
1397 #ifdef GNOME_STUFF
1398 wGNOMEUpdateClientStateHint(wwin, False);
1399 #endif
1401 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1406 void
1407 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1409 WScreen *scr;
1410 WWindow *wlist, *next;
1411 WWindow *focused=NULL;
1413 if (!wapp) {
1414 return;
1416 scr = wapp->main_window_desc->screen_ptr;
1417 wlist = scr->focused_window;
1418 if (!wlist) return;
1419 /* goto beginning of list */
1420 while (wlist->prev)
1421 wlist = wlist->prev;
1423 while (wlist) {
1424 next = wlist->next;
1426 if (wlist->main_window == wapp->main_window) {
1427 if (wlist->flags.focused)
1428 focused = wlist;
1429 else if (!focused || !focused->flags.focused)
1430 focused = wlist;
1432 if (wlist->flags.miniaturized && wlist->icon) {
1433 if (bringToCurrentWS || wPreferences.sticky_icons
1434 || wlist->frame->workspace == scr->current_workspace) {
1435 if (!wlist->icon->mapped) {
1436 XMapWindow(dpy, wlist->icon->core->window);
1437 wlist->icon->mapped = 1;
1439 wlist->flags.hidden = 0;
1441 UpdateSwitchMenu(scr, wlist, ACTION_CHANGE_STATE);
1443 if (wlist->frame->workspace != scr->current_workspace)
1444 wWindowChangeWorkspace(wlist, scr->current_workspace);
1446 if (miniwindows) {
1447 wDeiconifyWindow(wlist);
1449 } else if (wlist->flags.hidden) {
1450 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1451 wapp->app_icon->y_pos, wlist,
1452 !wapp->flags.skip_next_animation,
1453 bringToCurrentWS);
1454 } else {
1455 if (bringToCurrentWS
1456 && wlist->frame->workspace != scr->current_workspace) {
1457 wWindowChangeWorkspace(wlist, scr->current_workspace);
1459 wRaiseFrame(wlist->frame->core);
1462 wlist = next;
1465 wapp->flags.skip_next_animation = 0;
1466 wapp->flags.hidden = 0;
1468 if (focused)
1469 wSetFocusTo(scr, focused);
1470 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1471 wSetFocusTo(scr, wapp->last_focused);
1472 wapp->last_focused = NULL;
1473 if (wPreferences.auto_arrange_icons) {
1474 wArrangeIcons(scr, True);
1476 #ifdef HIDDENDOT
1477 wAppIconPaint(wapp->app_icon);
1478 #endif
1483 void
1484 wShowAllWindows(WScreen *scr)
1486 WWindow *wwin, *old_foc;
1487 WApplication *wapp;
1489 old_foc = wwin = scr->focused_window;
1490 while (wwin) {
1491 if (!wwin->flags.internal_window &&
1492 (scr->current_workspace == wwin->frame->workspace
1493 || IS_OMNIPRESENT(wwin))) {
1494 if (wwin->flags.miniaturized) {
1495 wwin->flags.skip_next_animation = 1;
1496 wDeiconifyWindow(wwin);
1497 } else if (wwin->flags.hidden) {
1498 wapp = wApplicationOf(wwin->main_window);
1499 if (wapp) {
1500 wUnhideApplication(wapp, False, False);
1501 } else {
1502 wwin->flags.skip_next_animation = 1;
1503 wDeiconifyWindow(wwin);
1507 wwin = wwin->prev;
1509 wSetFocusTo(scr, old_foc);
1510 /*wRaiseFrame(old_foc->frame->core);*/
1514 void
1515 wRefreshDesktop(WScreen *scr)
1517 Window win;
1518 XSetWindowAttributes attr;
1520 attr.backing_store = NotUseful;
1521 attr.save_under = False;
1522 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1523 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1524 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1525 &attr);
1526 XMapRaised(dpy, win);
1527 XDestroyWindow(dpy, win);
1528 XFlush(dpy);
1532 void
1533 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1535 WWindow *wwin;
1536 WAppIcon *aicon;
1537 int pf; /* primary axis */
1538 int sf; /* secondary axis */
1539 int fullW;
1540 int fullH;
1541 int pi, si;
1542 int sx1, sx2, sy1, sy2; /* screen boundary */
1543 int sw, sh;
1544 int xo, yo;
1545 int xs, ys;
1546 int isize = wPreferences.icon_size;
1549 * Find out screen boundaries.
1551 sx1 = 0;
1552 sy1 = 0;
1553 sx2 = scr->scr_width;
1554 sy2 = scr->scr_height;
1555 if (scr->dock) {
1556 if (scr->dock->on_right_side)
1557 sx2 -= isize + DOCK_EXTRA_SPACE;
1558 else
1559 sx1 += isize + DOCK_EXTRA_SPACE;
1562 sw = isize * (scr->scr_width/isize);
1563 sh = isize * (scr->scr_height/isize);
1564 fullW = (sx2-sx1)/isize;
1565 fullH = (sy2-sy1)/isize;
1567 /* icon yard boundaries */
1568 if (wPreferences.icon_yard & IY_VERT) {
1569 pf = fullH;
1570 sf = fullW;
1571 } else {
1572 pf = fullW;
1573 sf = fullH;
1575 if (wPreferences.icon_yard & IY_RIGHT) {
1576 xo = sx2 - isize;
1577 xs = -1;
1578 } else {
1579 xo = sx1;
1580 xs = 1;
1582 if (wPreferences.icon_yard & IY_TOP) {
1583 yo = sy1;
1584 ys = 1;
1585 } else {
1586 yo = sy2 - isize;
1587 ys = -1;
1590 /* arrange icons putting the most recently focused window
1591 * as the last icon */
1592 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1593 : xo + xs*(pi*isize))
1594 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1595 : yo + ys*(si*isize))
1597 /* arrange application icons */
1598 aicon = scr->app_icon_list;
1599 /* reverse them to avoid unnecessarily sliding of icons */
1600 while (aicon && aicon->next)
1601 aicon = aicon->next;
1603 pi = 0;
1604 si = 0;
1605 while (aicon) {
1606 if (!aicon->docked && wAppIconIsFirstInstance(aicon)) {
1607 if (aicon->x_pos != X || aicon->y_pos != Y) {
1608 #ifdef ANIMATIONS
1609 if (!wPreferences.no_animations) {
1610 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1611 X, Y);
1613 #endif /* ANIMATIONS */
1615 wAppIconMove(aicon, X, Y);
1616 pi++;
1618 /* we reversed the order so we use prev */
1619 aicon = aicon->prev;
1620 if (pi >= pf) {
1621 pi=0;
1622 si++;
1626 /* arrange miniwindows */
1628 wwin = scr->focused_window;
1629 /* reverse them to avoid unnecessarily shuffling */
1630 while (wwin && wwin->prev)
1631 wwin = wwin->prev;
1633 while (wwin) {
1634 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1635 (wwin->frame->workspace==scr->current_workspace ||
1636 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1638 if (arrangeAll || !wwin->flags.icon_moved) {
1639 if (wwin->icon_x != X || wwin->icon_y != Y) {
1640 #ifdef ANIMATIONS
1641 if (wPreferences.no_animations) {
1642 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1643 } else {
1644 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1645 wwin->icon_y, X, Y);
1647 #else
1648 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1649 #endif /* ANIMATIONS */
1651 wwin->icon_x = X;
1652 wwin->icon_y = Y;
1653 pi++;
1656 if (arrangeAll) {
1657 wwin->flags.icon_moved = 0;
1659 /* we reversed the order, so we use next */
1660 wwin = wwin->next;
1661 if (pi >= pf) {
1662 pi=0;
1663 si++;
1669 void
1670 wSelectWindow(WWindow *wwin, Bool flag)
1672 WScreen *scr = wwin->screen_ptr;
1674 if (flag) {
1675 wwin->flags.selected = 1;
1676 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1678 if (WFLAGP(wwin, no_border)) {
1679 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1680 FRAME_BORDER_WIDTH);
1683 if (!scr->selected_windows)
1684 scr->selected_windows = WMCreateArray(4);
1685 WMAddToArray(scr->selected_windows, wwin);
1686 } else {
1687 wwin->flags.selected = 0;
1688 XSetWindowBorder(dpy, wwin->frame->core->window,
1689 scr->frame_border_pixel);
1691 if (WFLAGP(wwin, no_border)) {
1692 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1695 if (scr->selected_windows) {
1696 WMRemoveFromArray(scr->selected_windows, wwin);
1702 void
1703 wMakeWindowVisible(WWindow *wwin)
1705 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1706 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1708 if (wwin->flags.shaded) {
1709 wUnshadeWindow(wwin);
1711 if (wwin->flags.hidden) {
1712 WApplication *app;
1714 app = wApplicationOf(wwin->main_window);
1715 if (app)
1716 wUnhideApplication(app, False, False);
1717 } else if (wwin->flags.miniaturized) {
1718 wDeiconifyWindow(wwin);
1719 } else {
1720 if (!WFLAGP(wwin, no_focusable))
1721 wSetFocusTo(wwin->screen_ptr, wwin);
1722 wRaiseFrame(wwin->frame->core);