bug fix for balloons and some other minor things
[wmaker-crm.git] / src / actions.c
blobf8cfb6432f552663610a02164cfb6e6c77e3e941
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 * 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 "list.h"
50 #include "workspace.h"
52 #ifdef GNOME_STUFF
53 # include "gnome.h"
54 #endif
55 #ifdef KWM_HINTS
56 # include "kwm.h"
57 #endif
59 #ifdef WMSOUND
60 #include "wmsound.h"
61 #endif
64 /****** Global Variables ******/
65 extern Time LastTimestamp;
66 extern Time LastFocusChange;
68 extern Cursor wCursor[WCUR_LAST];
70 extern WPreferences wPreferences;
72 extern Atom _XA_WM_TAKE_FOCUS;
75 /******* Local Variables *******/
76 static struct {
77 int steps;
78 int delay;
79 } shadePars[5] = {
80 {SHADE_STEPS_UF, SHADE_DELAY_UF},
81 {SHADE_STEPS_F, SHADE_DELAY_F},
82 {SHADE_STEPS_M, SHADE_DELAY_M},
83 {SHADE_STEPS_S, SHADE_DELAY_S},
84 {SHADE_STEPS_U, SHADE_DELAY_U}};
86 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
87 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
90 static int ignoreTimestamp=0;
93 #ifdef ANIMATIONS
94 static void
95 processEvents(int event_count)
97 XEvent event;
100 * This is a hack. When animations are enabled, processing of
101 * events ocurred during a animation are delayed until it's end.
102 * Calls that consider the TimeStamp, like XSetInputFocus(), will
103 * fail because the TimeStamp is too old. Then, for example, if
104 * the user changes window focus while a miniaturize animation is
105 * in course, the window will not get focus properly after the end
106 * of the animation. This tries to workaround it by passing CurrentTime
107 * as the TimeStamp for XSetInputFocus() for all events ocurred during
108 * the animation.
110 ignoreTimestamp=1;
111 while (XPending(dpy) && event_count--) {
112 WMNextEvent(dpy, &event);
113 WMHandleEvent(&event);
115 ignoreTimestamp=0;
117 #endif /* ANIMATIONS */
122 *----------------------------------------------------------------------
123 * wSetFocusTo--
124 * Changes the window focus to the one passed as argument.
125 * If the window to focus is not already focused, it will be brought
126 * to the head of the list of windows. Previously focused window is
127 * unfocused.
129 * Side effects:
130 * Window list may be reordered and the window focus is changed.
132 *----------------------------------------------------------------------
134 void
135 wSetFocusTo(WScreen *scr, WWindow *wwin)
137 WWindow *focused=scr->focused_window;
138 int timestamp=LastTimestamp;
139 WApplication *oapp=NULL, *napp=NULL;
140 int wasfocused;
142 LastFocusChange = timestamp;
145 * This is a hack, because XSetInputFocus() should have a proper
146 * timestamp instead of CurrentTime but it seems that some times
147 * clients will not receive focus properly that way.
148 if (ignoreTimestamp)
150 timestamp = CurrentTime;
152 if (focused)
153 oapp = wApplicationOf(focused->main_window);
155 if (wwin == NULL) {
156 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
157 if (focused) {
158 wWindowUnfocus(focused);
160 if (oapp) {
161 wAppMenuUnmap(oapp->menu);
162 #ifdef NEWAPPICON
163 wApplicationDeactivate(oapp);
164 #endif
166 #ifdef KWM_HINTS
167 wKWMUpdateActiveWindowHint(scr);
168 wKWMSendEventMessage(NULL, WKWMFocusWindow);
169 #endif
170 return;
172 wasfocused = wwin->flags.focused;
173 napp = wApplicationOf(wwin->main_window);
175 /* remember last workspace where the app has been */
176 if (napp)
177 napp->last_workspace = wwin->screen_ptr->current_workspace;
179 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
180 /* install colormap if colormap mode is lock mode */
181 if (wPreferences.colormap_mode==WKF_CLICK)
182 wColormapInstallForWindow(scr, wwin);
184 /* set input focus */
185 switch (wwin->focus_mode) {
186 case WFM_NO_INPUT:
187 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
188 break;
190 case WFM_PASSIVE:
191 case WFM_LOCALLY_ACTIVE:
192 XSetInputFocus(dpy, wwin->client_win, RevertToParent, timestamp);
193 break;
195 case WFM_GLOBALLY_ACTIVE:
196 break;
198 XFlush(dpy);
199 if (wwin->protocols.TAKE_FOCUS) {
200 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
202 XSync(dpy, False);
203 } else {
204 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
206 if (WFLAGP(wwin, no_focusable))
207 return;
209 /* if this is not the focused window focus it */
210 if (focused!=wwin) {
211 /* change the focus window list order */
212 if (wwin->prev)
213 wwin->prev->next = wwin->next;
215 if (wwin->next)
216 wwin->next->prev = wwin->prev;
218 wwin->prev = focused;
219 focused->next = wwin;
220 wwin->next = NULL;
221 scr->focused_window = wwin;
223 if (oapp && oapp != napp) {
224 wAppMenuUnmap(oapp->menu);
225 #ifdef NEWAPPICON
226 wApplicationDeactivate(oapp);
227 #endif
231 wWindowFocus(wwin, focused);
233 if (napp && !wasfocused) {
234 #ifdef USER_MENU
235 wUserMenuRefreshInstances(napp->menu, wwin);
236 #endif /* USER_MENU */
238 wAppMenuMap(napp->menu, wwin);
239 #ifdef NEWAPPICON
240 wApplicationActivate(napp);
241 #endif
243 #ifdef KWM_HINTS
244 wKWMUpdateActiveWindowHint(scr);
245 wKWMSendEventMessage(wwin, WKWMFocusWindow);
246 #endif
247 XFlush(dpy);
251 void
252 wShadeWindow(WWindow *wwin)
254 time_t time0 = time(NULL);
255 #ifdef ANIMATIONS
256 int y, s, w, h;
257 #endif
259 if (wwin->flags.shaded)
260 return;
262 XLowerWindow(dpy, wwin->client_win);
264 #ifdef WMSOUND
265 wSoundPlay(WMSOUND_SHADE);
266 #endif
268 #ifdef ANIMATIONS
269 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
270 && !wPreferences.no_animations) {
271 /* do the shading animation */
272 h = wwin->frame->core->height;
273 s = h/SHADE_STEPS;
274 if (s < 1) s=1;
275 w = wwin->frame->core->width;
276 y = wwin->frame->top_width;
277 while (h>wwin->frame->top_width+1) {
278 XMoveWindow(dpy, wwin->client_win, 0, y);
279 XResizeWindow(dpy, wwin->frame->core->window, w, h);
280 XFlush(dpy);
282 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
283 break;
285 if (SHADE_DELAY > 0)
286 wusleep(SHADE_DELAY*1000L);
287 h-=s;
288 y-=s;
290 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
292 #endif /* ANIMATIONS */
294 wwin->flags.skip_next_animation = 0;
295 wwin->flags.shaded = 1;
296 wwin->flags.mapped = 0;
297 /* prevent window withdrawal when getting UnmapNotify */
298 XSelectInput(dpy, wwin->client_win,
299 wwin->event_mask & ~StructureNotifyMask);
300 XUnmapWindow(dpy, wwin->client_win);
301 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
303 /* for the client it's just like iconification */
304 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
305 wwin->frame->top_width - 1);
307 wwin->client.y = wwin->frame_y - wwin->client.height
308 + wwin->frame->top_width;
309 wWindowSynthConfigureNotify(wwin);
312 wClientSetState(wwin, IconicState, None);
315 #ifdef GNOME_STUFF
316 wGNOMEUpdateClientStateHint(wwin, False);
317 #endif
318 #ifdef KWM_HINTS
319 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
320 wKWMSendEventMessage(wwin, WKWMChangedClient);
321 #endif
322 /* update window list to reflect shaded state */
323 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
325 #ifdef ANIMATIONS
326 if (!wwin->screen_ptr->flags.startup) {
327 /* Look at processEvents() for reason of this code. */
328 XSync(dpy, 0);
329 processEvents(XPending(dpy));
331 #endif
335 void
336 wUnshadeWindow(WWindow *wwin)
338 time_t time0 = time(NULL);
339 #ifdef ANIMATIONS
340 int y, s, w, h;
341 #endif /* ANIMATIONS */
344 if (!wwin->flags.shaded)
345 return;
347 wwin->flags.shaded = 0;
348 wwin->flags.mapped = 1;
349 XMapWindow(dpy, wwin->client_win);
351 #ifdef WMSOUND
352 wSoundPlay(WMSOUND_UNSHADE);
353 #endif
355 #ifdef ANIMATIONS
356 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
357 /* do the shading animation */
358 h = wwin->frame->top_width + wwin->frame->bottom_width;
359 y = wwin->frame->top_width - wwin->client.height;
360 s = abs(y)/SHADE_STEPS;
361 if (s<1) s=1;
362 w = wwin->frame->core->width;
363 XMoveWindow(dpy, wwin->client_win, 0, y);
364 if (s>0) {
365 while (h < wwin->client.height + wwin->frame->top_width
366 + wwin->frame->bottom_width) {
367 XResizeWindow(dpy, wwin->frame->core->window, w, h);
368 XMoveWindow(dpy, wwin->client_win, 0, y);
369 XSync(dpy, 0);
370 if (SHADE_DELAY > 0)
371 wusleep(SHADE_DELAY*2000L/3);
372 h+=s;
373 y+=s;
375 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
376 break;
379 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
381 #endif /* ANIMATIONS */
383 wwin->flags.skip_next_animation = 0;
384 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
385 wwin->frame->top_width + wwin->client.height
386 + wwin->frame->bottom_width);
388 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
389 wWindowSynthConfigureNotify(wwin);
392 wClientSetState(wwin, NormalState, None);
394 /* if the window is focused, set the focus again as it was disabled during
395 * shading */
396 if (wwin->flags.focused)
397 wSetFocusTo(wwin->screen_ptr, wwin);
399 #ifdef GNOME_STUFF
400 wGNOMEUpdateClientStateHint(wwin, False);
401 #endif
402 #ifdef KWM_HINTS
403 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
404 wKWMSendEventMessage(wwin, WKWMChangedClient);
405 #endif
407 /* update window list to reflect unshaded state */
408 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
413 void
414 wMaximizeWindow(WWindow *wwin, int directions)
416 int new_width, new_height, new_x, new_y;
417 WArea usableArea = wwin->screen_ptr->totalUsableArea;
420 if (WFLAGP(wwin, no_resizable))
421 return;
424 if (WFLAGP(wwin, full_maximize)) {
425 usableArea.x1 = 0;
426 usableArea.y1 = 0;
427 usableArea.x2 = wwin->screen_ptr->scr_width;
428 usableArea.y2 = wwin->screen_ptr->scr_height;
431 if (wwin->flags.shaded) {
432 wwin->flags.skip_next_animation = 1;
433 wUnshadeWindow(wwin);
435 wwin->flags.maximized = directions;
436 wwin->old_geometry.width = wwin->client.width;
437 wwin->old_geometry.height = wwin->client.height;
438 wwin->old_geometry.x = wwin->frame_x;
439 wwin->old_geometry.y = wwin->frame_y;
441 #ifdef KWM_HINTS
442 wKWMUpdateClientGeometryRestore(wwin);
443 #endif
445 if (directions & MAX_HORIZONTAL) {
447 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
448 new_x = usableArea.x1;
450 } else {
452 new_x = wwin->frame_x;
453 new_width = wwin->frame->core->width;
457 if (directions & MAX_VERTICAL) {
459 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
460 new_y = usableArea.y1;
461 if (WFLAGP(wwin, full_maximize))
462 new_y -= wwin->frame->top_width;
464 } else {
466 new_y = wwin->frame_y;
467 new_height = wwin->frame->core->height;
471 if (!WFLAGP(wwin, full_maximize)) {
472 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
475 wWindowConstrainSize(wwin, &new_width, &new_height);
476 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
478 #ifdef GNOME_STUFF
479 wGNOMEUpdateClientStateHint(wwin, False);
480 #endif
481 #ifdef KWM_HINTS
482 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
483 wKWMSendEventMessage(wwin, WKWMChangedClient);
484 #endif
486 #ifdef WMSOUND
487 wSoundPlay(WMSOUND_MAXIMIZE);
488 #endif
492 void
493 wUnmaximizeWindow(WWindow *wwin)
495 int restore_x, restore_y;
497 if (!wwin->flags.maximized)
498 return;
500 if (wwin->flags.shaded) {
501 wwin->flags.skip_next_animation = 1;
502 wUnshadeWindow(wwin);
504 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
505 wwin->old_geometry.x : wwin->frame_x;
506 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
507 wwin->old_geometry.y : wwin->frame_y;
508 wwin->flags.maximized = 0;
509 wWindowConfigure(wwin, restore_x, restore_y,
510 wwin->old_geometry.width, wwin->old_geometry.height);
512 #ifdef GNOME_STUFF
513 wGNOMEUpdateClientStateHint(wwin, False);
514 #endif
515 #ifdef KWM_HINTS
516 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
517 wKWMSendEventMessage(wwin, WKWMChangedClient);
518 #endif
520 #ifdef WMSOUND
521 wSoundPlay(WMSOUND_UNMAXIMIZE);
522 #endif
525 #ifdef ANIMATIONS
526 static void
527 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
528 int fx, int fy, int fw, int fh, int steps)
530 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
531 float cx, cy, cw, ch;
532 float xstep, ystep, wstep, hstep;
533 XPoint points[5];
534 float dx, dch, midy;
535 float angle, final_angle, delta;
537 xstep = (float)(fx-x)/steps;
538 ystep = (float)(fy-y)/steps;
539 wstep = (float)(fw-w)/steps;
540 hstep = (float)(fh-h)/steps;
542 cx = (float)x;
543 cy = (float)y;
544 cw = (float)w;
545 ch = (float)h;
547 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
548 delta = (float)(final_angle/FRAMES);
549 for (angle=0;; angle+=delta) {
550 if (angle > final_angle)
551 angle = final_angle;
553 dx = (cw/10) - ((cw/5) * sin(angle));
554 dch = (ch/2) * cos(angle);
555 midy = cy + (ch/2);
557 points[0].x = cx + dx; points[0].y = midy - dch;
558 points[1].x = cx + cw - dx; points[1].y = points[0].y;
559 points[2].x = cx + cw + dx; points[2].y = midy + dch;
560 points[3].x = cx - dx; points[3].y = points[2].y;
561 points[4].x = points[0].x; points[4].y = points[0].y;
563 XGrabServer(dpy);
564 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
565 XFlush(dpy);
566 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
567 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
568 #endif
570 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
571 XUngrabServer(dpy);
572 cx+=xstep;
573 cy+=ystep;
574 cw+=wstep;
575 ch+=hstep;
576 if (angle >= final_angle)
577 break;
580 XFlush(dpy);
582 #undef FRAMES
585 static void
586 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
587 int fx, int fy, int fw, int fh, int steps)
589 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
590 float cx, cy, cw, ch;
591 float xstep, ystep, wstep, hstep;
592 XPoint points[5];
593 float angle, final_angle, a, d, delta;
595 x += w/2;
596 y += h/2;
597 fx += fw/2;
598 fy += fh/2;
600 xstep = (float)(fx-x)/steps;
601 ystep = (float)(fy-y)/steps;
602 wstep = (float)(fw-w)/steps;
603 hstep = (float)(fh-h)/steps;
605 cx = (float)x;
606 cy = (float)y;
607 cw = (float)w;
608 ch = (float)h;
610 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
611 delta = (float)(final_angle/FRAMES);
612 for (angle=0;; angle+=delta) {
613 if (angle > final_angle)
614 angle = final_angle;
616 a = atan(ch/cw);
617 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
619 points[0].x = cx+cos(angle-a)*d;
620 points[0].y = cy+sin(angle-a)*d;
621 points[1].x = cx+cos(angle+a)*d;
622 points[1].y = cy+sin(angle+a)*d;
623 points[2].x = cx+cos(angle-a+WM_PI)*d;
624 points[2].y = cy+sin(angle-a+WM_PI)*d;
625 points[3].x = cx+cos(angle+a+WM_PI)*d;
626 points[3].y = cy+sin(angle+a+WM_PI)*d;
627 points[4].x = cx+cos(angle-a)*d;
628 points[4].y = cy+sin(angle-a)*d;
629 XGrabServer(dpy);
630 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
631 XFlush(dpy);
632 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
633 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
634 #endif
636 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
637 XUngrabServer(dpy);
638 cx+=xstep;
639 cy+=ystep;
640 cw+=wstep;
641 ch+=hstep;
642 if (angle >= final_angle)
643 break;
646 XFlush(dpy);
648 #undef FRAMES
651 static void
652 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
653 int fx, int fy, int fw, int fh, int steps)
655 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
656 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
657 float xstep, ystep, wstep, hstep;
658 int i, j;
660 xstep = (float)(fx-x)/steps;
661 ystep = (float)(fy-y)/steps;
662 wstep = (float)(fw-w)/steps;
663 hstep = (float)(fh-h)/steps;
665 for (j=0; j<FRAMES; j++) {
666 cx[j] = (float)x;
667 cy[j] = (float)y;
668 cw[j] = (float)w;
669 ch[j] = (float)h;
671 XGrabServer(dpy);
672 for (i=0; i<steps; i++) {
673 for (j=0; j<FRAMES; j++) {
674 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
675 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
677 XFlush(dpy);
678 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
679 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
680 #endif
681 for (j=0; j<FRAMES; j++) {
682 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
683 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
684 if (j<FRAMES-1) {
685 cx[j]=cx[j+1];
686 cy[j]=cy[j+1];
687 cw[j]=cw[j+1];
688 ch[j]=ch[j+1];
689 } else {
690 cx[j]+=xstep;
691 cy[j]+=ystep;
692 cw[j]+=wstep;
693 ch[j]+=hstep;
698 for (j=0; j<FRAMES; j++) {
699 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
700 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
702 XFlush(dpy);
703 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
704 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
705 #endif
706 for (j=0; j<FRAMES; j++) {
707 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
708 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
711 XUngrabServer(dpy);
713 #undef FRAMES
716 static void
717 animateResize(WScreen *scr, int x, int y, int w, int h,
718 int fx, int fy, int fw, int fh, int hiding)
720 int style = wPreferences.iconification_style; /* Catch the value */
721 int steps, k;
723 if (style == WIS_NONE)
724 return;
726 if (style == WIS_RANDOM) {
727 style = rand()%3;
730 k = (hiding ? 2 : 3);
731 switch(style) {
732 case WIS_TWIST:
733 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
734 if (steps>0)
735 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
736 break;
737 case WIS_FLIP:
738 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
739 if (steps>0)
740 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
741 break;
742 case WIS_ZOOM:
743 default:
744 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
745 if (steps>0)
746 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
747 break;
750 #endif /* ANIMATIONS */
753 static void
754 flushExpose()
756 XEvent tmpev;
758 while (XCheckTypedEvent(dpy, Expose, &tmpev))
759 WMHandleEvent(&tmpev);
760 XSync(dpy, 0);
763 static void
764 unmapTransientsFor(WWindow *wwin)
766 WWindow *tmp;
769 tmp = wwin->screen_ptr->focused_window;
770 while (tmp) {
771 /* unmap the transients for this transient */
772 if (tmp!=wwin && tmp->transient_for == wwin->client_win
773 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
774 || tmp->flags.shaded)) {
775 unmapTransientsFor(tmp);
776 tmp->flags.miniaturized = 1;
777 if (!tmp->flags.shaded) {
778 wWindowUnmap(tmp);
779 } else {
780 XUnmapWindow(dpy, tmp->frame->core->window);
783 if (!tmp->flags.shaded)
785 wClientSetState(tmp, IconicState, None);
786 #ifdef KWM_HINTS
787 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
788 wKWMSendEventMessage(tmp, WKWMRemoveWindow);
789 tmp->flags.kwm_hidden_for_modules = 1;
790 #endif
792 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
795 tmp = tmp->prev;
800 static void
801 mapTransientsFor(WWindow *wwin)
803 WWindow *tmp;
805 tmp = wwin->screen_ptr->focused_window;
806 while (tmp) {
807 /* recursively map the transients for this transient */
808 if (tmp!=wwin && tmp->transient_for == wwin->client_win
809 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
810 && tmp->icon==NULL) {
811 mapTransientsFor(tmp);
812 tmp->flags.miniaturized = 0;
813 if (!tmp->flags.shaded) {
814 wWindowMap(tmp);
815 } else {
816 XMapWindow(dpy, tmp->frame->core->window);
818 tmp->flags.semi_focused = 0;
820 if (!tmp->flags.shaded)
822 wClientSetState(tmp, NormalState, None);
823 #ifdef KWM_HINTS
824 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
825 if (tmp->flags.kwm_hidden_for_modules) {
826 wKWMSendEventMessage(tmp, WKWMAddWindow);
827 tmp->flags.kwm_hidden_for_modules = 0;
829 #endif
831 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
834 tmp = tmp->prev;
838 #if 0
839 static void
840 setupIconGrabs(WIcon *icon)
842 /* setup passive grabs on the icon */
843 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
844 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
845 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
846 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
847 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
848 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
849 XSync(dpy, 0);
851 #endif
853 static WWindow*
854 recursiveTransientFor(WWindow *wwin)
856 int i;
858 if (!wwin)
859 return None;
861 /* hackish way to detect transient_for cycle */
862 i = wwin->screen_ptr->window_count+1;
864 while (wwin && wwin->transient_for != None && i>0) {
865 wwin = wWindowFor(wwin->transient_for);
866 i--;
868 if (i==0 && wwin) {
869 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
870 wwin->frame->title);
871 return NULL;
874 return wwin;
877 #if 0
878 static void
879 removeIconGrabs(WIcon *icon)
881 /* remove passive grabs on the icon */
882 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
883 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
884 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
885 XSync(dpy, 0);
887 #endif
890 void
891 wIconifyWindow(WWindow *wwin)
893 XWindowAttributes attribs;
894 int present;
897 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
898 /* the window doesn't exist anymore */
899 return;
902 if (wwin->flags.miniaturized) {
903 return;
907 if (wwin->transient_for!=None) {
908 WWindow *owner = wWindowFor(wwin->transient_for);
910 if (owner && owner->flags.miniaturized)
911 return;
914 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
916 /* if the window is in another workspace, simplify process */
917 if (present) {
918 /* icon creation may take a while */
919 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
920 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
921 GrabModeAsync, None, None, CurrentTime);
924 if (!wPreferences.disable_miniwindows) {
925 if (!wwin->flags.icon_moved) {
926 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y);
928 wwin->icon = wIconCreate(wwin);
930 wwin->icon->mapped = 1;
933 wwin->flags.miniaturized = 1;
934 wwin->flags.mapped = 0;
936 /* unmap transients */
938 unmapTransientsFor(wwin);
940 if (present) {
941 #ifdef WMSOUND
942 wSoundPlay(WMSOUND_ICONIFY);
943 #endif
945 XUngrabPointer(dpy, CurrentTime);
946 wWindowUnmap(wwin);
947 /* let all Expose events arrive so that we can repaint
948 * something before the animation starts (and the server is grabbed) */
949 XSync(dpy, 0);
951 if (wPreferences.disable_miniwindows)
952 wClientSetState(wwin, IconicState, None);
953 else
954 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
956 flushExpose();
957 #ifdef ANIMATIONS
958 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
959 && !wPreferences.no_animations) {
960 int ix, iy, iw, ih;
962 if (!wPreferences.disable_miniwindows) {
963 ix = wwin->icon_x;
964 iy = wwin->icon_y;
965 iw = wwin->icon->core->width;
966 ih = wwin->icon->core->height;
967 } else {
968 #ifdef KWM_HINTS
969 WArea area;
971 if (wKWMGetIconGeometry(wwin, &area)) {
972 ix = area.x1;
973 iy = area.y1;
974 iw = area.x2 - ix;
975 ih = area.y2 - iy;
976 } else
977 #endif /* KWM_HINTS */
979 ix = 0;
980 iy = 0;
981 iw = wwin->screen_ptr->scr_width;
982 ih = wwin->screen_ptr->scr_height;
985 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
986 wwin->frame->core->width, wwin->frame->core->height,
987 ix, iy, iw, ih, False);
989 #endif
992 wwin->flags.skip_next_animation = 0;
994 if (!wPreferences.disable_miniwindows) {
996 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
997 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
999 XMapWindow(dpy, wwin->icon->core->window);
1001 AddToStackList(wwin->icon->core);
1003 wLowerFrame(wwin->icon->core);
1006 if (present) {
1007 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1010 * It doesn't seem to be working and causes button event hangup
1011 * when deiconifying a transient window.
1012 setupIconGrabs(wwin->icon);
1014 if ((wwin->flags.focused
1015 || (owner && wwin->client_win == owner->client_win))
1016 && wPreferences.focus_mode==WKF_CLICK) {
1017 WWindow *tmp;
1019 tmp = wwin->prev;
1020 while (tmp) {
1021 if (!WFLAGP(tmp, no_focusable)
1022 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1023 && (wwin->frame->workspace == tmp->frame->workspace))
1024 break;
1025 tmp = tmp->prev;
1027 wSetFocusTo(wwin->screen_ptr, tmp);
1028 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1029 wSetFocusTo(wwin->screen_ptr, NULL);
1032 #ifdef ANIMATIONS
1033 if (!wwin->screen_ptr->flags.startup) {
1034 Window clientwin = wwin->client_win;
1036 XSync(dpy, 0);
1037 processEvents(XPending(dpy));
1039 /* the window can disappear while doing the processEvents() */
1040 if (!wWindowFor(clientwin))
1041 return;
1043 #endif
1047 if (wwin->flags.selected && !wPreferences.disable_miniwindows)
1048 wIconSelect(wwin->icon);
1050 #ifdef GNOME_STUFF
1051 wGNOMEUpdateClientStateHint(wwin, False);
1052 #endif
1053 #ifdef KWM_HINTS
1054 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1055 wKWMSendEventMessage(wwin, WKWMChangedClient);
1056 #endif
1058 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1064 void
1065 wDeiconifyWindow(WWindow *wwin)
1067 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1069 if (!wwin->flags.miniaturized)
1070 return;
1072 if (wwin->transient_for != None
1073 && wwin->transient_for != wwin->screen_ptr->root_win) {
1074 WWindow *owner = recursiveTransientFor(wwin);
1076 if (owner && owner->flags.miniaturized) {
1077 wDeiconifyWindow(owner);
1078 wSetFocusTo(wwin->screen_ptr, wwin);
1079 wRaiseFrame(wwin->frame->core);
1080 return;
1084 wwin->flags.miniaturized = 0;
1085 if (!wwin->flags.shaded)
1086 wwin->flags.mapped = 1;
1088 if (!wPreferences.disable_miniwindows) {
1089 if (wwin->icon->selected)
1090 wIconSelect(wwin->icon);
1092 XUnmapWindow(dpy, wwin->icon->core->window);
1095 #ifdef WMSOUND
1096 wSoundPlay(WMSOUND_DEICONIFY);
1097 #endif
1099 /* if the window is in another workspace, do it silently */
1100 #ifdef ANIMATIONS
1101 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1102 && !wwin->flags.skip_next_animation) {
1103 int ix, iy, iw, ih;
1105 if (!wPreferences.disable_miniwindows) {
1106 ix = wwin->icon_x;
1107 iy = wwin->icon_y;
1108 iw = wwin->icon->core->width;
1109 ih = wwin->icon->core->height;
1110 } else {
1111 #ifdef KWM_HINTS
1112 WArea area;
1114 if (wKWMGetIconGeometry(wwin, &area)) {
1115 ix = area.x1;
1116 iy = area.y1;
1117 iw = area.x2 - ix;
1118 ih = area.y2 - iy;
1119 } else
1120 #endif /* KWM_HINTS */
1122 ix = 0;
1123 iy = 0;
1124 iw = wwin->screen_ptr->scr_width;
1125 ih = wwin->screen_ptr->scr_height;
1128 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1129 wwin->frame_x, wwin->frame_y,
1130 wwin->frame->core->width, wwin->frame->core->height,
1131 False);
1133 #endif /* ANIMATIONS */
1134 wwin->flags.skip_next_animation = 0;
1135 XGrabServer(dpy);
1136 if (!wwin->flags.shaded) {
1137 XMapWindow(dpy, wwin->client_win);
1139 XMapWindow(dpy, wwin->frame->core->window);
1140 wRaiseFrame(wwin->frame->core);
1141 if (!wwin->flags.shaded) {
1142 wClientSetState(wwin, NormalState, None);
1144 mapTransientsFor(wwin);
1146 if (!wPreferences.disable_miniwindows) {
1147 RemoveFromStackList(wwin->icon->core);
1148 /* removeIconGrabs(wwin->icon);*/
1149 wIconDestroy(wwin->icon);
1150 wwin->icon = NULL;
1152 XUngrabServer(dpy);
1154 if (wPreferences.focus_mode==WKF_CLICK)
1155 wSetFocusTo(wwin->screen_ptr, wwin);
1157 #ifdef ANIMATIONS
1158 if (!wwin->screen_ptr->flags.startup) {
1159 Window clientwin = wwin->client_win;
1161 XSync(dpy, 0);
1162 processEvents(XPending(dpy));
1164 if (!wWindowFor(clientwin))
1165 return;
1167 #endif
1169 if (wPreferences.auto_arrange_icons) {
1170 wArrangeIcons(wwin->screen_ptr, True);
1173 #ifdef GNOME_STUFF
1174 wGNOMEUpdateClientStateHint(wwin, False);
1175 #endif
1176 #ifdef KWM_HINTS
1177 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1178 wKWMSendEventMessage(wwin, WKWMChangedClient);
1179 #endif
1181 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1186 static void
1187 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1189 if (wwin->flags.miniaturized) {
1190 if (wwin->icon) {
1191 XUnmapWindow(dpy, wwin->icon->core->window);
1192 wwin->icon->mapped = 0;
1194 wwin->flags.hidden = 1;
1195 #ifdef GNOME_STUFF
1196 wGNOMEUpdateClientStateHint(wwin, False);
1197 #endif
1199 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1201 return;
1204 if (wwin->flags.inspector_open) {
1205 WWindow *pwin = wwin->inspector->frame;
1207 wWindowUnmap(pwin);
1208 pwin->flags.hidden = 1;
1210 wClientSetState(pwin, IconicState, icon->icon_win);
1213 wwin->flags.hidden = 1;
1214 wWindowUnmap(wwin);
1216 wClientSetState(wwin, IconicState, icon->icon_win);
1217 flushExpose();
1218 #ifdef WMSOUND
1219 wSoundPlay(WMSOUND_HIDE);
1220 #endif
1221 #ifdef ANIMATIONS
1222 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1223 !wwin->flags.skip_next_animation && animate) {
1224 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1225 wwin->frame->core->width, wwin->frame->core->height,
1226 icon_x, icon_y, icon->core->width, icon->core->height,
1227 True);
1229 #endif
1230 wwin->flags.skip_next_animation = 0;
1232 #ifdef GNOME_STUFF
1233 wGNOMEUpdateClientStateHint(wwin, False);
1234 #endif
1236 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1241 void
1242 wHideOtherApplications(WWindow *awin)
1244 WWindow *wwin;
1245 WApplication *tapp;
1246 #ifdef REDUCE_APPICONS
1247 char *tinstance, *tclass;
1248 unsigned int brokenwin = 0, match = 0;
1249 #endif
1251 if (!awin)
1252 return;
1253 wwin = awin->screen_ptr->focused_window;
1255 #ifdef REDUCE_APPICONS
1256 if (awin->wm_instance == NULL || awin->wm_class == NULL)
1257 brokenwin++;
1258 #endif
1260 while (wwin) {
1261 if (wwin!=awin
1262 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1263 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1264 && !wwin->flags.internal_window
1265 && (!wwin->flags.inspector_open || wwin->inspector->frame!=awin)
1266 && !WFLAGP(wwin, no_hide_others)) {
1268 #ifdef REDUCE_APPICONS
1269 match = 0;
1270 if (!brokenwin) {
1271 if ((tinstance = wwin->wm_instance) == NULL)
1272 tinstance = "";
1273 if ((tclass = wwin->wm_class) == NULL)
1274 tclass = "";
1275 if ((strcmp(awin->wm_instance, tinstance) == 0) &&
1276 (strcmp(awin->wm_class, tclass) == 0) )
1277 match++;
1279 #endif
1281 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1282 if (!WFLAGP(wwin, no_miniaturizable)) {
1283 wwin->flags.skip_next_animation = 1;
1284 wIconifyWindow(wwin);
1286 } else if (wwin->main_window!=None
1287 #ifndef REDUCE_APPICONS
1288 && awin->main_window != wwin->main_window) {
1289 #else
1290 && (awin->main_window != wwin->main_window && !match)) {
1291 #endif
1292 tapp = wApplicationOf(wwin->main_window);
1293 if (tapp) {
1294 tapp->flags.skip_next_animation = 1;
1295 wHideApplication(tapp);
1296 } else {
1297 if (!WFLAGP(wwin, no_miniaturizable)) {
1298 wwin->flags.skip_next_animation = 1;
1299 wIconifyWindow(wwin);
1304 wwin = wwin->prev;
1307 wSetFocusTo(awin->screen_ptr, awin);
1313 void
1314 wHideApplication(WApplication *wapp)
1316 #ifdef REDUCE_APPICONS
1317 WApplication *tapp;
1318 char *tinstance, *tclass;
1319 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1320 #endif
1321 WScreen *scr;
1322 WWindow *wlist;
1323 int hadfocus;
1325 if (!wapp) {
1326 wwarning("trying to hide a non grouped window");
1327 return;
1329 if (!wapp->main_window_desc) {
1330 wwarning("group leader not found for window group");
1331 return;
1333 #ifdef REDUCE_APPICONS
1334 if ((wapp->main_window_desc->wm_instance == NULL) ||
1335 (wapp->main_window_desc->wm_class == NULL))
1336 nowmhints++;
1337 #endif
1338 scr = wapp->main_window_desc->screen_ptr;
1339 hadfocus = 0;
1340 wlist = scr->focused_window;
1341 if (!wlist)
1342 return;
1344 if (wlist->main_window == wapp->main_window)
1345 wapp->last_focused = wlist;
1346 else
1347 wapp->last_focused = NULL;
1348 while (wlist) {
1349 #ifdef REDUCE_APPICONS
1350 matchwmhints = matchworkspace = 0;
1351 if (!nowmhints) {
1352 tapp = wApplicationOf(wlist->main_window);
1353 tinstance = tclass = NULL;
1354 if (tapp) {
1355 if (tapp->main_window_desc) {
1356 tinstance = tapp->main_window_desc->wm_instance;
1357 tclass = tapp->main_window_desc->wm_class;
1360 if (tapp == NULL || tinstance == NULL || tclass == NULL) {
1361 /* Should never reach here */
1362 tinstance = "";
1363 tclass = "";
1365 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0) &&
1366 (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1367 matchwmhints++;
1369 if (wlist->frame) {
1370 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1371 matchworkspace++;
1373 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1374 matchworkspace) {
1375 #ifdef I_HATE_THIS
1377 #endif
1378 #else
1379 if (wlist->main_window == wapp->main_window) {
1380 #endif
1381 if (wlist->flags.focused) {
1382 hadfocus = 1;
1384 if (wapp->app_icon)
1385 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1386 wapp->app_icon->y_pos, wlist,
1387 !wapp->flags.skip_next_animation);
1389 wlist = wlist->prev;
1392 wapp->flags.skip_next_animation = 0;
1394 if (hadfocus) {
1395 if (wPreferences.focus_mode==WKF_CLICK) {
1396 wlist = scr->focused_window;
1397 while (wlist) {
1398 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1399 && (wlist->flags.mapped || wlist->flags.shaded))
1400 break;
1401 wlist = wlist->prev;
1403 wSetFocusTo(scr, wlist);
1404 } else {
1405 wSetFocusTo(scr, NULL);
1409 wapp->flags.hidden = 1;
1411 if(wPreferences.auto_arrange_icons) {
1412 wArrangeIcons(scr, True);
1414 #ifdef HIDDENDOT
1415 if (wapp->app_icon)
1416 wAppIconPaint(wapp->app_icon);
1417 #endif
1423 static void
1424 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1425 int bringToCurrentWS)
1427 if (bringToCurrentWS)
1428 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1430 wwin->flags.hidden=0;
1431 wwin->flags.mapped=1;
1433 #ifdef WMSOUND
1434 wSoundPlay(WMSOUND_UNHIDE);
1435 #endif
1436 #ifdef ANIMATIONS
1437 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1438 && animate) {
1439 animateResize(wwin->screen_ptr, icon_x, icon_y,
1440 icon->core->width, icon->core->height,
1441 wwin->frame_x, wwin->frame_y,
1442 wwin->frame->core->width, wwin->frame->core->height,
1443 True);
1445 #endif
1446 wwin->flags.skip_next_animation = 0;
1447 XMapWindow(dpy, wwin->client_win);
1448 XMapWindow(dpy, wwin->frame->core->window);
1449 wClientSetState(wwin, NormalState, None);
1450 wRaiseFrame(wwin->frame->core);
1451 if (wwin->flags.inspector_open) {
1452 WWindow *pwin = wwin->inspector->frame;
1454 pwin->flags.hidden = 0;
1455 pwin->flags.mapped = 1;
1456 XMapWindow(dpy, pwin->client_win);
1457 XMapWindow(dpy, pwin->frame->core->window);
1458 wClientSetState(pwin, NormalState, None);
1461 #ifdef GNOME_STUFF
1462 wGNOMEUpdateClientStateHint(wwin, False);
1463 #endif
1465 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1470 void
1471 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1473 WScreen *scr;
1474 WWindow *wlist, *next;
1475 WWindow *focused=NULL;
1476 #ifdef REDUCE_APPICONS
1477 char *tinstance, *tclass;
1478 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1479 #endif
1481 if (!wapp) {
1482 return;
1485 #ifdef REDUCE_APPICONS
1486 if ((wapp->main_window_desc->wm_class == NULL) ||
1487 (wapp->main_window_desc->wm_instance == NULL))
1488 nowmhints++;
1489 #endif
1491 scr = wapp->main_window_desc->screen_ptr;
1492 wlist = scr->focused_window;
1493 if (!wlist) return;
1494 /* goto beginning of list */
1495 while (wlist->prev)
1496 wlist = wlist->prev;
1498 while (wlist) {
1499 next = wlist->next;
1501 #ifndef REDUCE_APPICONS
1502 if (wlist->main_window == wapp->main_window) {
1503 #else
1504 matchwmhints = matchworkspace = 0;
1505 if (!nowmhints) {
1506 if ((tinstance = wlist->wm_instance) == NULL)
1507 tinstance = "";
1508 if ((tclass = wlist->wm_class) == NULL)
1509 tclass = "";
1510 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0)
1511 && (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1512 matchwmhints++;
1514 if (wlist->frame) {
1515 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1516 matchworkspace++;
1519 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1520 matchworkspace) {
1521 #endif
1522 if (wlist->flags.focused)
1523 focused = wlist;
1524 else if (!focused || !focused->flags.focused)
1525 focused = wlist;
1527 if (wlist->flags.miniaturized && wlist->icon) {
1528 if (bringToCurrentWS || wPreferences.sticky_icons
1529 || wlist->frame->workspace == scr->current_workspace) {
1530 if (!wlist->icon->mapped) {
1531 XMapWindow(dpy, wlist->icon->core->window);
1532 wlist->icon->mapped = 1;
1534 wlist->flags.hidden = 0;
1536 UpdateSwitchMenu(scr, wlist, ACTION_CHANGE_STATE);
1538 if (wlist->frame->workspace != scr->current_workspace)
1539 wWindowChangeWorkspace(wlist, scr->current_workspace);
1541 if (miniwindows) {
1542 wDeiconifyWindow(wlist);
1544 } else if (wlist->flags.hidden) {
1545 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1546 wapp->app_icon->y_pos, wlist,
1547 !wapp->flags.skip_next_animation,
1548 bringToCurrentWS);
1549 } else {
1550 if (bringToCurrentWS
1551 && wlist->frame->workspace != scr->current_workspace) {
1552 wWindowChangeWorkspace(wlist, scr->current_workspace);
1554 wRaiseFrame(wlist->frame->core);
1557 wlist = next;
1560 wapp->flags.skip_next_animation = 0;
1561 wapp->flags.hidden = 0;
1563 if (focused)
1564 wSetFocusTo(scr, focused);
1565 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1566 wSetFocusTo(scr, wapp->last_focused);
1567 wapp->last_focused = NULL;
1568 if (wPreferences.auto_arrange_icons) {
1569 wArrangeIcons(scr, True);
1571 #ifdef HIDDENDOT
1572 wAppIconPaint(wapp->app_icon);
1573 #endif
1578 void
1579 wShowAllWindows(WScreen *scr)
1581 WWindow *wwin, *old_foc;
1582 WApplication *wapp;
1584 old_foc = wwin = scr->focused_window;
1585 while (wwin) {
1586 if (!wwin->flags.internal_window &&
1587 (scr->current_workspace == wwin->frame->workspace
1588 || IS_OMNIPRESENT(wwin))) {
1589 if (wwin->flags.miniaturized) {
1590 wwin->flags.skip_next_animation = 1;
1591 wDeiconifyWindow(wwin);
1592 } else if (wwin->flags.hidden) {
1593 wapp = wApplicationOf(wwin->main_window);
1594 if (wapp) {
1595 wUnhideApplication(wapp, False, False);
1596 } else {
1597 wwin->flags.skip_next_animation = 1;
1598 wDeiconifyWindow(wwin);
1602 wwin = wwin->prev;
1604 wSetFocusTo(scr, old_foc);
1605 /*wRaiseFrame(old_foc->frame->core);*/
1609 void
1610 wRefreshDesktop(WScreen *scr)
1612 Window win;
1613 XSetWindowAttributes attr;
1615 attr.backing_store = NotUseful;
1616 attr.save_under = False;
1617 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1618 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1619 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1620 &attr);
1621 XMapRaised(dpy, win);
1622 XDestroyWindow(dpy, win);
1623 XFlush(dpy);
1627 void
1628 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1630 WWindow *wwin;
1631 WAppIcon *aicon;
1632 int pf; /* primary axis */
1633 int sf; /* secondary axis */
1634 int fullW;
1635 int fullH;
1636 int pi, si;
1637 int sx1, sx2, sy1, sy2; /* screen boundary */
1638 int sw, sh;
1639 int xo, yo;
1640 int xs, ys;
1641 int isize = wPreferences.icon_size;
1644 * Find out screen boundaries.
1646 sx1 = 0;
1647 sy1 = 0;
1648 sx2 = scr->scr_width;
1649 sy2 = scr->scr_height;
1650 if (scr->dock) {
1651 if (scr->dock->on_right_side)
1652 sx2 -= isize + DOCK_EXTRA_SPACE;
1653 else
1654 sx1 += isize + DOCK_EXTRA_SPACE;
1657 sw = isize * (scr->scr_width/isize);
1658 sh = isize * (scr->scr_height/isize);
1659 fullW = (sx2-sx1)/isize;
1660 fullH = (sy2-sy1)/isize;
1662 /* icon yard boundaries */
1663 if (wPreferences.icon_yard & IY_VERT) {
1664 pf = fullH;
1665 sf = fullW;
1666 } else {
1667 pf = fullW;
1668 sf = fullH;
1670 if (wPreferences.icon_yard & IY_RIGHT) {
1671 xo = sx2 - isize;
1672 xs = -1;
1673 } else {
1674 xo = sx1;
1675 xs = 1;
1677 if (wPreferences.icon_yard & IY_TOP) {
1678 yo = sy1;
1679 ys = 1;
1680 } else {
1681 yo = sy2 - isize;
1682 ys = -1;
1685 /* arrange icons putting the most recently focused window
1686 * as the last icon */
1687 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1688 : xo + xs*(pi*isize))
1689 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1690 : yo + ys*(si*isize))
1692 /* arrange application icons */
1693 aicon = scr->app_icon_list;
1694 /* reverse them to avoid unnecessarily sliding of icons */
1695 while (aicon && aicon->next)
1696 aicon = aicon->next;
1698 pi = 0;
1699 si = 0;
1700 while (aicon) {
1701 if (!aicon->docked) {
1702 if (aicon->x_pos != X || aicon->y_pos != Y) {
1703 #ifdef ANIMATIONS
1704 if (!wPreferences.no_animations) {
1705 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1706 X, Y);
1708 #endif /* ANIMATIONS */
1710 wAppIconMove(aicon, X, Y);
1711 pi++;
1713 /* we reversed the order so we use prev */
1714 aicon = aicon->prev;
1715 if (pi >= pf) {
1716 pi=0;
1717 si++;
1721 /* arrange miniwindows */
1723 wwin = scr->focused_window;
1724 /* reverse them to avoid unnecessarily shuffling */
1725 while (wwin && wwin->prev)
1726 wwin = wwin->prev;
1728 while (wwin) {
1729 if (wwin->icon && wwin->flags.miniaturized &&/*!wwin->flags.hidden &&*/
1730 (wwin->frame->workspace==scr->current_workspace ||
1731 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1733 if (arrangeAll || !wwin->flags.icon_moved) {
1734 if (wwin->icon_x != X || wwin->icon_y != Y) {
1735 #ifdef ANIMATIONS
1736 if (wPreferences.no_animations) {
1737 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1738 } else {
1739 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1740 wwin->icon_y, X, Y);
1742 #else
1743 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1744 #endif /* ANIMATIONS */
1746 wwin->icon_x = X;
1747 wwin->icon_y = Y;
1748 pi++;
1751 if (arrangeAll) {
1752 wwin->flags.icon_moved = 0;
1754 /* we reversed the order, so we use next */
1755 wwin = wwin->next;
1756 if (pi >= pf) {
1757 pi=0;
1758 si++;
1764 void
1765 wSelectWindow(WWindow *wwin, Bool flag)
1767 WScreen *scr = wwin->screen_ptr;
1768 if (flag) {
1769 wwin->flags.selected = 1;
1770 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1771 scr->selected_windows = list_cons(wwin, scr->selected_windows);
1772 } else {
1773 wwin->flags.selected = 0;
1774 XSetWindowBorder(dpy, wwin->frame->core->window,
1775 scr->frame_border_pixel);
1776 scr->selected_windows = list_remove_elem(scr->selected_windows, wwin);
1781 void
1782 wMakeWindowVisible(WWindow *wwin)
1784 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1785 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1787 if (wwin->flags.shaded) {
1788 wUnshadeWindow(wwin);
1790 if (wwin->flags.hidden) {
1791 WApplication *app;
1793 app = wApplicationOf(wwin->main_window);
1794 if (app)
1795 wUnhideApplication(app, False, False);
1796 } else if (wwin->flags.miniaturized) {
1797 wDeiconifyWindow(wwin);
1798 } else {
1799 wSetFocusTo(wwin->screen_ptr, wwin);
1800 wRaiseFrame(wwin->frame->core);