*** empty log message ***
[wmaker-crm.git] / src / actions.c
blob8dbf5ef78502a6d4d60a4417726d2d2cc89b778d
1 /* action.c- misc. window commands (miniaturize, hide etc.)
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
23 #include "wconfig.h"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <math.h>
32 #include <time.h>
34 #include "WindowMaker.h"
35 #include "wcore.h"
36 #include "framewin.h"
37 #include "window.h"
38 #include "client.h"
39 #include "icon.h"
40 #include "funcs.h"
41 #include "application.h"
42 #include "actions.h"
43 #include "stacking.h"
44 #include "appicon.h"
45 #include "dock.h"
46 #include "appmenu.h"
47 #include "winspector.h"
48 #include "list.h"
49 #include "workspace.h"
51 #ifdef GNOME_STUFF
52 # include "gnome.h"
53 #endif
54 #ifdef KWM_HINTS
55 # include "kwm.h"
56 #endif
58 #ifdef WMSOUND
59 #include "wmsound.h"
60 #endif
63 /****** Global Variables ******/
64 extern Time LastTimestamp;
65 extern Time LastFocusChange;
67 extern Cursor wCursor[WCUR_LAST];
69 extern WPreferences wPreferences;
71 extern Atom _XA_WM_TAKE_FOCUS;
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 WWindow *focused=scr->focused_window;
137 int timestamp=LastTimestamp;
138 WApplication *oapp=NULL, *napp=NULL;
139 int wasfocused;
141 LastFocusChange = timestamp;
144 * This is a hack, because XSetInputFocus() should have a proper
145 * timestamp instead of CurrentTime but it seems that some times
146 * clients will not receive focus properly that way.
147 if (ignoreTimestamp)
149 timestamp = CurrentTime;
151 if (focused)
152 oapp = wApplicationOf(focused->main_window);
154 if (wwin == NULL) {
155 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
156 if (focused) {
157 wWindowUnfocus(focused);
159 if (oapp) {
160 wAppMenuUnmap(oapp->menu);
161 #ifdef NEWAPPICON
162 wApplicationDeactivate(oapp);
163 #endif
165 #ifdef KWM_HINTS
166 wKWMUpdateActiveWindowHint(scr);
167 wKWMSendEventMessage(NULL, WKWMFocusWindow);
168 #endif
169 return;
171 wasfocused = wwin->flags.focused;
172 napp = wApplicationOf(wwin->main_window);
174 /* remember last workspace where the app has been */
175 if (napp)
176 napp->last_workspace = wwin->screen_ptr->current_workspace;
178 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
179 /* install colormap if colormap mode is lock mode */
180 if (wPreferences.colormap_mode==WKF_CLICK)
181 wColormapInstallForWindow(scr, wwin);
183 /* set input focus */
184 switch (wwin->focus_mode) {
185 case WFM_NO_INPUT:
186 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
187 break;
189 case WFM_PASSIVE:
190 case WFM_LOCALLY_ACTIVE:
191 XSetInputFocus(dpy, wwin->client_win, RevertToParent, timestamp);
192 break;
194 case WFM_GLOBALLY_ACTIVE:
195 break;
197 XFlush(dpy);
198 if (wwin->protocols.TAKE_FOCUS) {
199 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
201 XSync(dpy, False);
202 } else {
203 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
205 if (WFLAGP(wwin, no_focusable))
206 return;
208 /* if this is not the focused window focus it */
209 if (focused!=wwin) {
210 /* change the focus window list order */
211 if (wwin->prev)
212 wwin->prev->next = wwin->next;
214 if (wwin->next)
215 wwin->next->prev = wwin->prev;
217 wwin->prev = focused;
218 focused->next = wwin;
219 wwin->next = NULL;
220 scr->focused_window = wwin;
222 if (oapp && oapp != napp) {
223 wAppMenuUnmap(oapp->menu);
224 #ifdef NEWAPPICON
225 wApplicationDeactivate(oapp);
226 #endif
230 wWindowFocus(wwin, focused);
232 if (napp && !wasfocused) {
233 #ifdef USER_MENU
234 wUserMenuRefreshInstances(napp->menu, wwin);
235 #endif /* USER_MENU */
237 wAppMenuMap(napp->menu, wwin);
238 #ifdef NEWAPPICON
239 wApplicationActivate(napp);
240 #endif
242 #ifdef KWM_HINTS
243 wKWMUpdateActiveWindowHint(scr);
244 wKWMSendEventMessage(wwin, WKWMFocusWindow);
245 #endif
246 XFlush(dpy);
250 void
251 wShadeWindow(WWindow *wwin)
253 time_t time0 = time(NULL);
254 #ifdef ANIMATIONS
255 int y, s, w, h;
256 #endif
258 if (wwin->flags.shaded)
259 return;
261 XLowerWindow(dpy, wwin->client_win);
263 #ifdef WMSOUND
264 wSoundPlay(WMSOUND_SHADE);
265 #endif
267 #ifdef ANIMATIONS
268 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
269 && !wPreferences.no_animations) {
270 /* do the shading animation */
271 h = wwin->frame->core->height;
272 s = h/SHADE_STEPS;
273 if (s < 1) s=1;
274 w = wwin->frame->core->width;
275 y = wwin->frame->top_width;
276 while (h>wwin->frame->top_width+1) {
277 XMoveWindow(dpy, wwin->client_win, 0, y);
278 XResizeWindow(dpy, wwin->frame->core->window, w, h);
279 XFlush(dpy);
281 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
282 break;
284 if (SHADE_DELAY > 0)
285 wusleep(SHADE_DELAY*1000L);
286 h-=s;
287 y-=s;
289 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
291 #endif /* ANIMATIONS */
293 wwin->flags.skip_next_animation = 0;
294 wwin->flags.shaded = 1;
295 wwin->flags.mapped = 0;
296 /* prevent window withdrawal when getting UnmapNotify */
297 XSelectInput(dpy, wwin->client_win,
298 wwin->event_mask & ~StructureNotifyMask);
299 XUnmapWindow(dpy, wwin->client_win);
300 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
302 /* for the client it's just like iconification */
303 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
304 wwin->frame->top_width - 1);
306 wwin->client.y = wwin->frame_y - wwin->client.height
307 + wwin->frame->top_width;
308 wWindowSynthConfigureNotify(wwin);
311 wClientSetState(wwin, IconicState, None);
314 #ifdef GNOME_STUFF
315 wGNOMEUpdateClientStateHint(wwin, False);
316 #endif
317 #ifdef KWM_HINTS
318 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
319 wKWMSendEventMessage(wwin, WKWMChangedClient);
320 #endif
321 /* update window list to reflect shaded state */
322 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
324 #ifdef ANIMATIONS
325 if (!wwin->screen_ptr->flags.startup) {
326 /* Look at processEvents() for reason of this code. */
327 XSync(dpy, 0);
328 processEvents(XPending(dpy));
330 #endif
334 void
335 wUnshadeWindow(WWindow *wwin)
337 time_t time0 = time(NULL);
338 #ifdef ANIMATIONS
339 int y, s, w, h;
340 #endif /* ANIMATIONS */
343 if (!wwin->flags.shaded)
344 return;
346 wwin->flags.shaded = 0;
347 wwin->flags.mapped = 1;
348 XMapWindow(dpy, wwin->client_win);
350 #ifdef WMSOUND
351 wSoundPlay(WMSOUND_UNSHADE);
352 #endif
354 #ifdef ANIMATIONS
355 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
356 /* do the shading animation */
357 h = wwin->frame->top_width + wwin->frame->bottom_width;
358 y = wwin->frame->top_width - wwin->client.height;
359 s = abs(y)/SHADE_STEPS;
360 if (s<1) s=1;
361 w = wwin->frame->core->width;
362 XMoveWindow(dpy, wwin->client_win, 0, y);
363 if (s>0) {
364 while (h < wwin->client.height + wwin->frame->top_width
365 + wwin->frame->bottom_width) {
366 XResizeWindow(dpy, wwin->frame->core->window, w, h);
367 XMoveWindow(dpy, wwin->client_win, 0, y);
368 XSync(dpy, 0);
369 if (SHADE_DELAY > 0)
370 wusleep(SHADE_DELAY*2000L/3);
371 h+=s;
372 y+=s;
374 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
375 break;
378 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
380 #endif /* ANIMATIONS */
382 wwin->flags.skip_next_animation = 0;
383 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
384 wwin->frame->top_width + wwin->client.height
385 + wwin->frame->bottom_width);
387 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
388 wWindowSynthConfigureNotify(wwin);
391 wClientSetState(wwin, NormalState, None);
393 /* if the window is focused, set the focus again as it was disabled during
394 * shading */
395 if (wwin->flags.focused)
396 wSetFocusTo(wwin->screen_ptr, wwin);
398 #ifdef GNOME_STUFF
399 wGNOMEUpdateClientStateHint(wwin, False);
400 #endif
401 #ifdef KWM_HINTS
402 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
403 wKWMSendEventMessage(wwin, WKWMChangedClient);
404 #endif
406 /* update window list to reflect unshaded state */
407 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
412 void
413 wMaximizeWindow(WWindow *wwin, int directions)
415 int new_width, new_height, new_x, new_y;
416 WArea usableArea = wwin->screen_ptr->totalUsableArea;
419 if (WFLAGP(wwin, no_resizable))
420 return;
423 if (WFLAGP(wwin, full_maximize)) {
424 usableArea.x1 = 0;
425 usableArea.y1 = 0;
426 usableArea.x2 = wwin->screen_ptr->scr_width;
427 usableArea.y2 = wwin->screen_ptr->scr_height;
430 if (wwin->flags.shaded) {
431 wwin->flags.skip_next_animation = 1;
432 wUnshadeWindow(wwin);
434 wwin->flags.maximized = directions;
435 wwin->old_geometry.width = wwin->client.width;
436 wwin->old_geometry.height = wwin->client.height;
437 wwin->old_geometry.x = wwin->frame_x;
438 wwin->old_geometry.y = wwin->frame_y;
440 #ifdef KWM_HINTS
441 wKWMUpdateClientGeometryRestore(wwin);
442 #endif
444 if (directions & MAX_HORIZONTAL) {
446 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
447 new_x = usableArea.x1;
449 } else {
451 new_x = wwin->frame_x;
452 new_width = wwin->frame->core->width;
456 if (directions & MAX_VERTICAL) {
458 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
459 new_y = usableArea.y1;
460 if (WFLAGP(wwin, full_maximize))
461 new_y -= wwin->frame->top_width;
463 } else {
465 new_y = wwin->frame_y;
466 new_height = wwin->frame->core->height;
470 if (!WFLAGP(wwin, full_maximize)) {
471 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
474 wWindowConstrainSize(wwin, &new_width, &new_height);
475 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
477 #ifdef GNOME_STUFF
478 wGNOMEUpdateClientStateHint(wwin, False);
479 #endif
480 #ifdef KWM_HINTS
481 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
482 wKWMSendEventMessage(wwin, WKWMChangedClient);
483 #endif
485 #ifdef WMSOUND
486 wSoundPlay(WMSOUND_MAXIMIZE);
487 #endif
491 void
492 wUnmaximizeWindow(WWindow *wwin)
494 int restore_x, restore_y;
496 if (!wwin->flags.maximized)
497 return;
499 if (wwin->flags.shaded) {
500 wwin->flags.skip_next_animation = 1;
501 wUnshadeWindow(wwin);
503 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
504 wwin->old_geometry.x : wwin->frame_x;
505 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
506 wwin->old_geometry.y : wwin->frame_y;
507 wwin->flags.maximized = 0;
508 wWindowConfigure(wwin, restore_x, restore_y,
509 wwin->old_geometry.width, wwin->old_geometry.height);
511 #ifdef GNOME_STUFF
512 wGNOMEUpdateClientStateHint(wwin, False);
513 #endif
514 #ifdef KWM_HINTS
515 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
516 wKWMSendEventMessage(wwin, WKWMChangedClient);
517 #endif
519 #ifdef WMSOUND
520 wSoundPlay(WMSOUND_UNMAXIMIZE);
521 #endif
524 #ifdef ANIMATIONS
525 static void
526 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
527 int fx, int fy, int fw, int fh, int steps)
529 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
530 float cx, cy, cw, ch;
531 float xstep, ystep, wstep, hstep;
532 XPoint points[5];
533 float dx, dch, midy;
534 float angle, final_angle, delta;
536 xstep = (float)(fx-x)/steps;
537 ystep = (float)(fy-y)/steps;
538 wstep = (float)(fw-w)/steps;
539 hstep = (float)(fh-h)/steps;
541 cx = (float)x;
542 cy = (float)y;
543 cw = (float)w;
544 ch = (float)h;
546 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
547 delta = (float)(final_angle/FRAMES);
548 for (angle=0;; angle+=delta) {
549 if (angle > final_angle)
550 angle = final_angle;
552 dx = (cw/10) - ((cw/5) * sin(angle));
553 dch = (ch/2) * cos(angle);
554 midy = cy + (ch/2);
556 points[0].x = cx + dx; points[0].y = midy - dch;
557 points[1].x = cx + cw - dx; points[1].y = points[0].y;
558 points[2].x = cx + cw + dx; points[2].y = midy + dch;
559 points[3].x = cx - dx; points[3].y = points[2].y;
560 points[4].x = points[0].x; points[4].y = points[0].y;
562 XGrabServer(dpy);
563 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
564 XFlush(dpy);
565 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
566 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
567 #endif
569 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
570 XUngrabServer(dpy);
571 cx+=xstep;
572 cy+=ystep;
573 cw+=wstep;
574 ch+=hstep;
575 if (angle >= final_angle)
576 break;
579 XFlush(dpy);
581 #undef FRAMES
584 static void
585 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
586 int fx, int fy, int fw, int fh, int steps)
588 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
589 float cx, cy, cw, ch;
590 float xstep, ystep, wstep, hstep;
591 XPoint points[5];
592 float angle, final_angle, a, d, delta;
594 x += w/2;
595 y += h/2;
596 fx += fw/2;
597 fy += fh/2;
599 xstep = (float)(fx-x)/steps;
600 ystep = (float)(fy-y)/steps;
601 wstep = (float)(fw-w)/steps;
602 hstep = (float)(fh-h)/steps;
604 cx = (float)x;
605 cy = (float)y;
606 cw = (float)w;
607 ch = (float)h;
609 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
610 delta = (float)(final_angle/FRAMES);
611 for (angle=0;; angle+=delta) {
612 if (angle > final_angle)
613 angle = final_angle;
615 a = atan(ch/cw);
616 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
618 points[0].x = cx+cos(angle-a)*d;
619 points[0].y = cy+sin(angle-a)*d;
620 points[1].x = cx+cos(angle+a)*d;
621 points[1].y = cy+sin(angle+a)*d;
622 points[2].x = cx+cos(angle-a+WM_PI)*d;
623 points[2].y = cy+sin(angle-a+WM_PI)*d;
624 points[3].x = cx+cos(angle+a+WM_PI)*d;
625 points[3].y = cy+sin(angle+a+WM_PI)*d;
626 points[4].x = cx+cos(angle-a)*d;
627 points[4].y = cy+sin(angle-a)*d;
628 XGrabServer(dpy);
629 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
630 XFlush(dpy);
631 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
632 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
633 #endif
635 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
636 XUngrabServer(dpy);
637 cx+=xstep;
638 cy+=ystep;
639 cw+=wstep;
640 ch+=hstep;
641 if (angle >= final_angle)
642 break;
645 XFlush(dpy);
647 #undef FRAMES
650 static void
651 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
652 int fx, int fy, int fw, int fh, int steps)
654 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
655 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
656 float xstep, ystep, wstep, hstep;
657 int i, j;
659 xstep = (float)(fx-x)/steps;
660 ystep = (float)(fy-y)/steps;
661 wstep = (float)(fw-w)/steps;
662 hstep = (float)(fh-h)/steps;
664 for (j=0; j<FRAMES; j++) {
665 cx[j] = (float)x;
666 cy[j] = (float)y;
667 cw[j] = (float)w;
668 ch[j] = (float)h;
670 XGrabServer(dpy);
671 for (i=0; i<steps; i++) {
672 for (j=0; j<FRAMES; j++) {
673 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
674 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
676 XFlush(dpy);
677 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
678 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
679 #endif
680 for (j=0; j<FRAMES; j++) {
681 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
682 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
683 if (j<FRAMES-1) {
684 cx[j]=cx[j+1];
685 cy[j]=cy[j+1];
686 cw[j]=cw[j+1];
687 ch[j]=ch[j+1];
688 } else {
689 cx[j]+=xstep;
690 cy[j]+=ystep;
691 cw[j]+=wstep;
692 ch[j]+=hstep;
697 for (j=0; j<FRAMES; j++) {
698 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
699 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
701 XFlush(dpy);
702 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
703 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
704 #endif
705 for (j=0; j<FRAMES; j++) {
706 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
707 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
710 XUngrabServer(dpy);
712 #undef FRAMES
715 static void
716 animateResize(WScreen *scr, int x, int y, int w, int h,
717 int fx, int fy, int fw, int fh, int hiding)
719 int style = wPreferences.iconification_style; /* Catch the value */
720 int steps, k;
722 if (style == WIS_NONE)
723 return;
725 if (style == WIS_RANDOM) {
726 style = rand()%3;
729 k = (hiding ? 2 : 3);
730 switch(style) {
731 case WIS_TWIST:
732 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
733 if (steps>0)
734 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
735 break;
736 case WIS_FLIP:
737 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
738 if (steps>0)
739 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
740 break;
741 case WIS_ZOOM:
742 default:
743 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
744 if (steps>0)
745 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
746 break;
749 #endif /* ANIMATIONS */
752 static void
753 flushExpose()
755 XEvent tmpev;
757 while (XCheckTypedEvent(dpy, Expose, &tmpev))
758 WMHandleEvent(&tmpev);
759 XSync(dpy, 0);
762 static void
763 unmapTransientsFor(WWindow *wwin)
765 WWindow *tmp;
768 tmp = wwin->screen_ptr->focused_window;
769 while (tmp) {
770 /* unmap the transients for this transient */
771 if (tmp!=wwin && tmp->transient_for == wwin->client_win
772 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
773 || tmp->flags.shaded)) {
774 unmapTransientsFor(tmp);
775 tmp->flags.miniaturized = 1;
776 if (!tmp->flags.shaded) {
777 wWindowUnmap(tmp);
778 } else {
779 XUnmapWindow(dpy, tmp->frame->core->window);
782 if (!tmp->flags.shaded)
784 wClientSetState(tmp, IconicState, None);
785 #ifdef KWM_HINTS
786 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
787 wKWMSendEventMessage(tmp, WKWMRemoveWindow);
788 tmp->flags.kwm_hidden_for_modules = 1;
789 #endif
791 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
794 tmp = tmp->prev;
799 static void
800 mapTransientsFor(WWindow *wwin)
802 WWindow *tmp;
804 tmp = wwin->screen_ptr->focused_window;
805 while (tmp) {
806 /* recursively map the transients for this transient */
807 if (tmp!=wwin && tmp->transient_for == wwin->client_win
808 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
809 && tmp->icon==NULL) {
810 mapTransientsFor(tmp);
811 tmp->flags.miniaturized = 0;
812 if (!tmp->flags.shaded) {
813 wWindowMap(tmp);
814 } else {
815 XMapWindow(dpy, tmp->frame->core->window);
817 tmp->flags.semi_focused = 0;
819 if (!tmp->flags.shaded)
821 wClientSetState(tmp, NormalState, None);
822 #ifdef KWM_HINTS
823 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
824 if (tmp->flags.kwm_hidden_for_modules) {
825 wKWMSendEventMessage(tmp, WKWMAddWindow);
826 tmp->flags.kwm_hidden_for_modules = 0;
828 #endif
830 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
833 tmp = tmp->prev;
837 #if 0
838 static void
839 setupIconGrabs(WIcon *icon)
841 /* setup passive grabs on the icon */
842 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
843 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
844 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
845 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
846 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
847 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
848 XSync(dpy, 0);
850 #endif
852 static WWindow*
853 recursiveTransientFor(WWindow *wwin)
855 int i;
857 if (!wwin)
858 return None;
860 /* hackish way to detect transient_for cycle */
861 i = wwin->screen_ptr->window_count+1;
863 while (wwin && wwin->transient_for != None && i>0) {
864 wwin = wWindowFor(wwin->transient_for);
865 i--;
867 if (i==0 && wwin) {
868 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
869 wwin->frame->title);
870 return NULL;
873 return wwin;
876 #if 0
877 static void
878 removeIconGrabs(WIcon *icon)
880 /* remove passive grabs on the icon */
881 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
882 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
883 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
884 XSync(dpy, 0);
886 #endif
889 void
890 wIconifyWindow(WWindow *wwin)
892 XWindowAttributes attribs;
893 int present;
896 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
897 /* the window doesn't exist anymore */
898 return;
901 if (wwin->flags.miniaturized) {
902 return;
906 if (wwin->transient_for!=None) {
907 WWindow *owner = wWindowFor(wwin->transient_for);
909 if (owner && owner->flags.miniaturized)
910 return;
913 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
915 /* if the window is in another workspace, simplify process */
916 if (present) {
917 /* icon creation may take a while */
918 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
919 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
920 GrabModeAsync, None, None, CurrentTime);
923 if (!wPreferences.disable_miniwindows) {
924 if (!wwin->flags.icon_moved) {
925 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y);
927 wwin->icon = wIconCreate(wwin);
930 wwin->flags.miniaturized = 1;
931 wwin->flags.mapped = 0;
933 /* unmap transients */
935 unmapTransientsFor(wwin);
937 if (present) {
938 #ifdef WMSOUND
939 wSoundPlay(WMSOUND_ICONIFY);
940 #endif
942 XUngrabPointer(dpy, CurrentTime);
943 wWindowUnmap(wwin);
944 /* let all Expose events arrive so that we can repaint
945 * something before the animation starts (and the server is grabbed) */
946 XSync(dpy, 0);
948 if (wPreferences.disable_miniwindows)
949 wClientSetState(wwin, IconicState, None);
950 else
951 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
953 flushExpose();
954 #ifdef ANIMATIONS
955 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
956 && !wPreferences.no_animations) {
957 int ix, iy, iw, ih;
959 if (!wPreferences.disable_miniwindows) {
960 ix = wwin->icon_x;
961 iy = wwin->icon_y;
962 iw = wwin->icon->core->width;
963 ih = wwin->icon->core->height;
964 } else {
965 #ifdef KWM_HINTS
966 WArea area;
968 if (wKWMGetIconGeometry(wwin, &area)) {
969 ix = area.x1;
970 iy = area.y1;
971 iw = area.x2 - ix;
972 ih = area.y2 - iy;
973 } else
974 #endif /* KWM_HINTS */
976 ix = 0;
977 iy = 0;
978 iw = wwin->screen_ptr->scr_width;
979 ih = wwin->screen_ptr->scr_height;
982 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
983 wwin->frame->core->width, wwin->frame->core->height,
984 ix, iy, iw, ih, False);
986 #endif
989 wwin->flags.skip_next_animation = 0;
991 if (!wPreferences.disable_miniwindows) {
993 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
994 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
996 XMapWindow(dpy, wwin->icon->core->window);
998 AddToStackList(wwin->icon->core);
1000 wLowerFrame(wwin->icon->core);
1003 if (present) {
1004 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1007 * It doesn't seem to be working and causes button event hangup
1008 * when deiconifying a transient window.
1009 setupIconGrabs(wwin->icon);
1011 if ((wwin->flags.focused
1012 || (owner && wwin->client_win == owner->client_win))
1013 && wPreferences.focus_mode==WKF_CLICK) {
1014 WWindow *tmp;
1016 tmp = wwin->prev;
1017 while (tmp) {
1018 if (!WFLAGP(tmp, no_focusable)
1019 && !(tmp->flags.hidden||tmp->flags.miniaturized))
1020 break;
1021 tmp = tmp->prev;
1023 wSetFocusTo(wwin->screen_ptr, tmp);
1024 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1025 wSetFocusTo(wwin->screen_ptr, NULL);
1028 #ifdef ANIMATIONS
1029 if (!wwin->screen_ptr->flags.startup) {
1030 Window clientwin = wwin->client_win;
1032 XSync(dpy, 0);
1033 processEvents(XPending(dpy));
1035 /* the window can disappear while doing the processEvents() */
1036 if (!wWindowFor(clientwin))
1037 return;
1039 #endif
1043 if (wwin->flags.selected && !wPreferences.disable_miniwindows)
1044 wIconSelect(wwin->icon);
1046 #ifdef GNOME_STUFF
1047 wGNOMEUpdateClientStateHint(wwin, False);
1048 #endif
1049 #ifdef KWM_HINTS
1050 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1051 wKWMSendEventMessage(wwin, WKWMChangedClient);
1052 #endif
1054 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1060 void
1061 wDeiconifyWindow(WWindow *wwin)
1063 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1065 if (!wwin->flags.miniaturized)
1066 return;
1068 if (wwin->transient_for != None
1069 && wwin->transient_for != wwin->screen_ptr->root_win) {
1070 WWindow *owner = recursiveTransientFor(wwin);
1072 if (owner && owner->flags.miniaturized) {
1073 wDeiconifyWindow(owner);
1074 wSetFocusTo(wwin->screen_ptr, wwin);
1075 wRaiseFrame(wwin->frame->core);
1076 return;
1080 wwin->flags.miniaturized = 0;
1081 if (!wwin->flags.shaded)
1082 wwin->flags.mapped = 1;
1084 if (!wPreferences.disable_miniwindows) {
1085 if (wwin->icon->selected)
1086 wIconSelect(wwin->icon);
1088 XUnmapWindow(dpy, wwin->icon->core->window);
1091 #ifdef WMSOUND
1092 wSoundPlay(WMSOUND_DEICONIFY);
1093 #endif
1095 /* if the window is in another workspace, do it silently */
1096 #ifdef ANIMATIONS
1097 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1098 && !wwin->flags.skip_next_animation) {
1099 int ix, iy, iw, ih;
1101 if (!wPreferences.disable_miniwindows) {
1102 ix = wwin->icon_x;
1103 iy = wwin->icon_y;
1104 iw = wwin->icon->core->width;
1105 ih = wwin->icon->core->height;
1106 } else {
1107 #ifdef KWM_HINTS
1108 WArea area;
1110 if (wKWMGetIconGeometry(wwin, &area)) {
1111 ix = area.x1;
1112 iy = area.y1;
1113 iw = area.x2 - ix;
1114 ih = area.y2 - iy;
1115 } else
1116 #endif /* KWM_HINTS */
1118 ix = 0;
1119 iy = 0;
1120 iw = wwin->screen_ptr->scr_width;
1121 ih = wwin->screen_ptr->scr_height;
1124 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1125 wwin->frame_x, wwin->frame_y,
1126 wwin->frame->core->width, wwin->frame->core->height,
1127 False);
1129 #endif /* ANIMATIONS */
1130 wwin->flags.skip_next_animation = 0;
1131 XGrabServer(dpy);
1132 if (!wwin->flags.shaded) {
1133 XMapWindow(dpy, wwin->client_win);
1135 XMapWindow(dpy, wwin->frame->core->window);
1136 wRaiseFrame(wwin->frame->core);
1137 if (!wwin->flags.shaded) {
1138 wClientSetState(wwin, NormalState, None);
1140 mapTransientsFor(wwin);
1142 if (!wPreferences.disable_miniwindows) {
1143 RemoveFromStackList(wwin->icon->core);
1144 /* removeIconGrabs(wwin->icon);*/
1145 wIconDestroy(wwin->icon);
1146 wwin->icon = NULL;
1148 XUngrabServer(dpy);
1149 if (wPreferences.focus_mode==WKF_CLICK
1150 || wPreferences.focus_mode==WKF_SLOPPY)
1151 wSetFocusTo(wwin->screen_ptr, wwin);
1153 #ifdef ANIMATIONS
1154 if (!wwin->screen_ptr->flags.startup) {
1155 Window clientwin = wwin->client_win;
1157 XSync(dpy, 0);
1158 processEvents(XPending(dpy));
1160 if (!wWindowFor(clientwin))
1161 return;
1163 #endif
1165 if (wPreferences.auto_arrange_icons) {
1166 wArrangeIcons(wwin->screen_ptr, True);
1169 #ifdef GNOME_STUFF
1170 wGNOMEUpdateClientStateHint(wwin, False);
1171 #endif
1172 #ifdef KWM_HINTS
1173 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1174 wKWMSendEventMessage(wwin, WKWMChangedClient);
1175 #endif
1177 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1182 static void
1183 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1185 if (wwin->flags.miniaturized) {
1186 if (wwin->icon) {
1187 XUnmapWindow(dpy, wwin->icon->core->window);
1188 wwin->icon->mapped = 0;
1190 wwin->flags.hidden = 1;
1191 #ifdef GNOME_STUFF
1192 wGNOMEUpdateClientStateHint(wwin, False);
1193 #endif
1195 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1197 return;
1200 if (wwin->flags.inspector_open) {
1201 WWindow *pwin = wwin->inspector->frame;
1203 wWindowUnmap(pwin);
1204 pwin->flags.hidden = 1;
1206 wClientSetState(pwin, IconicState, icon->icon_win);
1209 wwin->flags.hidden = 1;
1210 wWindowUnmap(wwin);
1212 wClientSetState(wwin, IconicState, icon->icon_win);
1213 flushExpose();
1214 #ifdef WMSOUND
1215 wSoundPlay(WMSOUND_HIDE);
1216 #endif
1217 #ifdef ANIMATIONS
1218 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1219 !wwin->flags.skip_next_animation && animate) {
1220 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1221 wwin->frame->core->width, wwin->frame->core->height,
1222 icon_x, icon_y, icon->core->width, icon->core->height,
1223 True);
1225 #endif
1226 wwin->flags.skip_next_animation = 0;
1228 #ifdef GNOME_STUFF
1229 wGNOMEUpdateClientStateHint(wwin, False);
1230 #endif
1232 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1237 void
1238 wHideOtherApplications(WWindow *awin)
1240 WWindow *wwin;
1241 WApplication *tapp;
1242 #ifdef REDUCE_APPICONS
1243 char *tinstance, *tclass;
1244 unsigned int brokenwin = 0, match = 0;
1245 #endif
1247 if (!awin)
1248 return;
1249 wwin = awin->screen_ptr->focused_window;
1251 #ifdef REDUCE_APPICONS
1252 if (awin->wm_instance == NULL || awin->wm_class == NULL)
1253 brokenwin++;
1254 #endif
1256 while (wwin) {
1257 if (wwin!=awin
1258 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1259 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1260 && !wwin->flags.internal_window
1261 && (!wwin->flags.inspector_open || wwin->inspector->frame!=awin)
1262 && !WFLAGP(wwin, no_hide_others)) {
1264 #ifdef REDUCE_APPICONS
1265 match = 0;
1266 if (!brokenwin) {
1267 if ((tinstance = wwin->wm_instance) == NULL)
1268 tinstance = "";
1269 if ((tclass = wwin->wm_class) == NULL)
1270 tclass = "";
1271 if ((strcmp(awin->wm_instance, tinstance) == 0) &&
1272 (strcmp(awin->wm_class, tclass) == 0) )
1273 match++;
1275 #endif
1277 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1278 if (!WFLAGP(wwin, no_miniaturizable)) {
1279 wwin->flags.skip_next_animation = 1;
1280 wIconifyWindow(wwin);
1282 } else if (wwin->main_window!=None
1283 #ifndef REDUCE_APPICONS
1284 && awin->main_window != wwin->main_window) {
1285 #else
1286 && (awin->main_window != wwin->main_window && !match)) {
1287 #endif
1288 tapp = wApplicationOf(wwin->main_window);
1289 if (tapp) {
1290 tapp->flags.skip_next_animation = 1;
1291 wHideApplication(tapp);
1292 } else {
1293 if (!WFLAGP(wwin, no_miniaturizable)) {
1294 wwin->flags.skip_next_animation = 1;
1295 wIconifyWindow(wwin);
1300 wwin = wwin->prev;
1303 wSetFocusTo(awin->screen_ptr, awin);
1309 void
1310 wHideApplication(WApplication *wapp)
1312 #ifdef REDUCE_APPICONS
1313 WApplication *tapp;
1314 char *tinstance, *tclass;
1315 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1316 #endif
1317 WScreen *scr;
1318 WWindow *wlist;
1319 int hadfocus;
1321 if (!wapp) {
1322 wwarning("trying to hide a non grouped window");
1323 return;
1325 if (!wapp->main_window_desc) {
1326 wwarning("group leader not found for window group");
1327 return;
1329 #ifdef REDUCE_APPICONS
1330 if ((wapp->main_window_desc->wm_instance == NULL) ||
1331 (wapp->main_window_desc->wm_class == NULL))
1332 nowmhints++;
1333 #endif
1334 scr = wapp->main_window_desc->screen_ptr;
1335 hadfocus = 0;
1336 wlist = scr->focused_window;
1337 if (!wlist)
1338 return;
1340 if (wlist->main_window == wapp->main_window)
1341 wapp->last_focused = wlist;
1342 else
1343 wapp->last_focused = NULL;
1344 while (wlist) {
1345 #ifdef REDUCE_APPICONS
1346 matchwmhints = matchworkspace = 0;
1347 if (!nowmhints) {
1348 tapp = wApplicationOf(wlist->main_window);
1349 tinstance = tclass = NULL;
1350 if (tapp) {
1351 if (tapp->main_window_desc) {
1352 tinstance = tapp->main_window_desc->wm_instance;
1353 tclass = tapp->main_window_desc->wm_class;
1356 if (tapp == NULL || tinstance == NULL || tclass == NULL) {
1357 /* Should never reach here */
1358 tinstance = "";
1359 tclass = "";
1361 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0) &&
1362 (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1363 matchwmhints++;
1365 if (wlist->frame) {
1366 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1367 matchworkspace++;
1369 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1370 matchworkspace) {
1371 #ifdef I_HATE_THIS
1373 #endif
1374 #else
1375 if (wlist->main_window == wapp->main_window) {
1376 #endif
1377 if (wlist->flags.focused) {
1378 hadfocus = 1;
1380 if (wapp->app_icon)
1381 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1382 wapp->app_icon->y_pos, wlist,
1383 !wapp->flags.skip_next_animation);
1385 wlist = wlist->prev;
1388 wapp->flags.skip_next_animation = 0;
1390 if (hadfocus) {
1391 if (wPreferences.focus_mode==WKF_CLICK) {
1392 wlist = scr->focused_window;
1393 while (wlist) {
1394 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1395 && (wlist->flags.mapped || wlist->flags.shaded))
1396 break;
1397 wlist = wlist->prev;
1399 wSetFocusTo(scr, wlist);
1400 } else {
1401 wSetFocusTo(scr, NULL);
1405 wapp->flags.hidden = 1;
1407 if(wPreferences.auto_arrange_icons) {
1408 wArrangeIcons(scr, True);
1410 #ifdef HIDDENDOT
1411 if (wapp->app_icon)
1412 wAppIconPaint(wapp->app_icon);
1413 #endif
1419 static void
1420 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1421 int bringToCurrentWS)
1423 if (bringToCurrentWS)
1424 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1426 wwin->flags.hidden=0;
1427 wwin->flags.mapped=1;
1429 #ifdef WMSOUND
1430 wSoundPlay(WMSOUND_UNHIDE);
1431 #endif
1432 #ifdef ANIMATIONS
1433 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1434 && animate) {
1435 animateResize(wwin->screen_ptr, icon_x, icon_y,
1436 icon->core->width, icon->core->height,
1437 wwin->frame_x, wwin->frame_y,
1438 wwin->frame->core->width, wwin->frame->core->height,
1439 True);
1441 #endif
1442 wwin->flags.skip_next_animation = 0;
1443 XMapWindow(dpy, wwin->client_win);
1444 XMapWindow(dpy, wwin->frame->core->window);
1445 wClientSetState(wwin, NormalState, None);
1446 wRaiseFrame(wwin->frame->core);
1447 if (wwin->flags.inspector_open) {
1448 WWindow *pwin = wwin->inspector->frame;
1450 pwin->flags.hidden = 0;
1451 pwin->flags.mapped = 1;
1452 XMapWindow(dpy, pwin->client_win);
1453 XMapWindow(dpy, pwin->frame->core->window);
1454 wClientSetState(pwin, NormalState, None);
1457 #ifdef GNOME_STUFF
1458 wGNOMEUpdateClientStateHint(wwin, False);
1459 #endif
1461 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1466 void
1467 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1469 WScreen *scr;
1470 WWindow *wlist, *next;
1471 WWindow *focused=NULL;
1472 #ifdef REDUCE_APPICONS
1473 char *tinstance, *tclass;
1474 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1475 #endif
1477 if (!wapp) {
1478 return;
1481 #ifdef REDUCE_APPICONS
1482 if ((wapp->main_window_desc->wm_class == NULL) ||
1483 (wapp->main_window_desc->wm_instance == NULL))
1484 nowmhints++;
1485 #endif
1487 scr = wapp->main_window_desc->screen_ptr;
1488 wlist = scr->focused_window;
1489 if (!wlist) return;
1490 /* goto beginning of list */
1491 while (wlist->prev)
1492 wlist = wlist->prev;
1494 while (wlist) {
1495 next = wlist->next;
1497 #ifndef REDUCE_APPICONS
1498 if (wlist->main_window == wapp->main_window) {
1499 #else
1500 matchwmhints = matchworkspace = 0;
1501 if (!nowmhints) {
1502 if ((tinstance = wlist->wm_instance) == NULL)
1503 tinstance = "";
1504 if ((tclass = wlist->wm_class) == NULL)
1505 tclass = "";
1506 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0)
1507 && (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1508 matchwmhints++;
1510 if (wlist->frame) {
1511 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1512 matchworkspace++;
1515 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1516 matchworkspace) {
1517 #endif
1518 if (wlist->flags.focused)
1519 focused = wlist;
1520 else if (!focused || !focused->flags.focused)
1521 focused = wlist;
1523 if (wlist->flags.miniaturized && wlist->icon) {
1524 if (bringToCurrentWS || wPreferences.sticky_icons
1525 || wlist->frame->workspace == scr->current_workspace) {
1526 if (!wlist->icon->mapped) {
1527 XMapWindow(dpy, wlist->icon->core->window);
1528 wlist->icon->mapped = 1;
1530 wlist->flags.hidden = 0;
1532 UpdateSwitchMenu(scr, wlist, ACTION_CHANGE_STATE);
1534 if (wlist->frame->workspace != scr->current_workspace)
1535 wWindowChangeWorkspace(wlist, scr->current_workspace);
1537 if (miniwindows) {
1538 wDeiconifyWindow(wlist);
1540 } else if (wlist->flags.hidden) {
1541 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1542 wapp->app_icon->y_pos, wlist,
1543 !wapp->flags.skip_next_animation,
1544 bringToCurrentWS);
1545 } else {
1546 if (bringToCurrentWS
1547 && wlist->frame->workspace != scr->current_workspace) {
1548 wWindowChangeWorkspace(wlist, scr->current_workspace);
1550 wRaiseFrame(wlist->frame->core);
1553 wlist = next;
1556 wapp->flags.skip_next_animation = 0;
1557 wapp->flags.hidden = 0;
1559 if (focused)
1560 wSetFocusTo(scr, focused);
1561 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1562 wSetFocusTo(scr, wapp->last_focused);
1563 wapp->last_focused = NULL;
1564 if (wPreferences.auto_arrange_icons) {
1565 wArrangeIcons(scr, True);
1567 #ifdef HIDDENDOT
1568 wAppIconPaint(wapp->app_icon);
1569 #endif
1574 void
1575 wShowAllWindows(WScreen *scr)
1577 WWindow *wwin, *old_foc;
1578 WApplication *wapp;
1580 old_foc = wwin = scr->focused_window;
1581 while (wwin) {
1582 if (!wwin->flags.internal_window &&
1583 (scr->current_workspace == wwin->frame->workspace
1584 || IS_OMNIPRESENT(wwin))) {
1585 if (wwin->flags.miniaturized) {
1586 wwin->flags.skip_next_animation = 1;
1587 wDeiconifyWindow(wwin);
1588 } else if (wwin->flags.hidden) {
1589 wapp = wApplicationOf(wwin->main_window);
1590 if (wapp) {
1591 wUnhideApplication(wapp, False, False);
1592 } else {
1593 wwin->flags.skip_next_animation = 1;
1594 wDeiconifyWindow(wwin);
1598 wwin = wwin->prev;
1600 wSetFocusTo(scr, old_foc);
1601 /*wRaiseFrame(old_foc->frame->core);*/
1605 void
1606 wRefreshDesktop(WScreen *scr)
1608 Window win;
1609 XSetWindowAttributes attr;
1611 attr.backing_store = NotUseful;
1612 attr.save_under = False;
1613 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1614 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1615 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1616 &attr);
1617 XMapRaised(dpy, win);
1618 XDestroyWindow(dpy, win);
1619 XFlush(dpy);
1623 void
1624 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1626 WWindow *wwin;
1627 WAppIcon *aicon;
1628 int pf; /* primary axis */
1629 int sf; /* secondary axis */
1630 int fullW;
1631 int fullH;
1632 int pi, si;
1633 int sx1, sx2, sy1, sy2; /* screen boundary */
1634 int sw, sh;
1635 int xo, yo;
1636 int xs, ys;
1637 int isize = wPreferences.icon_size;
1640 * Find out screen boundaries.
1642 sx1 = 0;
1643 sy1 = 0;
1644 sx2 = scr->scr_width;
1645 sy2 = scr->scr_height;
1646 if (scr->dock) {
1647 if (scr->dock->on_right_side)
1648 sx2 -= isize + DOCK_EXTRA_SPACE;
1649 else
1650 sx1 += isize + DOCK_EXTRA_SPACE;
1653 sw = isize * (scr->scr_width/isize);
1654 sh = isize * (scr->scr_height/isize);
1655 fullW = (sx2-sx1)/isize;
1656 fullH = (sy2-sy1)/isize;
1658 /* icon yard boundaries */
1659 if (wPreferences.icon_yard & IY_VERT) {
1660 pf = fullH;
1661 sf = fullW;
1662 } else {
1663 pf = fullW;
1664 sf = fullH;
1666 if (wPreferences.icon_yard & IY_RIGHT) {
1667 xo = sx2 - isize;
1668 xs = -1;
1669 } else {
1670 xo = sx1;
1671 xs = 1;
1673 if (wPreferences.icon_yard & IY_TOP) {
1674 yo = sy1;
1675 ys = 1;
1676 } else {
1677 yo = sy2 - isize;
1678 ys = -1;
1681 /* arrange icons putting the most recently focused window
1682 * as the last icon */
1683 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1684 : xo + xs*(pi*isize))
1685 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1686 : yo + ys*(si*isize))
1688 /* arrange application icons */
1689 aicon = scr->app_icon_list;
1690 /* reverse them to avoid unnecessarily sliding of icons */
1691 while (aicon && aicon->next)
1692 aicon = aicon->next;
1694 pi = 0;
1695 si = 0;
1696 while (aicon) {
1697 if (!aicon->docked) {
1698 if (aicon->x_pos != X || aicon->y_pos != Y) {
1699 #ifdef ANIMATIONS
1700 if (!wPreferences.no_animations) {
1701 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1702 X, Y);
1704 #endif /* ANIMATIONS */
1706 wAppIconMove(aicon, X, Y);
1707 pi++;
1709 /* we reversed the order so we use prev */
1710 aicon = aicon->prev;
1711 if (pi >= pf) {
1712 pi=0;
1713 si++;
1717 /* arrange miniwindows */
1719 wwin = scr->focused_window;
1720 /* reverse them to avoid unnecessarily shuffling */
1721 while (wwin && wwin->prev)
1722 wwin = wwin->prev;
1724 while (wwin) {
1725 if (wwin->icon && wwin->flags.miniaturized &&/*!wwin->flags.hidden &&*/
1726 (wwin->frame->workspace==scr->current_workspace ||
1727 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1729 if (arrangeAll || !wwin->flags.icon_moved) {
1730 if (wwin->icon_x != X || wwin->icon_y != Y) {
1731 #ifdef ANIMATIONS
1732 if (wPreferences.no_animations) {
1733 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1734 } else {
1735 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1736 wwin->icon_y, X, Y);
1738 #else
1739 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1740 #endif /* ANIMATIONS */
1742 wwin->icon_x = X;
1743 wwin->icon_y = Y;
1744 pi++;
1747 if (arrangeAll) {
1748 wwin->flags.icon_moved = 0;
1750 /* we reversed the order, so we use next */
1751 wwin = wwin->next;
1752 if (pi >= pf) {
1753 pi=0;
1754 si++;
1760 void
1761 wSelectWindow(WWindow *wwin, Bool flag)
1763 WScreen *scr = wwin->screen_ptr;
1764 if (flag) {
1765 wwin->flags.selected = 1;
1766 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1767 scr->selected_windows = list_cons(wwin, scr->selected_windows);
1768 } else {
1769 wwin->flags.selected = 0;
1770 XSetWindowBorder(dpy, wwin->frame->core->window,
1771 scr->frame_border_pixel);
1772 scr->selected_windows = list_remove_elem(scr->selected_windows, wwin);
1777 void
1778 wMakeWindowVisible(WWindow *wwin)
1780 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1782 if (wwin->flags.shaded) {
1783 wUnshadeWindow(wwin);
1785 if (wwin->flags.hidden) {
1786 WApplication *app;
1788 app = wApplicationOf(wwin->main_window);
1789 if (app)
1790 wUnhideApplication(app, False, False);
1791 } else if (wwin->flags.miniaturized) {
1792 wDeiconifyWindow(wwin);
1793 } else {
1794 wSetFocusTo(wwin->screen_ptr, wwin);
1795 wRaiseFrame(wwin->frame->core);