fixed bug with icons of different sizes
[wmaker-crm.git] / src / actions.c
bloba8024ede80a1ed966818ea81eb51b253fce38c28
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"
51 #ifdef GNOME_STUFF
52 # include "gnome.h"
53 #endif
54 #ifdef KWM_HINTS
55 # include "kwm.h"
56 #endif
58 #ifdef WMSOUND
59 #include "wmsound.h"
60 #endif
63 /****** Global Variables ******/
64 extern Time LastTimestamp;
65 extern Time LastFocusChange;
67 extern Cursor wCursor[WCUR_LAST];
69 extern WPreferences wPreferences;
71 extern Atom _XA_WM_TAKE_FOCUS;
74 /******* Local Variables *******/
75 static struct {
76 int steps;
77 int delay;
78 } shadePars[5] = {
79 {SHADE_STEPS_UF, SHADE_DELAY_UF},
80 {SHADE_STEPS_F, SHADE_DELAY_F},
81 {SHADE_STEPS_M, SHADE_DELAY_M},
82 {SHADE_STEPS_S, SHADE_DELAY_S},
83 {SHADE_STEPS_U, SHADE_DELAY_U}};
85 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
86 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
89 static int ignoreTimestamp=0;
92 #ifdef ANIMATIONS
93 static void
94 processEvents(int event_count)
96 XEvent event;
99 * This is a hack. When animations are enabled, processing of
100 * events ocurred during a animation are delayed until it's end.
101 * Calls that consider the TimeStamp, like XSetInputFocus(), will
102 * fail because the TimeStamp is too old. Then, for example, if
103 * the user changes window focus while a miniaturize animation is
104 * in course, the window will not get focus properly after the end
105 * of the animation. This tries to workaround it by passing CurrentTime
106 * as the TimeStamp for XSetInputFocus() for all events ocurred during
107 * the animation.
109 ignoreTimestamp=1;
110 while (XPending(dpy) && event_count--) {
111 WMNextEvent(dpy, &event);
112 WMHandleEvent(&event);
114 ignoreTimestamp=0;
116 #endif /* ANIMATIONS */
121 *----------------------------------------------------------------------
122 * wSetFocusTo--
123 * Changes the window focus to the one passed as argument.
124 * If the window to focus is not already focused, it will be brought
125 * to the head of the list of windows. Previously focused window is
126 * unfocused.
128 * Side effects:
129 * Window list may be reordered and the window focus is changed.
131 *----------------------------------------------------------------------
133 void
134 wSetFocusTo(WScreen *scr, WWindow *wwin)
136 static WScreen *old_scr=NULL;
138 WWindow *old_focused;
139 WWindow *focused=scr->focused_window;
140 int timestamp=LastTimestamp;
141 WApplication *oapp=NULL, *napp=NULL;
142 int wasfocused;
144 if (!old_scr)
145 old_scr=scr;
146 old_focused=old_scr->focused_window;
148 LastFocusChange = timestamp;
151 * This is a hack, because XSetInputFocus() should have a proper
152 * timestamp instead of CurrentTime but it seems that some times
153 * clients will not receive focus properly that way.
154 if (ignoreTimestamp)
156 timestamp = CurrentTime;
158 if (old_focused)
159 oapp = wApplicationOf(old_focused->main_window);
161 if (wwin == NULL) {
162 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
163 if (old_focused) {
164 wWindowUnfocus(old_focused);
166 if (oapp) {
167 wAppMenuUnmap(oapp->menu);
168 #ifdef NEWAPPICON
169 wApplicationDeactivate(oapp);
170 #endif
172 #ifdef KWM_HINTS
173 wKWMUpdateActiveWindowHint(scr);
174 wKWMSendEventMessage(NULL, WKWMFocusWindow);
175 #endif
176 return;
177 } else if(old_scr != scr && old_focused) {
178 wWindowUnfocus(old_focused);
181 wasfocused = wwin->flags.focused;
182 napp = wApplicationOf(wwin->main_window);
184 /* remember last workspace where the app has been */
185 if (napp)
186 napp->last_workspace = wwin->screen_ptr->current_workspace;
188 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
189 /* install colormap if colormap mode is lock mode */
190 if (wPreferences.colormap_mode==WKF_CLICK)
191 wColormapInstallForWindow(scr, wwin);
193 /* set input focus */
194 switch (wwin->focus_mode) {
195 case WFM_NO_INPUT:
196 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
197 break;
199 case WFM_PASSIVE:
200 case WFM_LOCALLY_ACTIVE:
201 XSetInputFocus(dpy, wwin->client_win, RevertToParent, timestamp);
202 break;
204 case WFM_GLOBALLY_ACTIVE:
205 break;
207 XFlush(dpy);
208 if (wwin->protocols.TAKE_FOCUS) {
209 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
211 XSync(dpy, False);
212 } else {
213 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
215 if (WFLAGP(wwin, no_focusable))
216 return;
218 /* if this is not the focused window focus it */
219 if (focused!=wwin) {
220 /* change the focus window list order */
221 if (wwin->prev)
222 wwin->prev->next = wwin->next;
224 if (wwin->next)
225 wwin->next->prev = wwin->prev;
227 wwin->prev = focused;
228 focused->next = wwin;
229 wwin->next = NULL;
230 scr->focused_window = wwin;
232 if (oapp && oapp != napp) {
233 wAppMenuUnmap(oapp->menu);
234 #ifdef NEWAPPICON
235 wApplicationDeactivate(oapp);
236 #endif
240 wWindowFocus(wwin, focused);
242 if (napp && !wasfocused) {
243 #ifdef USER_MENU
244 wUserMenuRefreshInstances(napp->menu, wwin);
245 #endif /* USER_MENU */
247 if (wwin->flags.mapped)
248 wAppMenuMap(napp->menu, wwin);
249 #ifdef NEWAPPICON
250 wApplicationActivate(napp);
251 #endif
253 #ifdef KWM_HINTS
254 wKWMUpdateActiveWindowHint(scr);
255 wKWMSendEventMessage(wwin, WKWMFocusWindow);
256 #endif
257 XFlush(dpy);
258 old_scr=scr;
262 void
263 wShadeWindow(WWindow *wwin)
265 time_t time0 = time(NULL);
266 #ifdef ANIMATIONS
267 int y, s, w, h;
268 #endif
270 if (wwin->flags.shaded)
271 return;
273 XLowerWindow(dpy, wwin->client_win);
275 #ifdef WMSOUND
276 wSoundPlay(WMSOUND_SHADE);
277 #endif
279 #ifdef ANIMATIONS
280 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
281 && !wPreferences.no_animations) {
282 /* do the shading animation */
283 h = wwin->frame->core->height;
284 s = h/SHADE_STEPS;
285 if (s < 1) s=1;
286 w = wwin->frame->core->width;
287 y = wwin->frame->top_width;
288 while (h>wwin->frame->top_width+1) {
289 XMoveWindow(dpy, wwin->client_win, 0, y);
290 XResizeWindow(dpy, wwin->frame->core->window, w, h);
291 XFlush(dpy);
293 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
294 break;
296 if (SHADE_DELAY > 0)
297 wusleep(SHADE_DELAY*1000L);
298 h-=s;
299 y-=s;
301 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
303 #endif /* ANIMATIONS */
305 wwin->flags.skip_next_animation = 0;
306 wwin->flags.shaded = 1;
307 wwin->flags.mapped = 0;
308 /* prevent window withdrawal when getting UnmapNotify */
309 XSelectInput(dpy, wwin->client_win,
310 wwin->event_mask & ~StructureNotifyMask);
311 XUnmapWindow(dpy, wwin->client_win);
312 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
314 /* for the client it's just like iconification */
315 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
316 wwin->frame->top_width - 1);
318 wwin->client.y = wwin->frame_y - wwin->client.height
319 + wwin->frame->top_width;
320 wWindowSynthConfigureNotify(wwin);
323 wClientSetState(wwin, IconicState, None);
326 #ifdef GNOME_STUFF
327 wGNOMEUpdateClientStateHint(wwin, False);
328 #endif
329 #ifdef KWM_HINTS
330 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
331 wKWMSendEventMessage(wwin, WKWMChangedClient);
332 #endif
333 /* update window list to reflect shaded state */
334 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
336 #ifdef ANIMATIONS
337 if (!wwin->screen_ptr->flags.startup) {
338 /* Look at processEvents() for reason of this code. */
339 XSync(dpy, 0);
340 processEvents(XPending(dpy));
342 #endif
346 void
347 wUnshadeWindow(WWindow *wwin)
349 time_t time0 = time(NULL);
350 #ifdef ANIMATIONS
351 int y, s, w, h;
352 #endif /* ANIMATIONS */
355 if (!wwin->flags.shaded)
356 return;
358 wwin->flags.shaded = 0;
359 wwin->flags.mapped = 1;
360 XMapWindow(dpy, wwin->client_win);
362 #ifdef WMSOUND
363 wSoundPlay(WMSOUND_UNSHADE);
364 #endif
366 #ifdef ANIMATIONS
367 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
368 /* do the shading animation */
369 h = wwin->frame->top_width + wwin->frame->bottom_width;
370 y = wwin->frame->top_width - wwin->client.height;
371 s = abs(y)/SHADE_STEPS;
372 if (s<1) s=1;
373 w = wwin->frame->core->width;
374 XMoveWindow(dpy, wwin->client_win, 0, y);
375 if (s>0) {
376 while (h < wwin->client.height + wwin->frame->top_width
377 + wwin->frame->bottom_width) {
378 XResizeWindow(dpy, wwin->frame->core->window, w, h);
379 XMoveWindow(dpy, wwin->client_win, 0, y);
380 XSync(dpy, 0);
381 if (SHADE_DELAY > 0)
382 wusleep(SHADE_DELAY*2000L/3);
383 h+=s;
384 y+=s;
386 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
387 break;
390 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
392 #endif /* ANIMATIONS */
394 wwin->flags.skip_next_animation = 0;
395 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
396 wwin->frame->top_width + wwin->client.height
397 + wwin->frame->bottom_width);
399 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
400 wWindowSynthConfigureNotify(wwin);
403 wClientSetState(wwin, NormalState, None);
405 /* if the window is focused, set the focus again as it was disabled during
406 * shading */
407 if (wwin->flags.focused)
408 wSetFocusTo(wwin->screen_ptr, wwin);
410 #ifdef GNOME_STUFF
411 wGNOMEUpdateClientStateHint(wwin, False);
412 #endif
413 #ifdef KWM_HINTS
414 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
415 wKWMSendEventMessage(wwin, WKWMChangedClient);
416 #endif
418 /* update window list to reflect unshaded state */
419 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
424 void
425 wMaximizeWindow(WWindow *wwin, int directions)
427 int new_width, new_height, new_x, new_y;
428 WArea usableArea = wwin->screen_ptr->totalUsableArea;
431 if (WFLAGP(wwin, no_resizable))
432 return;
435 if (WFLAGP(wwin, full_maximize)) {
436 usableArea.x1 = 0;
437 usableArea.y1 = 0;
438 usableArea.x2 = wwin->screen_ptr->scr_width;
439 usableArea.y2 = wwin->screen_ptr->scr_height;
442 if (wwin->flags.shaded) {
443 wwin->flags.skip_next_animation = 1;
444 wUnshadeWindow(wwin);
446 wwin->flags.maximized = directions;
447 wwin->old_geometry.width = wwin->client.width;
448 wwin->old_geometry.height = wwin->client.height;
449 wwin->old_geometry.x = wwin->frame_x;
450 wwin->old_geometry.y = wwin->frame_y;
452 #ifdef KWM_HINTS
453 wKWMUpdateClientGeometryRestore(wwin);
454 #endif
456 if (directions & MAX_HORIZONTAL) {
458 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
459 new_x = usableArea.x1;
461 } else {
463 new_x = wwin->frame_x;
464 new_width = wwin->frame->core->width;
468 if (directions & MAX_VERTICAL) {
470 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
471 new_y = usableArea.y1;
472 if (WFLAGP(wwin, full_maximize)) {
473 new_y -= wwin->frame->top_width - 1;
474 new_height += wwin->frame->bottom_width - 3;
476 } else {
477 new_y = wwin->frame_y;
478 new_height = wwin->frame->core->height;
481 if (!WFLAGP(wwin, full_maximize)) {
482 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
485 wWindowConstrainSize(wwin, &new_width, &new_height);
486 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
488 #ifdef GNOME_STUFF
489 wGNOMEUpdateClientStateHint(wwin, False);
490 #endif
491 #ifdef KWM_HINTS
492 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
493 wKWMSendEventMessage(wwin, WKWMChangedClient);
494 #endif
496 #ifdef WMSOUND
497 wSoundPlay(WMSOUND_MAXIMIZE);
498 #endif
502 void
503 wUnmaximizeWindow(WWindow *wwin)
505 int restore_x, restore_y;
507 if (!wwin->flags.maximized)
508 return;
510 if (wwin->flags.shaded) {
511 wwin->flags.skip_next_animation = 1;
512 wUnshadeWindow(wwin);
514 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
515 wwin->old_geometry.x : wwin->frame_x;
516 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
517 wwin->old_geometry.y : wwin->frame_y;
518 wwin->flags.maximized = 0;
519 wWindowConfigure(wwin, restore_x, restore_y,
520 wwin->old_geometry.width, wwin->old_geometry.height);
522 #ifdef GNOME_STUFF
523 wGNOMEUpdateClientStateHint(wwin, False);
524 #endif
525 #ifdef KWM_HINTS
526 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
527 wKWMSendEventMessage(wwin, WKWMChangedClient);
528 #endif
530 #ifdef WMSOUND
531 wSoundPlay(WMSOUND_UNMAXIMIZE);
532 #endif
535 #ifdef ANIMATIONS
536 static void
537 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
538 int fx, int fy, int fw, int fh, int steps)
540 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
541 float cx, cy, cw, ch;
542 float xstep, ystep, wstep, hstep;
543 XPoint points[5];
544 float dx, dch, midy;
545 float angle, final_angle, delta;
547 xstep = (float)(fx-x)/steps;
548 ystep = (float)(fy-y)/steps;
549 wstep = (float)(fw-w)/steps;
550 hstep = (float)(fh-h)/steps;
552 cx = (float)x;
553 cy = (float)y;
554 cw = (float)w;
555 ch = (float)h;
557 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
558 delta = (float)(final_angle/FRAMES);
559 for (angle=0;; angle+=delta) {
560 if (angle > final_angle)
561 angle = final_angle;
563 dx = (cw/10) - ((cw/5) * sin(angle));
564 dch = (ch/2) * cos(angle);
565 midy = cy + (ch/2);
567 points[0].x = cx + dx; points[0].y = midy - dch;
568 points[1].x = cx + cw - dx; points[1].y = points[0].y;
569 points[2].x = cx + cw + dx; points[2].y = midy + dch;
570 points[3].x = cx - dx; points[3].y = points[2].y;
571 points[4].x = points[0].x; points[4].y = points[0].y;
573 XGrabServer(dpy);
574 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
575 XFlush(dpy);
576 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
577 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
578 #endif
580 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
581 XUngrabServer(dpy);
582 cx+=xstep;
583 cy+=ystep;
584 cw+=wstep;
585 ch+=hstep;
586 if (angle >= final_angle)
587 break;
590 XFlush(dpy);
592 #undef FRAMES
595 static void
596 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
597 int fx, int fy, int fw, int fh, int steps)
599 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
600 float cx, cy, cw, ch;
601 float xstep, ystep, wstep, hstep;
602 XPoint points[5];
603 float angle, final_angle, a, d, delta;
605 x += w/2;
606 y += h/2;
607 fx += fw/2;
608 fy += fh/2;
610 xstep = (float)(fx-x)/steps;
611 ystep = (float)(fy-y)/steps;
612 wstep = (float)(fw-w)/steps;
613 hstep = (float)(fh-h)/steps;
615 cx = (float)x;
616 cy = (float)y;
617 cw = (float)w;
618 ch = (float)h;
620 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
621 delta = (float)(final_angle/FRAMES);
622 for (angle=0;; angle+=delta) {
623 if (angle > final_angle)
624 angle = final_angle;
626 a = atan(ch/cw);
627 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
629 points[0].x = cx+cos(angle-a)*d;
630 points[0].y = cy+sin(angle-a)*d;
631 points[1].x = cx+cos(angle+a)*d;
632 points[1].y = cy+sin(angle+a)*d;
633 points[2].x = cx+cos(angle-a+WM_PI)*d;
634 points[2].y = cy+sin(angle-a+WM_PI)*d;
635 points[3].x = cx+cos(angle+a+WM_PI)*d;
636 points[3].y = cy+sin(angle+a+WM_PI)*d;
637 points[4].x = cx+cos(angle-a)*d;
638 points[4].y = cy+sin(angle-a)*d;
639 XGrabServer(dpy);
640 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
641 XFlush(dpy);
642 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
643 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
644 #endif
646 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
647 XUngrabServer(dpy);
648 cx+=xstep;
649 cy+=ystep;
650 cw+=wstep;
651 ch+=hstep;
652 if (angle >= final_angle)
653 break;
656 XFlush(dpy);
658 #undef FRAMES
661 static void
662 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
663 int fx, int fy, int fw, int fh, int steps)
665 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
666 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
667 float xstep, ystep, wstep, hstep;
668 int i, j;
670 xstep = (float)(fx-x)/steps;
671 ystep = (float)(fy-y)/steps;
672 wstep = (float)(fw-w)/steps;
673 hstep = (float)(fh-h)/steps;
675 for (j=0; j<FRAMES; j++) {
676 cx[j] = (float)x;
677 cy[j] = (float)y;
678 cw[j] = (float)w;
679 ch[j] = (float)h;
681 XGrabServer(dpy);
682 for (i=0; i<steps; i++) {
683 for (j=0; j<FRAMES; j++) {
684 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
685 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
687 XFlush(dpy);
688 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
689 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
690 #endif
691 for (j=0; j<FRAMES; j++) {
692 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
693 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
694 if (j<FRAMES-1) {
695 cx[j]=cx[j+1];
696 cy[j]=cy[j+1];
697 cw[j]=cw[j+1];
698 ch[j]=ch[j+1];
699 } else {
700 cx[j]+=xstep;
701 cy[j]+=ystep;
702 cw[j]+=wstep;
703 ch[j]+=hstep;
708 for (j=0; j<FRAMES; j++) {
709 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
710 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
712 XFlush(dpy);
713 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
714 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
715 #endif
716 for (j=0; j<FRAMES; j++) {
717 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
718 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
721 XUngrabServer(dpy);
723 #undef FRAMES
726 static void
727 animateResize(WScreen *scr, int x, int y, int w, int h,
728 int fx, int fy, int fw, int fh, int hiding)
730 int style = wPreferences.iconification_style; /* Catch the value */
731 int steps, k;
733 if (style == WIS_NONE)
734 return;
736 if (style == WIS_RANDOM) {
737 style = rand()%3;
740 k = (hiding ? 2 : 3);
741 switch(style) {
742 case WIS_TWIST:
743 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
744 if (steps>0)
745 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
746 break;
747 case WIS_FLIP:
748 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
749 if (steps>0)
750 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
751 break;
752 case WIS_ZOOM:
753 default:
754 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
755 if (steps>0)
756 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
757 break;
760 #endif /* ANIMATIONS */
763 static void
764 flushExpose()
766 XEvent tmpev;
768 while (XCheckTypedEvent(dpy, Expose, &tmpev))
769 WMHandleEvent(&tmpev);
770 XSync(dpy, 0);
773 static void
774 unmapTransientsFor(WWindow *wwin)
776 WWindow *tmp;
779 tmp = wwin->screen_ptr->focused_window;
780 while (tmp) {
781 /* unmap the transients for this transient */
782 if (tmp!=wwin && tmp->transient_for == wwin->client_win
783 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
784 || tmp->flags.shaded)) {
785 unmapTransientsFor(tmp);
786 tmp->flags.miniaturized = 1;
787 if (!tmp->flags.shaded) {
788 wWindowUnmap(tmp);
789 } else {
790 XUnmapWindow(dpy, tmp->frame->core->window);
793 if (!tmp->flags.shaded)
795 wClientSetState(tmp, IconicState, None);
796 #ifdef KWM_HINTS
797 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
798 wKWMSendEventMessage(tmp, WKWMRemoveWindow);
799 tmp->flags.kwm_hidden_for_modules = 1;
800 #endif
802 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
805 tmp = tmp->prev;
810 static void
811 mapTransientsFor(WWindow *wwin)
813 WWindow *tmp;
815 tmp = wwin->screen_ptr->focused_window;
816 while (tmp) {
817 /* recursively map the transients for this transient */
818 if (tmp!=wwin && tmp->transient_for == wwin->client_win
819 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
820 && tmp->icon==NULL) {
821 mapTransientsFor(tmp);
822 tmp->flags.miniaturized = 0;
823 if (!tmp->flags.shaded) {
824 wWindowMap(tmp);
825 } else {
826 XMapWindow(dpy, tmp->frame->core->window);
828 tmp->flags.semi_focused = 0;
830 if (!tmp->flags.shaded)
832 wClientSetState(tmp, NormalState, None);
833 #ifdef KWM_HINTS
834 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
835 if (tmp->flags.kwm_hidden_for_modules) {
836 wKWMSendEventMessage(tmp, WKWMAddWindow);
837 tmp->flags.kwm_hidden_for_modules = 0;
839 #endif
841 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
844 tmp = tmp->prev;
848 #if 0
849 static void
850 setupIconGrabs(WIcon *icon)
852 /* setup passive grabs on the icon */
853 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
854 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
855 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
856 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
857 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
858 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
859 XSync(dpy, 0);
861 #endif
863 static WWindow*
864 recursiveTransientFor(WWindow *wwin)
866 int i;
868 if (!wwin)
869 return None;
871 /* hackish way to detect transient_for cycle */
872 i = wwin->screen_ptr->window_count+1;
874 while (wwin && wwin->transient_for != None && i>0) {
875 wwin = wWindowFor(wwin->transient_for);
876 i--;
878 if (i==0 && wwin) {
879 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
880 wwin->frame->title);
881 return NULL;
884 return wwin;
887 #if 0
888 static void
889 removeIconGrabs(WIcon *icon)
891 /* remove passive grabs on the icon */
892 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
893 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
894 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
895 XSync(dpy, 0);
897 #endif
900 void
901 wIconifyWindow(WWindow *wwin)
903 XWindowAttributes attribs;
904 int present;
907 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
908 /* the window doesn't exist anymore */
909 return;
912 if (wwin->flags.miniaturized) {
913 return;
917 if (wwin->transient_for!=None) {
918 WWindow *owner = wWindowFor(wwin->transient_for);
920 if (owner && owner->flags.miniaturized)
921 return;
924 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
926 /* if the window is in another workspace, simplify process */
927 if (present) {
928 /* icon creation may take a while */
929 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
930 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
931 GrabModeAsync, None, None, CurrentTime);
934 if (!wPreferences.disable_miniwindows) {
935 if (!wwin->flags.icon_moved) {
936 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y);
938 wwin->icon = wIconCreate(wwin);
940 wwin->icon->mapped = 1;
943 wwin->flags.miniaturized = 1;
944 wwin->flags.mapped = 0;
946 /* unmap transients */
948 unmapTransientsFor(wwin);
950 if (present) {
951 #ifdef WMSOUND
952 wSoundPlay(WMSOUND_ICONIFY);
953 #endif
955 XUngrabPointer(dpy, CurrentTime);
956 wWindowUnmap(wwin);
957 /* let all Expose events arrive so that we can repaint
958 * something before the animation starts (and the server is grabbed) */
959 XSync(dpy, 0);
961 if (wPreferences.disable_miniwindows)
962 wClientSetState(wwin, IconicState, None);
963 else
964 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
966 flushExpose();
967 #ifdef ANIMATIONS
968 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
969 && !wPreferences.no_animations) {
970 int ix, iy, iw, ih;
972 if (!wPreferences.disable_miniwindows) {
973 ix = wwin->icon_x;
974 iy = wwin->icon_y;
975 iw = wwin->icon->core->width;
976 ih = wwin->icon->core->height;
977 } else {
978 #ifdef KWM_HINTS
979 WArea area;
981 if (wKWMGetIconGeometry(wwin, &area)) {
982 ix = area.x1;
983 iy = area.y1;
984 iw = area.x2 - ix;
985 ih = area.y2 - iy;
986 } else
987 #endif /* KWM_HINTS */
989 ix = 0;
990 iy = 0;
991 iw = wwin->screen_ptr->scr_width;
992 ih = wwin->screen_ptr->scr_height;
995 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
996 wwin->frame->core->width, wwin->frame->core->height,
997 ix, iy, iw, ih, False);
999 #endif
1002 wwin->flags.skip_next_animation = 0;
1004 if (!wPreferences.disable_miniwindows) {
1006 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
1007 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1009 XMapWindow(dpy, wwin->icon->core->window);
1011 AddToStackList(wwin->icon->core);
1013 wLowerFrame(wwin->icon->core);
1016 if (present) {
1017 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1020 * It doesn't seem to be working and causes button event hangup
1021 * when deiconifying a transient window.
1022 setupIconGrabs(wwin->icon);
1024 if ((wwin->flags.focused
1025 || (owner && wwin->client_win == owner->client_win))
1026 && wPreferences.focus_mode==WKF_CLICK) {
1027 WWindow *tmp;
1029 tmp = wwin->prev;
1030 while (tmp) {
1031 if (!WFLAGP(tmp, no_focusable)
1032 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1033 && (wwin->frame->workspace == tmp->frame->workspace))
1034 break;
1035 tmp = tmp->prev;
1037 wSetFocusTo(wwin->screen_ptr, tmp);
1038 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1039 wSetFocusTo(wwin->screen_ptr, NULL);
1042 #ifdef ANIMATIONS
1043 if (!wwin->screen_ptr->flags.startup) {
1044 Window clientwin = wwin->client_win;
1046 XSync(dpy, 0);
1047 processEvents(XPending(dpy));
1049 /* the window can disappear while doing the processEvents() */
1050 if (!wWindowFor(clientwin))
1051 return;
1053 #endif
1057 if (wwin->flags.selected && !wPreferences.disable_miniwindows)
1058 wIconSelect(wwin->icon);
1060 #ifdef GNOME_STUFF
1061 wGNOMEUpdateClientStateHint(wwin, False);
1062 #endif
1063 #ifdef KWM_HINTS
1064 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1065 wKWMSendEventMessage(wwin, WKWMChangedClient);
1066 #endif
1068 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1074 void
1075 wDeiconifyWindow(WWindow *wwin)
1077 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1079 if (!wwin->flags.miniaturized)
1080 return;
1082 if (wwin->transient_for != None
1083 && wwin->transient_for != wwin->screen_ptr->root_win) {
1084 WWindow *owner = recursiveTransientFor(wwin);
1086 if (owner && owner->flags.miniaturized) {
1087 wDeiconifyWindow(owner);
1088 wSetFocusTo(wwin->screen_ptr, wwin);
1089 wRaiseFrame(wwin->frame->core);
1090 return;
1094 wwin->flags.miniaturized = 0;
1095 if (!wwin->flags.shaded)
1096 wwin->flags.mapped = 1;
1098 if (!wPreferences.disable_miniwindows) {
1099 if (wwin->icon->selected)
1100 wIconSelect(wwin->icon);
1102 XUnmapWindow(dpy, wwin->icon->core->window);
1105 #ifdef WMSOUND
1106 wSoundPlay(WMSOUND_DEICONIFY);
1107 #endif
1109 /* if the window is in another workspace, do it silently */
1110 #ifdef ANIMATIONS
1111 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1112 && !wwin->flags.skip_next_animation) {
1113 int ix, iy, iw, ih;
1115 if (!wPreferences.disable_miniwindows) {
1116 ix = wwin->icon_x;
1117 iy = wwin->icon_y;
1118 iw = wwin->icon->core->width;
1119 ih = wwin->icon->core->height;
1120 } else {
1121 #ifdef KWM_HINTS
1122 WArea area;
1124 if (wKWMGetIconGeometry(wwin, &area)) {
1125 ix = area.x1;
1126 iy = area.y1;
1127 iw = area.x2 - ix;
1128 ih = area.y2 - iy;
1129 } else
1130 #endif /* KWM_HINTS */
1132 ix = 0;
1133 iy = 0;
1134 iw = wwin->screen_ptr->scr_width;
1135 ih = wwin->screen_ptr->scr_height;
1138 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1139 wwin->frame_x, wwin->frame_y,
1140 wwin->frame->core->width, wwin->frame->core->height,
1141 False);
1143 #endif /* ANIMATIONS */
1144 wwin->flags.skip_next_animation = 0;
1145 XGrabServer(dpy);
1146 if (!wwin->flags.shaded) {
1147 XMapWindow(dpy, wwin->client_win);
1149 XMapWindow(dpy, wwin->frame->core->window);
1150 wRaiseFrame(wwin->frame->core);
1151 if (!wwin->flags.shaded) {
1152 wClientSetState(wwin, NormalState, None);
1154 mapTransientsFor(wwin);
1156 if (!wPreferences.disable_miniwindows) {
1157 RemoveFromStackList(wwin->icon->core);
1158 /* removeIconGrabs(wwin->icon);*/
1159 wIconDestroy(wwin->icon);
1160 wwin->icon = NULL;
1162 XUngrabServer(dpy);
1164 if (wPreferences.focus_mode==WKF_CLICK)
1165 wSetFocusTo(wwin->screen_ptr, wwin);
1167 #ifdef ANIMATIONS
1168 if (!wwin->screen_ptr->flags.startup) {
1169 Window clientwin = wwin->client_win;
1171 XSync(dpy, 0);
1172 processEvents(XPending(dpy));
1174 if (!wWindowFor(clientwin))
1175 return;
1177 #endif
1179 if (wPreferences.auto_arrange_icons) {
1180 wArrangeIcons(wwin->screen_ptr, True);
1183 #ifdef GNOME_STUFF
1184 wGNOMEUpdateClientStateHint(wwin, False);
1185 #endif
1186 #ifdef KWM_HINTS
1187 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1188 wKWMSendEventMessage(wwin, WKWMChangedClient);
1189 #endif
1191 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1196 static void
1197 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1199 if (wwin->flags.miniaturized) {
1200 if (wwin->icon) {
1201 XUnmapWindow(dpy, wwin->icon->core->window);
1202 wwin->icon->mapped = 0;
1204 wwin->flags.hidden = 1;
1205 #ifdef GNOME_STUFF
1206 wGNOMEUpdateClientStateHint(wwin, False);
1207 #endif
1209 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1211 return;
1214 if (wwin->flags.inspector_open) {
1215 wHideInspectorForWindow(wwin);
1218 wwin->flags.hidden = 1;
1219 wWindowUnmap(wwin);
1221 wClientSetState(wwin, IconicState, icon->icon_win);
1222 flushExpose();
1223 #ifdef WMSOUND
1224 wSoundPlay(WMSOUND_HIDE);
1225 #endif
1226 #ifdef ANIMATIONS
1227 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1228 !wwin->flags.skip_next_animation && animate) {
1229 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1230 wwin->frame->core->width, wwin->frame->core->height,
1231 icon_x, icon_y, icon->core->width, icon->core->height,
1232 True);
1234 #endif
1235 wwin->flags.skip_next_animation = 0;
1237 #ifdef GNOME_STUFF
1238 wGNOMEUpdateClientStateHint(wwin, False);
1239 #endif
1241 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1246 void
1247 wHideOtherApplications(WWindow *awin)
1249 WWindow *wwin;
1250 WApplication *tapp;
1251 #ifdef REDUCE_APPICONS
1252 char *tinstance, *tclass;
1253 unsigned int brokenwin = 0, match = 0;
1254 #endif
1256 if (!awin)
1257 return;
1258 wwin = awin->screen_ptr->focused_window;
1260 #ifdef REDUCE_APPICONS
1261 if (awin->wm_instance == NULL || awin->wm_class == NULL)
1262 brokenwin++;
1263 #endif
1265 while (wwin) {
1266 if (wwin!=awin
1267 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1268 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1269 && !wwin->flags.internal_window
1270 && wGetWindowOfInspectorForWindow(wwin) != awin
1271 && !WFLAGP(wwin, no_hide_others)) {
1273 #ifdef REDUCE_APPICONS
1274 match = 0;
1275 if (!brokenwin) {
1276 if ((tinstance = wwin->wm_instance) == NULL)
1277 tinstance = "";
1278 if ((tclass = wwin->wm_class) == NULL)
1279 tclass = "";
1280 if ((strcmp(awin->wm_instance, tinstance) == 0) &&
1281 (strcmp(awin->wm_class, tclass) == 0) )
1282 match++;
1284 #endif
1286 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1287 if (!WFLAGP(wwin, no_miniaturizable)) {
1288 wwin->flags.skip_next_animation = 1;
1289 wIconifyWindow(wwin);
1291 } else if (wwin->main_window!=None
1292 #ifndef REDUCE_APPICONS
1293 && awin->main_window != wwin->main_window) {
1294 #else
1295 && (awin->main_window != wwin->main_window && !match)) {
1296 #endif
1297 tapp = wApplicationOf(wwin->main_window);
1298 if (tapp) {
1299 tapp->flags.skip_next_animation = 1;
1300 wHideApplication(tapp);
1301 } else {
1302 if (!WFLAGP(wwin, no_miniaturizable)) {
1303 wwin->flags.skip_next_animation = 1;
1304 wIconifyWindow(wwin);
1309 wwin = wwin->prev;
1312 wSetFocusTo(awin->screen_ptr, awin);
1318 void
1319 wHideApplication(WApplication *wapp)
1321 #ifdef REDUCE_APPICONS
1322 WApplication *tapp;
1323 char *tinstance, *tclass;
1324 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1325 #endif
1326 WScreen *scr;
1327 WWindow *wlist;
1328 int hadfocus;
1330 if (!wapp) {
1331 wwarning("trying to hide a non grouped window");
1332 return;
1334 if (!wapp->main_window_desc) {
1335 wwarning("group leader not found for window group");
1336 return;
1338 #ifdef REDUCE_APPICONS
1339 if ((wapp->main_window_desc->wm_instance == NULL) ||
1340 (wapp->main_window_desc->wm_class == NULL))
1341 nowmhints++;
1342 #endif
1343 scr = wapp->main_window_desc->screen_ptr;
1344 hadfocus = 0;
1345 wlist = scr->focused_window;
1346 if (!wlist)
1347 return;
1349 if (wlist->main_window == wapp->main_window)
1350 wapp->last_focused = wlist;
1351 else
1352 wapp->last_focused = NULL;
1353 while (wlist) {
1354 #ifdef REDUCE_APPICONS
1355 matchwmhints = matchworkspace = 0;
1356 if (!nowmhints) {
1357 tapp = wApplicationOf(wlist->main_window);
1358 tinstance = tclass = NULL;
1359 if (tapp) {
1360 if (tapp->main_window_desc) {
1361 tinstance = tapp->main_window_desc->wm_instance;
1362 tclass = tapp->main_window_desc->wm_class;
1365 if (tapp == NULL || tinstance == NULL || tclass == NULL) {
1366 /* Should never reach here */
1367 tinstance = "";
1368 tclass = "";
1370 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0) &&
1371 (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1372 matchwmhints++;
1374 if (wlist->frame) {
1375 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1376 matchworkspace++;
1378 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1379 matchworkspace) {
1380 #ifdef I_HATE_THIS
1382 #endif
1383 #else
1384 if (wlist->main_window == wapp->main_window) {
1385 #endif
1386 if (wlist->flags.focused) {
1387 hadfocus = 1;
1389 if (wapp->app_icon)
1390 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1391 wapp->app_icon->y_pos, wlist,
1392 !wapp->flags.skip_next_animation);
1394 wlist = wlist->prev;
1397 wapp->flags.skip_next_animation = 0;
1399 if (hadfocus) {
1400 if (wPreferences.focus_mode==WKF_CLICK) {
1401 wlist = scr->focused_window;
1402 while (wlist) {
1403 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1404 && (wlist->flags.mapped || wlist->flags.shaded))
1405 break;
1406 wlist = wlist->prev;
1408 wSetFocusTo(scr, wlist);
1409 } else {
1410 wSetFocusTo(scr, NULL);
1414 wapp->flags.hidden = 1;
1416 if(wPreferences.auto_arrange_icons) {
1417 wArrangeIcons(scr, True);
1419 #ifdef HIDDENDOT
1420 if (wapp->app_icon)
1421 wAppIconPaint(wapp->app_icon);
1422 #endif
1428 static void
1429 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1430 int bringToCurrentWS)
1432 if (bringToCurrentWS)
1433 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1435 wwin->flags.hidden=0;
1436 wwin->flags.mapped=1;
1438 #ifdef WMSOUND
1439 wSoundPlay(WMSOUND_UNHIDE);
1440 #endif
1441 #ifdef ANIMATIONS
1442 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1443 && animate) {
1444 animateResize(wwin->screen_ptr, icon_x, icon_y,
1445 icon->core->width, icon->core->height,
1446 wwin->frame_x, wwin->frame_y,
1447 wwin->frame->core->width, wwin->frame->core->height,
1448 True);
1450 #endif
1451 wwin->flags.skip_next_animation = 0;
1452 XMapWindow(dpy, wwin->client_win);
1453 XMapWindow(dpy, wwin->frame->core->window);
1454 wClientSetState(wwin, NormalState, None);
1455 wRaiseFrame(wwin->frame->core);
1456 if (wwin->flags.inspector_open) {
1457 wUnhideInspectorForWindow(wwin);
1460 #ifdef GNOME_STUFF
1461 wGNOMEUpdateClientStateHint(wwin, False);
1462 #endif
1464 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1469 void
1470 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1472 WScreen *scr;
1473 WWindow *wlist, *next;
1474 WWindow *focused=NULL;
1475 #ifdef REDUCE_APPICONS
1476 char *tinstance, *tclass;
1477 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1478 #endif
1480 if (!wapp) {
1481 return;
1484 #ifdef REDUCE_APPICONS
1485 if ((wapp->main_window_desc->wm_class == NULL) ||
1486 (wapp->main_window_desc->wm_instance == NULL))
1487 nowmhints++;
1488 #endif
1490 scr = wapp->main_window_desc->screen_ptr;
1491 wlist = scr->focused_window;
1492 if (!wlist) return;
1493 /* goto beginning of list */
1494 while (wlist->prev)
1495 wlist = wlist->prev;
1497 while (wlist) {
1498 next = wlist->next;
1500 #ifndef REDUCE_APPICONS
1501 if (wlist->main_window == wapp->main_window) {
1502 #else
1503 matchwmhints = matchworkspace = 0;
1504 if (!nowmhints) {
1505 if ((tinstance = wlist->wm_instance) == NULL)
1506 tinstance = "";
1507 if ((tclass = wlist->wm_class) == NULL)
1508 tclass = "";
1509 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0)
1510 && (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1511 matchwmhints++;
1513 if (wlist->frame) {
1514 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1515 matchworkspace++;
1518 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1519 matchworkspace) {
1520 #endif
1521 if (wlist->flags.focused)
1522 focused = wlist;
1523 else if (!focused || !focused->flags.focused)
1524 focused = wlist;
1526 if (wlist->flags.miniaturized && wlist->icon) {
1527 if (bringToCurrentWS || wPreferences.sticky_icons
1528 || wlist->frame->workspace == scr->current_workspace) {
1529 if (!wlist->icon->mapped) {
1530 XMapWindow(dpy, wlist->icon->core->window);
1531 wlist->icon->mapped = 1;
1533 wlist->flags.hidden = 0;
1535 UpdateSwitchMenu(scr, wlist, ACTION_CHANGE_STATE);
1537 if (wlist->frame->workspace != scr->current_workspace)
1538 wWindowChangeWorkspace(wlist, scr->current_workspace);
1540 if (miniwindows) {
1541 wDeiconifyWindow(wlist);
1543 } else if (wlist->flags.hidden) {
1544 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1545 wapp->app_icon->y_pos, wlist,
1546 !wapp->flags.skip_next_animation,
1547 bringToCurrentWS);
1548 } else {
1549 if (bringToCurrentWS
1550 && wlist->frame->workspace != scr->current_workspace) {
1551 wWindowChangeWorkspace(wlist, scr->current_workspace);
1553 wRaiseFrame(wlist->frame->core);
1556 wlist = next;
1559 wapp->flags.skip_next_animation = 0;
1560 wapp->flags.hidden = 0;
1562 if (focused)
1563 wSetFocusTo(scr, focused);
1564 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1565 wSetFocusTo(scr, wapp->last_focused);
1566 wapp->last_focused = NULL;
1567 if (wPreferences.auto_arrange_icons) {
1568 wArrangeIcons(scr, True);
1570 #ifdef HIDDENDOT
1571 wAppIconPaint(wapp->app_icon);
1572 #endif
1577 void
1578 wShowAllWindows(WScreen *scr)
1580 WWindow *wwin, *old_foc;
1581 WApplication *wapp;
1583 old_foc = wwin = scr->focused_window;
1584 while (wwin) {
1585 if (!wwin->flags.internal_window &&
1586 (scr->current_workspace == wwin->frame->workspace
1587 || IS_OMNIPRESENT(wwin))) {
1588 if (wwin->flags.miniaturized) {
1589 wwin->flags.skip_next_animation = 1;
1590 wDeiconifyWindow(wwin);
1591 } else if (wwin->flags.hidden) {
1592 wapp = wApplicationOf(wwin->main_window);
1593 if (wapp) {
1594 wUnhideApplication(wapp, False, False);
1595 } else {
1596 wwin->flags.skip_next_animation = 1;
1597 wDeiconifyWindow(wwin);
1601 wwin = wwin->prev;
1603 wSetFocusTo(scr, old_foc);
1604 /*wRaiseFrame(old_foc->frame->core);*/
1608 void
1609 wRefreshDesktop(WScreen *scr)
1611 Window win;
1612 XSetWindowAttributes attr;
1614 attr.backing_store = NotUseful;
1615 attr.save_under = False;
1616 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1617 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1618 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1619 &attr);
1620 XMapRaised(dpy, win);
1621 XDestroyWindow(dpy, win);
1622 XFlush(dpy);
1626 void
1627 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1629 WWindow *wwin;
1630 WAppIcon *aicon;
1631 int pf; /* primary axis */
1632 int sf; /* secondary axis */
1633 int fullW;
1634 int fullH;
1635 int pi, si;
1636 int sx1, sx2, sy1, sy2; /* screen boundary */
1637 int sw, sh;
1638 int xo, yo;
1639 int xs, ys;
1640 int isize = wPreferences.icon_size;
1643 * Find out screen boundaries.
1645 sx1 = 0;
1646 sy1 = 0;
1647 sx2 = scr->scr_width;
1648 sy2 = scr->scr_height;
1649 if (scr->dock) {
1650 if (scr->dock->on_right_side)
1651 sx2 -= isize + DOCK_EXTRA_SPACE;
1652 else
1653 sx1 += isize + DOCK_EXTRA_SPACE;
1656 sw = isize * (scr->scr_width/isize);
1657 sh = isize * (scr->scr_height/isize);
1658 fullW = (sx2-sx1)/isize;
1659 fullH = (sy2-sy1)/isize;
1661 /* icon yard boundaries */
1662 if (wPreferences.icon_yard & IY_VERT) {
1663 pf = fullH;
1664 sf = fullW;
1665 } else {
1666 pf = fullW;
1667 sf = fullH;
1669 if (wPreferences.icon_yard & IY_RIGHT) {
1670 xo = sx2 - isize;
1671 xs = -1;
1672 } else {
1673 xo = sx1;
1674 xs = 1;
1676 if (wPreferences.icon_yard & IY_TOP) {
1677 yo = sy1;
1678 ys = 1;
1679 } else {
1680 yo = sy2 - isize;
1681 ys = -1;
1684 /* arrange icons putting the most recently focused window
1685 * as the last icon */
1686 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1687 : xo + xs*(pi*isize))
1688 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1689 : yo + ys*(si*isize))
1691 /* arrange application icons */
1692 aicon = scr->app_icon_list;
1693 /* reverse them to avoid unnecessarily sliding of icons */
1694 while (aicon && aicon->next)
1695 aicon = aicon->next;
1697 pi = 0;
1698 si = 0;
1699 while (aicon) {
1700 if (!aicon->docked) {
1701 if (aicon->x_pos != X || aicon->y_pos != Y) {
1702 #ifdef ANIMATIONS
1703 if (!wPreferences.no_animations) {
1704 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1705 X, Y);
1707 #endif /* ANIMATIONS */
1709 wAppIconMove(aicon, X, Y);
1710 pi++;
1712 /* we reversed the order so we use prev */
1713 aicon = aicon->prev;
1714 if (pi >= pf) {
1715 pi=0;
1716 si++;
1720 /* arrange miniwindows */
1722 wwin = scr->focused_window;
1723 /* reverse them to avoid unnecessarily shuffling */
1724 while (wwin && wwin->prev)
1725 wwin = wwin->prev;
1727 while (wwin) {
1728 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1729 (wwin->frame->workspace==scr->current_workspace ||
1730 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1732 if (arrangeAll || !wwin->flags.icon_moved) {
1733 if (wwin->icon_x != X || wwin->icon_y != Y) {
1734 #ifdef ANIMATIONS
1735 if (wPreferences.no_animations) {
1736 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1737 } else {
1738 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1739 wwin->icon_y, X, Y);
1741 #else
1742 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1743 #endif /* ANIMATIONS */
1745 wwin->icon_x = X;
1746 wwin->icon_y = Y;
1747 pi++;
1750 if (arrangeAll) {
1751 wwin->flags.icon_moved = 0;
1753 /* we reversed the order, so we use next */
1754 wwin = wwin->next;
1755 if (pi >= pf) {
1756 pi=0;
1757 si++;
1763 void
1764 wSelectWindow(WWindow *wwin, Bool flag)
1766 WScreen *scr = wwin->screen_ptr;
1768 if (flag) {
1769 wwin->flags.selected = 1;
1770 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1772 if (WFLAGP(wwin, no_border)) {
1773 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1774 FRAME_BORDER_WIDTH);
1777 if (!scr->selected_windows)
1778 scr->selected_windows = WMCreateBag(4);
1779 WMPutInBag(scr->selected_windows, wwin);
1780 } else {
1781 wwin->flags.selected = 0;
1782 XSetWindowBorder(dpy, wwin->frame->core->window,
1783 scr->frame_border_pixel);
1785 if (WFLAGP(wwin, no_border)) {
1786 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1789 if (scr->selected_windows) {
1790 WMRemoveFromBag(scr->selected_windows, wwin);
1796 void
1797 wMakeWindowVisible(WWindow *wwin)
1799 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1800 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1802 if (wwin->flags.shaded) {
1803 wUnshadeWindow(wwin);
1805 if (wwin->flags.hidden) {
1806 WApplication *app;
1808 app = wApplicationOf(wwin->main_window);
1809 if (app)
1810 wUnhideApplication(app, False, False);
1811 } else if (wwin->flags.miniaturized) {
1812 wDeiconifyWindow(wwin);
1813 } else {
1814 if (!WFLAGP(wwin, no_focusable))
1815 wSetFocusTo(wwin->screen_ptr, wwin);
1816 wRaiseFrame(wwin->frame->core);