Added the crash dialog panel
[wmaker-crm.git] / src / actions.c
blobd24216c756dd3a1f30e6395052bf99e1bc194c51
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);
931 wwin->flags.miniaturized = 1;
932 wwin->flags.mapped = 0;
934 /* unmap transients */
936 unmapTransientsFor(wwin);
938 if (present) {
939 #ifdef WMSOUND
940 wSoundPlay(WMSOUND_ICONIFY);
941 #endif
943 XUngrabPointer(dpy, CurrentTime);
944 wWindowUnmap(wwin);
945 /* let all Expose events arrive so that we can repaint
946 * something before the animation starts (and the server is grabbed) */
947 XSync(dpy, 0);
949 if (wPreferences.disable_miniwindows)
950 wClientSetState(wwin, IconicState, None);
951 else
952 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
954 flushExpose();
955 #ifdef ANIMATIONS
956 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
957 && !wPreferences.no_animations) {
958 int ix, iy, iw, ih;
960 if (!wPreferences.disable_miniwindows) {
961 ix = wwin->icon_x;
962 iy = wwin->icon_y;
963 iw = wwin->icon->core->width;
964 ih = wwin->icon->core->height;
965 } else {
966 #ifdef KWM_HINTS
967 WArea area;
969 if (wKWMGetIconGeometry(wwin, &area)) {
970 ix = area.x1;
971 iy = area.y1;
972 iw = area.x2 - ix;
973 ih = area.y2 - iy;
974 } else
975 #endif /* KWM_HINTS */
977 ix = 0;
978 iy = 0;
979 iw = wwin->screen_ptr->scr_width;
980 ih = wwin->screen_ptr->scr_height;
983 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
984 wwin->frame->core->width, wwin->frame->core->height,
985 ix, iy, iw, ih, False);
987 #endif
990 wwin->flags.skip_next_animation = 0;
992 if (!wPreferences.disable_miniwindows) {
994 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
995 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
997 XMapWindow(dpy, wwin->icon->core->window);
999 AddToStackList(wwin->icon->core);
1001 wLowerFrame(wwin->icon->core);
1004 if (present) {
1005 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1008 * It doesn't seem to be working and causes button event hangup
1009 * when deiconifying a transient window.
1010 setupIconGrabs(wwin->icon);
1012 if ((wwin->flags.focused
1013 || (owner && wwin->client_win == owner->client_win))
1014 && wPreferences.focus_mode==WKF_CLICK) {
1015 WWindow *tmp;
1017 tmp = wwin->prev;
1018 while (tmp) {
1019 if (!WFLAGP(tmp, no_focusable)
1020 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1021 && (wwin->frame->workspace == tmp->frame->workspace))
1022 break;
1023 tmp = tmp->prev;
1025 wSetFocusTo(wwin->screen_ptr, tmp);
1026 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1027 wSetFocusTo(wwin->screen_ptr, NULL);
1030 #ifdef ANIMATIONS
1031 if (!wwin->screen_ptr->flags.startup) {
1032 Window clientwin = wwin->client_win;
1034 XSync(dpy, 0);
1035 processEvents(XPending(dpy));
1037 /* the window can disappear while doing the processEvents() */
1038 if (!wWindowFor(clientwin))
1039 return;
1041 #endif
1045 if (wwin->flags.selected && !wPreferences.disable_miniwindows)
1046 wIconSelect(wwin->icon);
1048 #ifdef GNOME_STUFF
1049 wGNOMEUpdateClientStateHint(wwin, False);
1050 #endif
1051 #ifdef KWM_HINTS
1052 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1053 wKWMSendEventMessage(wwin, WKWMChangedClient);
1054 #endif
1056 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1062 void
1063 wDeiconifyWindow(WWindow *wwin)
1065 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1067 if (!wwin->flags.miniaturized)
1068 return;
1070 if (wwin->transient_for != None
1071 && wwin->transient_for != wwin->screen_ptr->root_win) {
1072 WWindow *owner = recursiveTransientFor(wwin);
1074 if (owner && owner->flags.miniaturized) {
1075 wDeiconifyWindow(owner);
1076 wSetFocusTo(wwin->screen_ptr, wwin);
1077 wRaiseFrame(wwin->frame->core);
1078 return;
1082 wwin->flags.miniaturized = 0;
1083 if (!wwin->flags.shaded)
1084 wwin->flags.mapped = 1;
1086 if (!wPreferences.disable_miniwindows) {
1087 if (wwin->icon->selected)
1088 wIconSelect(wwin->icon);
1090 XUnmapWindow(dpy, wwin->icon->core->window);
1093 #ifdef WMSOUND
1094 wSoundPlay(WMSOUND_DEICONIFY);
1095 #endif
1097 /* if the window is in another workspace, do it silently */
1098 #ifdef ANIMATIONS
1099 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1100 && !wwin->flags.skip_next_animation) {
1101 int ix, iy, iw, ih;
1103 if (!wPreferences.disable_miniwindows) {
1104 ix = wwin->icon_x;
1105 iy = wwin->icon_y;
1106 iw = wwin->icon->core->width;
1107 ih = wwin->icon->core->height;
1108 } else {
1109 #ifdef KWM_HINTS
1110 WArea area;
1112 if (wKWMGetIconGeometry(wwin, &area)) {
1113 ix = area.x1;
1114 iy = area.y1;
1115 iw = area.x2 - ix;
1116 ih = area.y2 - iy;
1117 } else
1118 #endif /* KWM_HINTS */
1120 ix = 0;
1121 iy = 0;
1122 iw = wwin->screen_ptr->scr_width;
1123 ih = wwin->screen_ptr->scr_height;
1126 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1127 wwin->frame_x, wwin->frame_y,
1128 wwin->frame->core->width, wwin->frame->core->height,
1129 False);
1131 #endif /* ANIMATIONS */
1132 wwin->flags.skip_next_animation = 0;
1133 XGrabServer(dpy);
1134 if (!wwin->flags.shaded) {
1135 XMapWindow(dpy, wwin->client_win);
1137 XMapWindow(dpy, wwin->frame->core->window);
1138 wRaiseFrame(wwin->frame->core);
1139 if (!wwin->flags.shaded) {
1140 wClientSetState(wwin, NormalState, None);
1142 mapTransientsFor(wwin);
1144 if (!wPreferences.disable_miniwindows) {
1145 RemoveFromStackList(wwin->icon->core);
1146 /* removeIconGrabs(wwin->icon);*/
1147 wIconDestroy(wwin->icon);
1148 wwin->icon = NULL;
1150 XUngrabServer(dpy);
1151 if (wPreferences.focus_mode==WKF_CLICK
1152 || wPreferences.focus_mode==WKF_SLOPPY)
1153 wSetFocusTo(wwin->screen_ptr, wwin);
1155 #ifdef ANIMATIONS
1156 if (!wwin->screen_ptr->flags.startup) {
1157 Window clientwin = wwin->client_win;
1159 XSync(dpy, 0);
1160 processEvents(XPending(dpy));
1162 if (!wWindowFor(clientwin))
1163 return;
1165 #endif
1167 if (wPreferences.auto_arrange_icons) {
1168 wArrangeIcons(wwin->screen_ptr, True);
1171 #ifdef GNOME_STUFF
1172 wGNOMEUpdateClientStateHint(wwin, False);
1173 #endif
1174 #ifdef KWM_HINTS
1175 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1176 wKWMSendEventMessage(wwin, WKWMChangedClient);
1177 #endif
1179 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1184 static void
1185 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1187 if (wwin->flags.miniaturized) {
1188 if (wwin->icon) {
1189 XUnmapWindow(dpy, wwin->icon->core->window);
1190 wwin->icon->mapped = 0;
1192 wwin->flags.hidden = 1;
1193 #ifdef GNOME_STUFF
1194 wGNOMEUpdateClientStateHint(wwin, False);
1195 #endif
1197 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1199 return;
1202 if (wwin->flags.inspector_open) {
1203 WWindow *pwin = wwin->inspector->frame;
1205 wWindowUnmap(pwin);
1206 pwin->flags.hidden = 1;
1208 wClientSetState(pwin, IconicState, icon->icon_win);
1211 wwin->flags.hidden = 1;
1212 wWindowUnmap(wwin);
1214 wClientSetState(wwin, IconicState, icon->icon_win);
1215 flushExpose();
1216 #ifdef WMSOUND
1217 wSoundPlay(WMSOUND_HIDE);
1218 #endif
1219 #ifdef ANIMATIONS
1220 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1221 !wwin->flags.skip_next_animation && animate) {
1222 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1223 wwin->frame->core->width, wwin->frame->core->height,
1224 icon_x, icon_y, icon->core->width, icon->core->height,
1225 True);
1227 #endif
1228 wwin->flags.skip_next_animation = 0;
1230 #ifdef GNOME_STUFF
1231 wGNOMEUpdateClientStateHint(wwin, False);
1232 #endif
1234 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1239 void
1240 wHideOtherApplications(WWindow *awin)
1242 WWindow *wwin;
1243 WApplication *tapp;
1244 #ifdef REDUCE_APPICONS
1245 char *tinstance, *tclass;
1246 unsigned int brokenwin = 0, match = 0;
1247 #endif
1249 if (!awin)
1250 return;
1251 wwin = awin->screen_ptr->focused_window;
1253 #ifdef REDUCE_APPICONS
1254 if (awin->wm_instance == NULL || awin->wm_class == NULL)
1255 brokenwin++;
1256 #endif
1258 while (wwin) {
1259 if (wwin!=awin
1260 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1261 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1262 && !wwin->flags.internal_window
1263 && (!wwin->flags.inspector_open || wwin->inspector->frame!=awin)
1264 && !WFLAGP(wwin, no_hide_others)) {
1266 #ifdef REDUCE_APPICONS
1267 match = 0;
1268 if (!brokenwin) {
1269 if ((tinstance = wwin->wm_instance) == NULL)
1270 tinstance = "";
1271 if ((tclass = wwin->wm_class) == NULL)
1272 tclass = "";
1273 if ((strcmp(awin->wm_instance, tinstance) == 0) &&
1274 (strcmp(awin->wm_class, tclass) == 0) )
1275 match++;
1277 #endif
1279 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1280 if (!WFLAGP(wwin, no_miniaturizable)) {
1281 wwin->flags.skip_next_animation = 1;
1282 wIconifyWindow(wwin);
1284 } else if (wwin->main_window!=None
1285 #ifndef REDUCE_APPICONS
1286 && awin->main_window != wwin->main_window) {
1287 #else
1288 && (awin->main_window != wwin->main_window && !match)) {
1289 #endif
1290 tapp = wApplicationOf(wwin->main_window);
1291 if (tapp) {
1292 tapp->flags.skip_next_animation = 1;
1293 wHideApplication(tapp);
1294 } else {
1295 if (!WFLAGP(wwin, no_miniaturizable)) {
1296 wwin->flags.skip_next_animation = 1;
1297 wIconifyWindow(wwin);
1302 wwin = wwin->prev;
1305 wSetFocusTo(awin->screen_ptr, awin);
1311 void
1312 wHideApplication(WApplication *wapp)
1314 #ifdef REDUCE_APPICONS
1315 WApplication *tapp;
1316 char *tinstance, *tclass;
1317 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1318 #endif
1319 WScreen *scr;
1320 WWindow *wlist;
1321 int hadfocus;
1323 if (!wapp) {
1324 wwarning("trying to hide a non grouped window");
1325 return;
1327 if (!wapp->main_window_desc) {
1328 wwarning("group leader not found for window group");
1329 return;
1331 #ifdef REDUCE_APPICONS
1332 if ((wapp->main_window_desc->wm_instance == NULL) ||
1333 (wapp->main_window_desc->wm_class == NULL))
1334 nowmhints++;
1335 #endif
1336 scr = wapp->main_window_desc->screen_ptr;
1337 hadfocus = 0;
1338 wlist = scr->focused_window;
1339 if (!wlist)
1340 return;
1342 if (wlist->main_window == wapp->main_window)
1343 wapp->last_focused = wlist;
1344 else
1345 wapp->last_focused = NULL;
1346 while (wlist) {
1347 #ifdef REDUCE_APPICONS
1348 matchwmhints = matchworkspace = 0;
1349 if (!nowmhints) {
1350 tapp = wApplicationOf(wlist->main_window);
1351 tinstance = tclass = NULL;
1352 if (tapp) {
1353 if (tapp->main_window_desc) {
1354 tinstance = tapp->main_window_desc->wm_instance;
1355 tclass = tapp->main_window_desc->wm_class;
1358 if (tapp == NULL || tinstance == NULL || tclass == NULL) {
1359 /* Should never reach here */
1360 tinstance = "";
1361 tclass = "";
1363 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0) &&
1364 (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1365 matchwmhints++;
1367 if (wlist->frame) {
1368 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1369 matchworkspace++;
1371 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1372 matchworkspace) {
1373 #ifdef I_HATE_THIS
1375 #endif
1376 #else
1377 if (wlist->main_window == wapp->main_window) {
1378 #endif
1379 if (wlist->flags.focused) {
1380 hadfocus = 1;
1382 if (wapp->app_icon)
1383 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1384 wapp->app_icon->y_pos, wlist,
1385 !wapp->flags.skip_next_animation);
1387 wlist = wlist->prev;
1390 wapp->flags.skip_next_animation = 0;
1392 if (hadfocus) {
1393 if (wPreferences.focus_mode==WKF_CLICK) {
1394 wlist = scr->focused_window;
1395 while (wlist) {
1396 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1397 && (wlist->flags.mapped || wlist->flags.shaded))
1398 break;
1399 wlist = wlist->prev;
1401 wSetFocusTo(scr, wlist);
1402 } else {
1403 wSetFocusTo(scr, NULL);
1407 wapp->flags.hidden = 1;
1409 if(wPreferences.auto_arrange_icons) {
1410 wArrangeIcons(scr, True);
1412 #ifdef HIDDENDOT
1413 if (wapp->app_icon)
1414 wAppIconPaint(wapp->app_icon);
1415 #endif
1421 static void
1422 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1423 int bringToCurrentWS)
1425 if (bringToCurrentWS)
1426 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1428 wwin->flags.hidden=0;
1429 wwin->flags.mapped=1;
1431 #ifdef WMSOUND
1432 wSoundPlay(WMSOUND_UNHIDE);
1433 #endif
1434 #ifdef ANIMATIONS
1435 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1436 && animate) {
1437 animateResize(wwin->screen_ptr, icon_x, icon_y,
1438 icon->core->width, icon->core->height,
1439 wwin->frame_x, wwin->frame_y,
1440 wwin->frame->core->width, wwin->frame->core->height,
1441 True);
1443 #endif
1444 wwin->flags.skip_next_animation = 0;
1445 XMapWindow(dpy, wwin->client_win);
1446 XMapWindow(dpy, wwin->frame->core->window);
1447 wClientSetState(wwin, NormalState, None);
1448 wRaiseFrame(wwin->frame->core);
1449 if (wwin->flags.inspector_open) {
1450 WWindow *pwin = wwin->inspector->frame;
1452 pwin->flags.hidden = 0;
1453 pwin->flags.mapped = 1;
1454 XMapWindow(dpy, pwin->client_win);
1455 XMapWindow(dpy, pwin->frame->core->window);
1456 wClientSetState(pwin, NormalState, None);
1459 #ifdef GNOME_STUFF
1460 wGNOMEUpdateClientStateHint(wwin, False);
1461 #endif
1463 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1468 void
1469 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1471 WScreen *scr;
1472 WWindow *wlist, *next;
1473 WWindow *focused=NULL;
1474 #ifdef REDUCE_APPICONS
1475 char *tinstance, *tclass;
1476 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1477 #endif
1479 if (!wapp) {
1480 return;
1483 #ifdef REDUCE_APPICONS
1484 if ((wapp->main_window_desc->wm_class == NULL) ||
1485 (wapp->main_window_desc->wm_instance == NULL))
1486 nowmhints++;
1487 #endif
1489 scr = wapp->main_window_desc->screen_ptr;
1490 wlist = scr->focused_window;
1491 if (!wlist) return;
1492 /* goto beginning of list */
1493 while (wlist->prev)
1494 wlist = wlist->prev;
1496 while (wlist) {
1497 next = wlist->next;
1499 #ifndef REDUCE_APPICONS
1500 if (wlist->main_window == wapp->main_window) {
1501 #else
1502 matchwmhints = matchworkspace = 0;
1503 if (!nowmhints) {
1504 if ((tinstance = wlist->wm_instance) == NULL)
1505 tinstance = "";
1506 if ((tclass = wlist->wm_class) == NULL)
1507 tclass = "";
1508 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0)
1509 && (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1510 matchwmhints++;
1512 if (wlist->frame) {
1513 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1514 matchworkspace++;
1517 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1518 matchworkspace) {
1519 #endif
1520 if (wlist->flags.focused)
1521 focused = wlist;
1522 else if (!focused || !focused->flags.focused)
1523 focused = wlist;
1525 if (wlist->flags.miniaturized && wlist->icon) {
1526 if (bringToCurrentWS || wPreferences.sticky_icons
1527 || wlist->frame->workspace == scr->current_workspace) {
1528 if (!wlist->icon->mapped) {
1529 XMapWindow(dpy, wlist->icon->core->window);
1530 wlist->icon->mapped = 1;
1532 wlist->flags.hidden = 0;
1534 UpdateSwitchMenu(scr, wlist, ACTION_CHANGE_STATE);
1536 if (wlist->frame->workspace != scr->current_workspace)
1537 wWindowChangeWorkspace(wlist, scr->current_workspace);
1539 if (miniwindows) {
1540 wDeiconifyWindow(wlist);
1542 } else if (wlist->flags.hidden) {
1543 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1544 wapp->app_icon->y_pos, wlist,
1545 !wapp->flags.skip_next_animation,
1546 bringToCurrentWS);
1547 } else {
1548 if (bringToCurrentWS
1549 && wlist->frame->workspace != scr->current_workspace) {
1550 wWindowChangeWorkspace(wlist, scr->current_workspace);
1552 wRaiseFrame(wlist->frame->core);
1555 wlist = next;
1558 wapp->flags.skip_next_animation = 0;
1559 wapp->flags.hidden = 0;
1561 if (focused)
1562 wSetFocusTo(scr, focused);
1563 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1564 wSetFocusTo(scr, wapp->last_focused);
1565 wapp->last_focused = NULL;
1566 if (wPreferences.auto_arrange_icons) {
1567 wArrangeIcons(scr, True);
1569 #ifdef HIDDENDOT
1570 wAppIconPaint(wapp->app_icon);
1571 #endif
1576 void
1577 wShowAllWindows(WScreen *scr)
1579 WWindow *wwin, *old_foc;
1580 WApplication *wapp;
1582 old_foc = wwin = scr->focused_window;
1583 while (wwin) {
1584 if (!wwin->flags.internal_window &&
1585 (scr->current_workspace == wwin->frame->workspace
1586 || IS_OMNIPRESENT(wwin))) {
1587 if (wwin->flags.miniaturized) {
1588 wwin->flags.skip_next_animation = 1;
1589 wDeiconifyWindow(wwin);
1590 } else if (wwin->flags.hidden) {
1591 wapp = wApplicationOf(wwin->main_window);
1592 if (wapp) {
1593 wUnhideApplication(wapp, False, False);
1594 } else {
1595 wwin->flags.skip_next_animation = 1;
1596 wDeiconifyWindow(wwin);
1600 wwin = wwin->prev;
1602 wSetFocusTo(scr, old_foc);
1603 /*wRaiseFrame(old_foc->frame->core);*/
1607 void
1608 wRefreshDesktop(WScreen *scr)
1610 Window win;
1611 XSetWindowAttributes attr;
1613 attr.backing_store = NotUseful;
1614 attr.save_under = False;
1615 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1616 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1617 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1618 &attr);
1619 XMapRaised(dpy, win);
1620 XDestroyWindow(dpy, win);
1621 XFlush(dpy);
1625 void
1626 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1628 WWindow *wwin;
1629 WAppIcon *aicon;
1630 int pf; /* primary axis */
1631 int sf; /* secondary axis */
1632 int fullW;
1633 int fullH;
1634 int pi, si;
1635 int sx1, sx2, sy1, sy2; /* screen boundary */
1636 int sw, sh;
1637 int xo, yo;
1638 int xs, ys;
1639 int isize = wPreferences.icon_size;
1642 * Find out screen boundaries.
1644 sx1 = 0;
1645 sy1 = 0;
1646 sx2 = scr->scr_width;
1647 sy2 = scr->scr_height;
1648 if (scr->dock) {
1649 if (scr->dock->on_right_side)
1650 sx2 -= isize + DOCK_EXTRA_SPACE;
1651 else
1652 sx1 += isize + DOCK_EXTRA_SPACE;
1655 sw = isize * (scr->scr_width/isize);
1656 sh = isize * (scr->scr_height/isize);
1657 fullW = (sx2-sx1)/isize;
1658 fullH = (sy2-sy1)/isize;
1660 /* icon yard boundaries */
1661 if (wPreferences.icon_yard & IY_VERT) {
1662 pf = fullH;
1663 sf = fullW;
1664 } else {
1665 pf = fullW;
1666 sf = fullH;
1668 if (wPreferences.icon_yard & IY_RIGHT) {
1669 xo = sx2 - isize;
1670 xs = -1;
1671 } else {
1672 xo = sx1;
1673 xs = 1;
1675 if (wPreferences.icon_yard & IY_TOP) {
1676 yo = sy1;
1677 ys = 1;
1678 } else {
1679 yo = sy2 - isize;
1680 ys = -1;
1683 /* arrange icons putting the most recently focused window
1684 * as the last icon */
1685 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1686 : xo + xs*(pi*isize))
1687 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1688 : yo + ys*(si*isize))
1690 /* arrange application icons */
1691 aicon = scr->app_icon_list;
1692 /* reverse them to avoid unnecessarily sliding of icons */
1693 while (aicon && aicon->next)
1694 aicon = aicon->next;
1696 pi = 0;
1697 si = 0;
1698 while (aicon) {
1699 if (!aicon->docked) {
1700 if (aicon->x_pos != X || aicon->y_pos != Y) {
1701 #ifdef ANIMATIONS
1702 if (!wPreferences.no_animations) {
1703 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1704 X, Y);
1706 #endif /* ANIMATIONS */
1708 wAppIconMove(aicon, X, Y);
1709 pi++;
1711 /* we reversed the order so we use prev */
1712 aicon = aicon->prev;
1713 if (pi >= pf) {
1714 pi=0;
1715 si++;
1719 /* arrange miniwindows */
1721 wwin = scr->focused_window;
1722 /* reverse them to avoid unnecessarily shuffling */
1723 while (wwin && wwin->prev)
1724 wwin = wwin->prev;
1726 while (wwin) {
1727 if (wwin->icon && wwin->flags.miniaturized &&/*!wwin->flags.hidden &&*/
1728 (wwin->frame->workspace==scr->current_workspace ||
1729 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1731 if (arrangeAll || !wwin->flags.icon_moved) {
1732 if (wwin->icon_x != X || wwin->icon_y != Y) {
1733 #ifdef ANIMATIONS
1734 if (wPreferences.no_animations) {
1735 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1736 } else {
1737 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1738 wwin->icon_y, X, Y);
1740 #else
1741 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1742 #endif /* ANIMATIONS */
1744 wwin->icon_x = X;
1745 wwin->icon_y = Y;
1746 pi++;
1749 if (arrangeAll) {
1750 wwin->flags.icon_moved = 0;
1752 /* we reversed the order, so we use next */
1753 wwin = wwin->next;
1754 if (pi >= pf) {
1755 pi=0;
1756 si++;
1762 void
1763 wSelectWindow(WWindow *wwin, Bool flag)
1765 WScreen *scr = wwin->screen_ptr;
1766 if (flag) {
1767 wwin->flags.selected = 1;
1768 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1769 scr->selected_windows = list_cons(wwin, scr->selected_windows);
1770 } else {
1771 wwin->flags.selected = 0;
1772 XSetWindowBorder(dpy, wwin->frame->core->window,
1773 scr->frame_border_pixel);
1774 scr->selected_windows = list_remove_elem(scr->selected_windows, wwin);
1779 void
1780 wMakeWindowVisible(WWindow *wwin)
1782 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1784 if (wwin->flags.shaded) {
1785 wUnshadeWindow(wwin);
1787 if (wwin->flags.hidden) {
1788 WApplication *app;
1790 app = wApplicationOf(wwin->main_window);
1791 if (app)
1792 wUnhideApplication(app, False, False);
1793 } else if (wwin->flags.miniaturized) {
1794 wDeiconifyWindow(wwin);
1795 } else {
1796 wSetFocusTo(wwin->screen_ptr, wwin);
1797 wRaiseFrame(wwin->frame->core);