*** empty log message ***
[wmaker-crm.git] / src / actions.c
blobf10d409e316ef64e119ab94d1b6a0edd32aeb841
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 (WFLAGP(wwin, no_focusable))
179 return;
181 if (wwin->flags.mapped /*&& !WFLAGP(wwin, no_focusable)*/) {
182 /* install colormap if colormap mode is lock mode */
183 if (wPreferences.colormap_mode==WKF_CLICK)
184 wColormapInstallForWindow(scr, wwin);
186 /* set input focus */
187 switch (wwin->focus_mode) {
188 case WFM_NO_INPUT:
189 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
190 break;
192 case WFM_PASSIVE:
193 case WFM_LOCALLY_ACTIVE:
194 XSetInputFocus(dpy, wwin->client_win, RevertToParent, timestamp);
195 break;
197 case WFM_GLOBALLY_ACTIVE:
198 break;
200 XFlush(dpy);
201 if (wwin->protocols.TAKE_FOCUS) {
202 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
204 XSync(dpy, False);
205 } else {
206 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
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 wAppMenuMap(napp->menu, wwin);
235 #ifdef NEWAPPICON
236 wApplicationActivate(napp);
237 #endif
239 #ifdef KWM_HINTS
240 wKWMUpdateActiveWindowHint(scr);
241 wKWMSendEventMessage(wwin, WKWMFocusWindow);
242 #endif
243 XFlush(dpy);
247 void
248 wShadeWindow(WWindow *wwin)
250 time_t time0 = time(NULL);
251 #ifdef ANIMATIONS
252 int y, s, w, h;
253 #endif
255 if (wwin->flags.shaded)
256 return;
258 XLowerWindow(dpy, wwin->client_win);
260 #ifdef WMSOUND
261 wSoundPlay(WMSOUND_SHADE);
262 #endif
264 #ifdef ANIMATIONS
265 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
266 && !wPreferences.no_animations) {
267 /* do the shading animation */
268 h = wwin->frame->core->height;
269 s = h/SHADE_STEPS;
270 if (s < 1) s=1;
271 w = wwin->frame->core->width;
272 y = wwin->frame->top_width;
273 while (h>wwin->frame->top_width+1) {
274 XMoveWindow(dpy, wwin->client_win, 0, y);
275 XResizeWindow(dpy, wwin->frame->core->window, w, h);
276 XFlush(dpy);
278 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
279 break;
281 if (SHADE_DELAY > 0)
282 wusleep(SHADE_DELAY*1000L);
283 h-=s;
284 y-=s;
286 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
288 #endif /* ANIMATIONS */
290 wwin->flags.skip_next_animation = 0;
291 wwin->flags.shaded = 1;
292 wwin->flags.mapped = 0;
293 /* prevent window withdrawal when getting UnmapNotify */
294 XSelectInput(dpy, wwin->client_win,
295 wwin->event_mask & ~StructureNotifyMask);
296 XUnmapWindow(dpy, wwin->client_win);
297 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
299 /* for the client it's just like iconification */
300 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
301 wwin->frame->top_width - 1);
303 wwin->client.y = wwin->frame_y - wwin->client.height
304 + wwin->frame->top_width;
305 wWindowSynthConfigureNotify(wwin);
308 wClientSetState(wwin, IconicState, None);
311 #ifdef GNOME_STUFF
312 wGNOMEUpdateClientStateHint(wwin, False);
313 #endif
314 #ifdef KWM_HINTS
315 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
316 wKWMSendEventMessage(wwin, WKWMChangedClient);
317 #endif
318 /* update window list to reflect shaded state */
319 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
321 #ifdef ANIMATIONS
322 if (!wwin->screen_ptr->flags.startup) {
323 /* Look at processEvents() for reason of this code. */
324 XSync(dpy, 0);
325 processEvents(XPending(dpy));
327 #endif
331 void
332 wUnshadeWindow(WWindow *wwin)
334 time_t time0 = time(NULL);
335 #ifdef ANIMATIONS
336 int y, s, w, h;
337 #endif /* ANIMATIONS */
340 if (!wwin->flags.shaded)
341 return;
343 wwin->flags.shaded = 0;
344 wwin->flags.mapped = 1;
345 XMapWindow(dpy, wwin->client_win);
347 #ifdef WMSOUND
348 wSoundPlay(WMSOUND_UNSHADE);
349 #endif
351 #ifdef ANIMATIONS
352 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
353 /* do the shading animation */
354 h = wwin->frame->top_width + wwin->frame->bottom_width;
355 y = wwin->frame->top_width - wwin->client.height;
356 s = abs(y)/SHADE_STEPS;
357 if (s<1) s=1;
358 w = wwin->frame->core->width;
359 XMoveWindow(dpy, wwin->client_win, 0, y);
360 if (s>0) {
361 while (h < wwin->client.height + wwin->frame->top_width
362 + wwin->frame->bottom_width) {
363 XResizeWindow(dpy, wwin->frame->core->window, w, h);
364 XMoveWindow(dpy, wwin->client_win, 0, y);
365 XSync(dpy, 0);
366 if (SHADE_DELAY > 0)
367 wusleep(SHADE_DELAY*2000L/3);
368 h+=s;
369 y+=s;
371 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
372 break;
375 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
377 #endif /* ANIMATIONS */
379 wwin->flags.skip_next_animation = 0;
380 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
381 wwin->frame->top_width + wwin->client.height
382 + wwin->frame->bottom_width);
384 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
385 wWindowSynthConfigureNotify(wwin);
388 wClientSetState(wwin, NormalState, None);
390 /* if the window is focused, set the focus again as it was disabled during
391 * shading */
392 if (wwin->flags.focused)
393 wSetFocusTo(wwin->screen_ptr, wwin);
395 #ifdef GNOME_STUFF
396 wGNOMEUpdateClientStateHint(wwin, False);
397 #endif
398 #ifdef KWM_HINTS
399 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
400 wKWMSendEventMessage(wwin, WKWMChangedClient);
401 #endif
403 /* update window list to reflect unshaded state */
404 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
409 void
410 wMaximizeWindow(WWindow *wwin, int directions)
412 int new_width, new_height, new_x, new_y;
413 WArea usableArea = wwin->screen_ptr->totalUsableArea;
416 if (WFLAGP(wwin, no_resizable))
417 return;
420 if (WFLAGP(wwin, full_maximize)) {
421 usableArea.x1 = 0;
422 usableArea.y1 = 0;
423 usableArea.x2 = wwin->screen_ptr->scr_width;
424 usableArea.y2 = wwin->screen_ptr->scr_height;
427 if (wwin->flags.shaded) {
428 wwin->flags.skip_next_animation = 1;
429 wUnshadeWindow(wwin);
431 wwin->flags.maximized = directions;
432 wwin->old_geometry.width = wwin->client.width;
433 wwin->old_geometry.height = wwin->client.height;
434 wwin->old_geometry.x = wwin->frame_x;
435 wwin->old_geometry.y = wwin->frame_y;
437 #ifdef KWM_HINTS
438 wKWMUpdateClientGeometryRestore(wwin);
439 #endif
441 if (directions & MAX_HORIZONTAL) {
443 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
444 new_x = usableArea.x1;
446 } else {
448 new_x = wwin->frame_x;
449 new_width = wwin->frame->core->width;
453 if (directions & MAX_VERTICAL) {
455 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
456 new_y = usableArea.y1;
457 if (WFLAGP(wwin, full_maximize))
458 new_y -= wwin->frame->top_width;
460 } else {
462 new_y = wwin->frame_y;
463 new_height = wwin->frame->core->height;
467 if (!WFLAGP(wwin, full_maximize)) {
468 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
471 wWindowConstrainSize(wwin, &new_width, &new_height);
472 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
474 #ifdef GNOME_STUFF
475 wGNOMEUpdateClientStateHint(wwin, False);
476 #endif
477 #ifdef KWM_HINTS
478 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
479 wKWMSendEventMessage(wwin, WKWMChangedClient);
480 #endif
482 #ifdef WMSOUND
483 wSoundPlay(WMSOUND_MAXIMIZE);
484 #endif
488 void
489 wUnmaximizeWindow(WWindow *wwin)
491 int restore_x, restore_y;
493 if (!wwin->flags.maximized)
494 return;
496 if (wwin->flags.shaded) {
497 wwin->flags.skip_next_animation = 1;
498 wUnshadeWindow(wwin);
500 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
501 wwin->old_geometry.x : wwin->frame_x;
502 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
503 wwin->old_geometry.y : wwin->frame_y;
504 wwin->flags.maximized = 0;
505 wWindowConfigure(wwin, restore_x, restore_y,
506 wwin->old_geometry.width, wwin->old_geometry.height);
508 #ifdef GNOME_STUFF
509 wGNOMEUpdateClientStateHint(wwin, False);
510 #endif
511 #ifdef KWM_HINTS
512 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
513 wKWMSendEventMessage(wwin, WKWMChangedClient);
514 #endif
516 #ifdef WMSOUND
517 wSoundPlay(WMSOUND_UNMAXIMIZE);
518 #endif
521 #ifdef ANIMATIONS
522 static void
523 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
524 int fx, int fy, int fw, int fh, int steps)
526 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
527 float cx, cy, cw, ch;
528 float xstep, ystep, wstep, hstep;
529 XPoint points[5];
530 float dx, dch, midy;
531 float angle, final_angle, delta;
533 xstep = (float)(fx-x)/steps;
534 ystep = (float)(fy-y)/steps;
535 wstep = (float)(fw-w)/steps;
536 hstep = (float)(fh-h)/steps;
538 cx = (float)x;
539 cy = (float)y;
540 cw = (float)w;
541 ch = (float)h;
543 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
544 delta = (float)(final_angle/FRAMES);
545 for (angle=0;; angle+=delta) {
546 if (angle > final_angle)
547 angle = final_angle;
549 dx = (cw/10) - ((cw/5) * sin(angle));
550 dch = (ch/2) * cos(angle);
551 midy = cy + (ch/2);
553 points[0].x = cx + dx; points[0].y = midy - dch;
554 points[1].x = cx + cw - dx; points[1].y = points[0].y;
555 points[2].x = cx + cw + dx; points[2].y = midy + dch;
556 points[3].x = cx - dx; points[3].y = points[2].y;
557 points[4].x = points[0].x; points[4].y = points[0].y;
559 XGrabServer(dpy);
560 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
561 XFlush(dpy);
562 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
563 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
564 #endif
566 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
567 XUngrabServer(dpy);
568 cx+=xstep;
569 cy+=ystep;
570 cw+=wstep;
571 ch+=hstep;
572 if (angle >= final_angle)
573 break;
576 XFlush(dpy);
578 #undef FRAMES
581 static void
582 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
583 int fx, int fy, int fw, int fh, int steps)
585 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
586 float cx, cy, cw, ch;
587 float xstep, ystep, wstep, hstep;
588 XPoint points[5];
589 float angle, final_angle, a, d, delta;
591 x += w/2;
592 y += h/2;
593 fx += fw/2;
594 fy += fh/2;
596 xstep = (float)(fx-x)/steps;
597 ystep = (float)(fy-y)/steps;
598 wstep = (float)(fw-w)/steps;
599 hstep = (float)(fh-h)/steps;
601 cx = (float)x;
602 cy = (float)y;
603 cw = (float)w;
604 ch = (float)h;
606 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
607 delta = (float)(final_angle/FRAMES);
608 for (angle=0;; angle+=delta) {
609 if (angle > final_angle)
610 angle = final_angle;
612 a = atan(ch/cw);
613 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
615 points[0].x = cx+cos(angle-a)*d;
616 points[0].y = cy+sin(angle-a)*d;
617 points[1].x = cx+cos(angle+a)*d;
618 points[1].y = cy+sin(angle+a)*d;
619 points[2].x = cx+cos(angle-a+WM_PI)*d;
620 points[2].y = cy+sin(angle-a+WM_PI)*d;
621 points[3].x = cx+cos(angle+a+WM_PI)*d;
622 points[3].y = cy+sin(angle+a+WM_PI)*d;
623 points[4].x = cx+cos(angle-a)*d;
624 points[4].y = cy+sin(angle-a)*d;
625 XGrabServer(dpy);
626 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
627 XFlush(dpy);
628 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
629 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
630 #endif
632 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
633 XUngrabServer(dpy);
634 cx+=xstep;
635 cy+=ystep;
636 cw+=wstep;
637 ch+=hstep;
638 if (angle >= final_angle)
639 break;
642 XFlush(dpy);
644 #undef FRAMES
647 static void
648 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
649 int fx, int fy, int fw, int fh, int steps)
651 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
652 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
653 float xstep, ystep, wstep, hstep;
654 int i, j;
656 xstep = (float)(fx-x)/steps;
657 ystep = (float)(fy-y)/steps;
658 wstep = (float)(fw-w)/steps;
659 hstep = (float)(fh-h)/steps;
661 for (j=0; j<FRAMES; j++) {
662 cx[j] = (float)x;
663 cy[j] = (float)y;
664 cw[j] = (float)w;
665 ch[j] = (float)h;
667 XGrabServer(dpy);
668 for (i=0; i<steps; i++) {
669 for (j=0; j<FRAMES; j++) {
670 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
671 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
673 XFlush(dpy);
674 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
675 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
676 #endif
677 for (j=0; j<FRAMES; j++) {
678 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
679 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
680 if (j<FRAMES-1) {
681 cx[j]=cx[j+1];
682 cy[j]=cy[j+1];
683 cw[j]=cw[j+1];
684 ch[j]=ch[j+1];
685 } else {
686 cx[j]+=xstep;
687 cy[j]+=ystep;
688 cw[j]+=wstep;
689 ch[j]+=hstep;
694 for (j=0; j<FRAMES; j++) {
695 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
696 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
698 XFlush(dpy);
699 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
700 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
701 #endif
702 for (j=0; j<FRAMES; j++) {
703 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
704 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
707 XUngrabServer(dpy);
709 #undef FRAMES
712 static void
713 animateResize(WScreen *scr, int x, int y, int w, int h,
714 int fx, int fy, int fw, int fh, int hiding)
716 int style = wPreferences.iconification_style; /* Catch the value */
717 int steps, k;
719 if (style == WIS_NONE)
720 return;
722 if (style == WIS_RANDOM) {
723 style = rand()%3;
726 k = (hiding ? 2 : 3);
727 switch(style) {
728 case WIS_TWIST:
729 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
730 if (steps>0)
731 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
732 break;
733 case WIS_FLIP:
734 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
735 if (steps>0)
736 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
737 break;
738 case WIS_ZOOM:
739 default:
740 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
741 if (steps>0)
742 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
743 break;
746 #endif /* ANIMATIONS */
749 static void
750 flushExpose()
752 XEvent tmpev;
754 while (XCheckTypedEvent(dpy, Expose, &tmpev))
755 WMHandleEvent(&tmpev);
756 XSync(dpy, 0);
759 static void
760 unmapTransientsFor(WWindow *wwin)
762 WWindow *tmp;
765 tmp = wwin->screen_ptr->focused_window;
766 while (tmp) {
767 /* unmap the transients for this transient */
768 if (tmp!=wwin && tmp->transient_for == wwin->client_win
769 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
770 || tmp->flags.shaded)) {
771 unmapTransientsFor(tmp);
772 tmp->flags.miniaturized = 1;
773 if (!tmp->flags.shaded) {
774 wWindowUnmap(tmp);
775 } else {
776 XUnmapWindow(dpy, tmp->frame->core->window);
779 if (!tmp->flags.shaded)
781 wClientSetState(tmp, IconicState, None);
782 #ifdef KWM_HINTS
783 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
784 wKWMSendEventMessage(tmp, WKWMRemoveWindow);
785 tmp->flags.kwm_hidden_for_modules = 1;
786 #endif
788 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
791 tmp = tmp->prev;
796 static void
797 mapTransientsFor(WWindow *wwin)
799 WWindow *tmp;
801 tmp = wwin->screen_ptr->focused_window;
802 while (tmp) {
803 /* recursively map the transients for this transient */
804 if (tmp!=wwin && tmp->transient_for == wwin->client_win
805 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
806 && tmp->icon==NULL) {
807 mapTransientsFor(tmp);
808 tmp->flags.miniaturized = 0;
809 if (!tmp->flags.shaded) {
810 wWindowMap(tmp);
811 } else {
812 XMapWindow(dpy, tmp->frame->core->window);
814 tmp->flags.semi_focused = 0;
816 if (!tmp->flags.shaded)
818 wClientSetState(tmp, NormalState, None);
819 #ifdef KWM_HINTS
820 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
821 if (tmp->flags.kwm_hidden_for_modules) {
822 wKWMSendEventMessage(tmp, WKWMAddWindow);
823 tmp->flags.kwm_hidden_for_modules = 0;
825 #endif
827 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
830 tmp = tmp->prev;
834 #if 0
835 static void
836 setupIconGrabs(WIcon *icon)
838 /* setup passive grabs on the icon */
839 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
840 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
841 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
842 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
843 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
844 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
845 XSync(dpy, 0);
847 #endif
849 static WWindow*
850 recursiveTransientFor(WWindow *wwin)
852 int i;
854 if (!wwin)
855 return None;
857 /* hackish way to detect transient_for cycle */
858 i = wwin->screen_ptr->window_count+1;
860 while (wwin && wwin->transient_for != None && i>0) {
861 wwin = wWindowFor(wwin->transient_for);
862 i--;
864 if (i==0 && wwin) {
865 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
866 wwin->frame->title);
867 return NULL;
870 return wwin;
873 #if 0
874 static void
875 removeIconGrabs(WIcon *icon)
877 /* remove passive grabs on the icon */
878 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
879 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
880 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
881 XSync(dpy, 0);
883 #endif
886 void
887 wIconifyWindow(WWindow *wwin)
889 XWindowAttributes attribs;
890 int present;
893 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
894 /* the window doesn't exist anymore */
895 return;
898 if (wwin->flags.miniaturized) {
899 return;
903 if (wwin->transient_for!=None) {
904 WWindow *owner = wWindowFor(wwin->transient_for);
906 if (owner && owner->flags.miniaturized)
907 return;
910 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
912 /* if the window is in another workspace, simplify process */
913 if (present) {
914 /* icon creation may take a while */
915 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
916 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
917 GrabModeAsync, None, None, CurrentTime);
920 if (!wPreferences.disable_miniwindows) {
921 if (!wwin->flags.icon_moved) {
922 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y);
924 wwin->icon = wIconCreate(wwin);
927 wwin->flags.miniaturized = 1;
928 wwin->flags.mapped = 0;
930 /* unmap transients */
932 unmapTransientsFor(wwin);
934 if (present) {
935 #ifdef WMSOUND
936 wSoundPlay(WMSOUND_ICONIFY);
937 #endif
939 XUngrabPointer(dpy, CurrentTime);
940 wWindowUnmap(wwin);
941 /* let all Expose events arrive so that we can repaint
942 * something before the animation starts (and the server is grabbed) */
943 XSync(dpy, 0);
945 if (wPreferences.disable_miniwindows)
946 wClientSetState(wwin, IconicState, None);
947 else
948 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
950 flushExpose();
951 #ifdef ANIMATIONS
952 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
953 && !wPreferences.no_animations) {
954 int ix, iy, iw, ih;
956 if (!wPreferences.disable_miniwindows) {
957 ix = wwin->icon_x;
958 iy = wwin->icon_y;
959 iw = wwin->icon->core->width;
960 ih = wwin->icon->core->height;
961 } else {
962 #ifdef KWM_HINTS
963 WArea area;
965 if (wKWMGetIconGeometry(wwin, &area)) {
966 ix = area.x1;
967 iy = area.y1;
968 iw = area.x2 - ix;
969 ih = area.y2 - iy;
970 } else
971 #endif /* KWM_HINTS */
973 ix = 0;
974 iy = 0;
975 iw = wwin->screen_ptr->scr_width;
976 ih = wwin->screen_ptr->scr_height;
979 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
980 wwin->frame->core->width, wwin->frame->core->height,
981 ix, iy, iw, ih, False);
983 #endif
986 wwin->flags.skip_next_animation = 0;
988 if (!wPreferences.disable_miniwindows) {
990 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
991 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
993 XMapWindow(dpy, wwin->icon->core->window);
995 AddToStackList(wwin->icon->core);
997 wLowerFrame(wwin->icon->core);
1000 if (present) {
1001 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1004 * It doesn't seem to be working and causes button event hangup
1005 * when deiconifying a transient window.
1006 setupIconGrabs(wwin->icon);
1008 if ((wwin->flags.focused
1009 || (owner && wwin->client_win == owner->client_win))
1010 && wPreferences.focus_mode==WKF_CLICK) {
1011 WWindow *tmp;
1013 tmp = wwin->prev;
1014 while (tmp) {
1015 if (!WFLAGP(tmp, no_focusable)
1016 && !(tmp->flags.hidden||tmp->flags.miniaturized))
1017 break;
1018 tmp = tmp->prev;
1020 wSetFocusTo(wwin->screen_ptr, tmp);
1021 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1022 wSetFocusTo(wwin->screen_ptr, NULL);
1025 #ifdef ANIMATIONS
1026 if (!wwin->screen_ptr->flags.startup) {
1027 Window clientwin = wwin->client_win;
1029 XSync(dpy, 0);
1030 processEvents(XPending(dpy));
1032 /* the window can disappear while doing the processEvents() */
1033 if (!wWindowFor(clientwin))
1034 return;
1036 #endif
1040 if (wwin->flags.selected && !wPreferences.disable_miniwindows)
1041 wIconSelect(wwin->icon);
1043 #ifdef GNOME_STUFF
1044 wGNOMEUpdateClientStateHint(wwin, False);
1045 #endif
1046 #ifdef KWM_HINTS
1047 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1048 wKWMSendEventMessage(wwin, WKWMChangedClient);
1049 #endif
1051 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1057 void
1058 wDeiconifyWindow(WWindow *wwin)
1060 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1062 if (!wwin->flags.miniaturized)
1063 return;
1065 if (wwin->transient_for != None
1066 && wwin->transient_for != wwin->screen_ptr->root_win) {
1067 WWindow *owner = recursiveTransientFor(wwin);
1069 if (owner && owner->flags.miniaturized) {
1070 wDeiconifyWindow(owner);
1071 wSetFocusTo(wwin->screen_ptr, wwin);
1072 wRaiseFrame(wwin->frame->core);
1073 return;
1077 wwin->flags.miniaturized = 0;
1078 if (!wwin->flags.shaded)
1079 wwin->flags.mapped = 1;
1081 if (!wPreferences.disable_miniwindows) {
1082 if (wwin->icon->selected)
1083 wIconSelect(wwin->icon);
1085 XUnmapWindow(dpy, wwin->icon->core->window);
1088 #ifdef WMSOUND
1089 wSoundPlay(WMSOUND_DEICONIFY);
1090 #endif
1092 /* if the window is in another workspace, do it silently */
1093 #ifdef ANIMATIONS
1094 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1095 && !wwin->flags.skip_next_animation) {
1096 int ix, iy, iw, ih;
1098 if (!wPreferences.disable_miniwindows) {
1099 ix = wwin->icon_x;
1100 iy = wwin->icon_y;
1101 iw = wwin->icon->core->width;
1102 ih = wwin->icon->core->height;
1103 } else {
1104 #ifdef KWM_HINTS
1105 WArea area;
1107 if (wKWMGetIconGeometry(wwin, &area)) {
1108 ix = area.x1;
1109 iy = area.y1;
1110 iw = area.x2 - ix;
1111 ih = area.y2 - iy;
1112 } else
1113 #endif /* KWM_HINTS */
1115 ix = 0;
1116 iy = 0;
1117 iw = wwin->screen_ptr->scr_width;
1118 ih = wwin->screen_ptr->scr_height;
1121 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1122 wwin->frame_x, wwin->frame_y,
1123 wwin->frame->core->width, wwin->frame->core->height,
1124 False);
1126 #endif /* ANIMATIONS */
1127 wwin->flags.skip_next_animation = 0;
1128 XGrabServer(dpy);
1129 if (!wwin->flags.shaded) {
1130 XMapWindow(dpy, wwin->client_win);
1132 XMapWindow(dpy, wwin->frame->core->window);
1133 wRaiseFrame(wwin->frame->core);
1134 if (!wwin->flags.shaded) {
1135 wClientSetState(wwin, NormalState, None);
1137 mapTransientsFor(wwin);
1139 if (!wPreferences.disable_miniwindows) {
1140 RemoveFromStackList(wwin->icon->core);
1141 /* removeIconGrabs(wwin->icon);*/
1142 wIconDestroy(wwin->icon);
1143 wwin->icon = NULL;
1145 XUngrabServer(dpy);
1146 if (wPreferences.focus_mode==WKF_CLICK
1147 || wPreferences.focus_mode==WKF_SLOPPY)
1148 wSetFocusTo(wwin->screen_ptr, wwin);
1150 #ifdef ANIMATIONS
1151 if (!wwin->screen_ptr->flags.startup) {
1152 Window clientwin = wwin->client_win;
1154 XSync(dpy, 0);
1155 processEvents(XPending(dpy));
1157 if (!wWindowFor(clientwin))
1158 return;
1160 #endif
1162 if (wPreferences.auto_arrange_icons) {
1163 wArrangeIcons(wwin->screen_ptr, True);
1166 #ifdef GNOME_STUFF
1167 wGNOMEUpdateClientStateHint(wwin, False);
1168 #endif
1169 #ifdef KWM_HINTS
1170 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1171 wKWMSendEventMessage(wwin, WKWMChangedClient);
1172 #endif
1174 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1179 static void
1180 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1182 if (wwin->flags.miniaturized) {
1183 if (wwin->icon) {
1184 XUnmapWindow(dpy, wwin->icon->core->window);
1185 wwin->icon->mapped = 0;
1187 wwin->flags.hidden = 1;
1188 #ifdef GNOME_STUFF
1189 wGNOMEUpdateClientStateHint(wwin, False);
1190 #endif
1192 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1194 return;
1197 if (wwin->flags.inspector_open) {
1198 WWindow *pwin = wwin->inspector->frame;
1200 wWindowUnmap(pwin);
1201 pwin->flags.hidden = 1;
1203 wClientSetState(pwin, IconicState, icon->icon_win);
1206 wwin->flags.hidden = 1;
1207 wWindowUnmap(wwin);
1209 wClientSetState(wwin, IconicState, icon->icon_win);
1210 flushExpose();
1211 #ifdef WMSOUND
1212 wSoundPlay(WMSOUND_HIDE);
1213 #endif
1214 #ifdef ANIMATIONS
1215 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1216 !wwin->flags.skip_next_animation && animate) {
1217 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1218 wwin->frame->core->width, wwin->frame->core->height,
1219 icon_x, icon_y, icon->core->width, icon->core->height,
1220 True);
1222 #endif
1223 wwin->flags.skip_next_animation = 0;
1225 #ifdef GNOME_STUFF
1226 wGNOMEUpdateClientStateHint(wwin, False);
1227 #endif
1229 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1234 void
1235 wHideOtherApplications(WWindow *awin)
1237 WWindow *wwin;
1238 WApplication *tapp;
1239 #ifdef REDUCE_APPICONS
1240 char *tinstance, *tclass;
1241 unsigned int brokenwin = 0, match = 0;
1242 #endif
1244 if (!awin)
1245 return;
1246 wwin = awin->screen_ptr->focused_window;
1248 #ifdef REDUCE_APPICONS
1249 if (awin->wm_instance == NULL || awin->wm_class == NULL)
1250 brokenwin++;
1251 #endif
1253 while (wwin) {
1254 if (wwin!=awin
1255 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1256 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1257 && !wwin->flags.internal_window
1258 && (!wwin->flags.inspector_open || wwin->inspector->frame!=awin)
1259 && !WFLAGP(wwin, no_hide_others)) {
1261 #ifdef REDUCE_APPICONS
1262 match = 0;
1263 if (!brokenwin) {
1264 if ((tinstance = wwin->wm_instance) == NULL)
1265 tinstance = "";
1266 if ((tclass = wwin->wm_class) == NULL)
1267 tclass = "";
1268 if ((strcmp(awin->wm_instance, tinstance) == 0) &&
1269 (strcmp(awin->wm_class, tclass) == 0) )
1270 match++;
1272 #endif
1274 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1275 if (!WFLAGP(wwin, no_miniaturizable)) {
1276 wwin->flags.skip_next_animation = 1;
1277 wIconifyWindow(wwin);
1279 } else if (wwin->main_window!=None
1280 #ifndef REDUCE_APPICONS
1281 && awin->main_window != wwin->main_window) {
1282 #else
1283 && (awin->main_window != wwin->main_window && !match)) {
1284 #endif
1285 tapp = wApplicationOf(wwin->main_window);
1286 if (tapp) {
1287 tapp->flags.skip_next_animation = 1;
1288 wHideApplication(tapp);
1289 } else {
1290 if (!WFLAGP(wwin, no_miniaturizable)) {
1291 wwin->flags.skip_next_animation = 1;
1292 wIconifyWindow(wwin);
1297 wwin = wwin->prev;
1300 wSetFocusTo(awin->screen_ptr, awin);
1306 void
1307 wHideApplication(WApplication *wapp)
1309 #ifdef REDUCE_APPICONS
1310 WApplication *tapp;
1311 char *tinstance, *tclass;
1312 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1313 #endif
1314 WScreen *scr;
1315 WWindow *wlist;
1316 int hadfocus;
1318 if (!wapp) {
1319 wwarning("trying to hide a non grouped window");
1320 return;
1322 if (!wapp->main_window_desc) {
1323 wwarning("group leader not found for window group");
1324 return;
1326 #ifdef REDUCE_APPICONS
1327 if ((wapp->main_window_desc->wm_instance == NULL) ||
1328 (wapp->main_window_desc->wm_class == NULL))
1329 nowmhints++;
1330 #endif
1331 scr = wapp->main_window_desc->screen_ptr;
1332 hadfocus = 0;
1333 wlist = scr->focused_window;
1334 if (!wlist)
1335 return;
1337 if (wlist->main_window == wapp->main_window)
1338 wapp->last_focused = wlist;
1339 else
1340 wapp->last_focused = NULL;
1341 while (wlist) {
1342 #ifdef REDUCE_APPICONS
1343 matchwmhints = matchworkspace = 0;
1344 if (!nowmhints) {
1345 tapp = wApplicationOf(wlist->main_window);
1346 tinstance = tclass = NULL;
1347 if (tapp) {
1348 if (tapp->main_window_desc) {
1349 tinstance = tapp->main_window_desc->wm_instance;
1350 tclass = tapp->main_window_desc->wm_class;
1353 if (tapp == NULL || tinstance == NULL || tclass == NULL) {
1354 /* Should never reach here */
1355 tinstance = "";
1356 tclass = "";
1358 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0) &&
1359 (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1360 matchwmhints++;
1362 if (wlist->frame) {
1363 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1364 matchworkspace++;
1366 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1367 matchworkspace) {
1368 #ifdef I_HATE_THIS
1370 #endif
1371 #else
1372 if (wlist->main_window == wapp->main_window) {
1373 #endif
1374 if (wlist->flags.focused) {
1375 hadfocus = 1;
1377 if (wapp->app_icon)
1378 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1379 wapp->app_icon->y_pos, wlist,
1380 !wapp->flags.skip_next_animation);
1382 wlist = wlist->prev;
1385 wapp->flags.skip_next_animation = 0;
1387 if (hadfocus) {
1388 if (wPreferences.focus_mode==WKF_CLICK) {
1389 wlist = scr->focused_window;
1390 while (wlist) {
1391 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1392 && (wlist->flags.mapped || wlist->flags.shaded))
1393 break;
1394 wlist = wlist->prev;
1396 wSetFocusTo(scr, wlist);
1397 } else {
1398 wSetFocusTo(scr, NULL);
1402 wapp->flags.hidden = 1;
1404 if(wPreferences.auto_arrange_icons) {
1405 wArrangeIcons(scr, True);
1407 #ifdef HIDDENDOT
1408 if (wapp->app_icon)
1409 wAppIconPaint(wapp->app_icon);
1410 #endif
1416 static void
1417 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1418 int bringToCurrentWS)
1420 if (bringToCurrentWS)
1421 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1423 wwin->flags.hidden=0;
1424 wwin->flags.mapped=1;
1426 #ifdef WMSOUND
1427 wSoundPlay(WMSOUND_UNHIDE);
1428 #endif
1429 #ifdef ANIMATIONS
1430 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1431 && animate) {
1432 animateResize(wwin->screen_ptr, icon_x, icon_y,
1433 icon->core->width, icon->core->height,
1434 wwin->frame_x, wwin->frame_y,
1435 wwin->frame->core->width, wwin->frame->core->height,
1436 True);
1438 #endif
1439 wwin->flags.skip_next_animation = 0;
1440 XMapWindow(dpy, wwin->client_win);
1441 XMapWindow(dpy, wwin->frame->core->window);
1442 wClientSetState(wwin, NormalState, None);
1443 wRaiseFrame(wwin->frame->core);
1444 if (wwin->flags.inspector_open) {
1445 WWindow *pwin = wwin->inspector->frame;
1447 pwin->flags.hidden = 0;
1448 pwin->flags.mapped = 1;
1449 XMapWindow(dpy, pwin->client_win);
1450 XMapWindow(dpy, pwin->frame->core->window);
1451 wClientSetState(pwin, NormalState, None);
1454 #ifdef GNOME_STUFF
1455 wGNOMEUpdateClientStateHint(wwin, False);
1456 #endif
1458 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1463 void
1464 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1466 WScreen *scr;
1467 WWindow *wlist, *next;
1468 WWindow *focused=NULL;
1469 #ifdef REDUCE_APPICONS
1470 char *tinstance, *tclass;
1471 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1472 #endif
1474 if (!wapp) {
1475 return;
1478 #ifdef REDUCE_APPICONS
1479 if ((wapp->main_window_desc->wm_class == NULL) ||
1480 (wapp->main_window_desc->wm_instance == NULL))
1481 nowmhints++;
1482 #endif
1484 scr = wapp->main_window_desc->screen_ptr;
1485 wlist = scr->focused_window;
1486 if (!wlist) return;
1487 /* goto beginning of list */
1488 while (wlist->prev)
1489 wlist = wlist->prev;
1491 while (wlist) {
1492 next = wlist->next;
1494 #ifndef REDUCE_APPICONS
1495 if (wlist->main_window == wapp->main_window) {
1496 #else
1497 matchwmhints = matchworkspace = 0;
1498 if (!nowmhints) {
1499 if ((tinstance = wlist->wm_instance) == NULL)
1500 tinstance = "";
1501 if ((tclass = wlist->wm_class) == NULL)
1502 tclass = "";
1503 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0)
1504 && (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1505 matchwmhints++;
1507 if (wlist->frame) {
1508 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1509 matchworkspace++;
1512 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1513 matchworkspace) {
1514 #endif
1515 if (wlist->flags.focused)
1516 focused = wlist;
1517 else if (!focused || !focused->flags.focused)
1518 focused = wlist;
1520 if (wlist->flags.miniaturized && wlist->icon) {
1521 if (bringToCurrentWS || wPreferences.sticky_icons
1522 || wlist->frame->workspace == scr->current_workspace) {
1523 if (!wlist->icon->mapped) {
1524 XMapWindow(dpy, wlist->icon->core->window);
1525 wlist->icon->mapped = 1;
1527 wlist->flags.hidden = 0;
1529 UpdateSwitchMenu(scr, wlist, ACTION_CHANGE_STATE);
1531 if (wlist->frame->workspace != scr->current_workspace)
1532 wWindowChangeWorkspace(wlist, scr->current_workspace);
1534 if (miniwindows) {
1535 wDeiconifyWindow(wlist);
1537 } else if (wlist->flags.hidden) {
1538 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1539 wapp->app_icon->y_pos, wlist,
1540 !wapp->flags.skip_next_animation,
1541 bringToCurrentWS);
1542 } else {
1543 if (bringToCurrentWS
1544 && wlist->frame->workspace != scr->current_workspace) {
1545 wWindowChangeWorkspace(wlist, scr->current_workspace);
1547 wRaiseFrame(wlist->frame->core);
1550 wlist = next;
1553 wapp->flags.skip_next_animation = 0;
1554 wapp->flags.hidden = 0;
1556 if (focused)
1557 wSetFocusTo(scr, focused);
1558 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1559 wSetFocusTo(scr, wapp->last_focused);
1560 wapp->last_focused = NULL;
1561 if (wPreferences.auto_arrange_icons) {
1562 wArrangeIcons(scr, True);
1564 #ifdef HIDDENDOT
1565 wAppIconPaint(wapp->app_icon);
1566 #endif
1571 void
1572 wShowAllWindows(WScreen *scr)
1574 WWindow *wwin, *old_foc;
1575 WApplication *wapp;
1577 old_foc = wwin = scr->focused_window;
1578 while (wwin) {
1579 if (!wwin->flags.internal_window &&
1580 (scr->current_workspace == wwin->frame->workspace
1581 || IS_OMNIPRESENT(wwin))) {
1582 if (wwin->flags.miniaturized) {
1583 wwin->flags.skip_next_animation = 1;
1584 wDeiconifyWindow(wwin);
1585 } else if (wwin->flags.hidden) {
1586 wapp = wApplicationOf(wwin->main_window);
1587 if (wapp) {
1588 wUnhideApplication(wapp, False, False);
1589 } else {
1590 wwin->flags.skip_next_animation = 1;
1591 wDeiconifyWindow(wwin);
1595 wwin = wwin->prev;
1597 wSetFocusTo(scr, old_foc);
1598 /*wRaiseFrame(old_foc->frame->core);*/
1602 void
1603 wRefreshDesktop(WScreen *scr)
1605 Window win;
1606 XSetWindowAttributes attr;
1608 attr.backing_store = NotUseful;
1609 attr.save_under = False;
1610 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1611 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1612 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1613 &attr);
1614 XMapRaised(dpy, win);
1615 XDestroyWindow(dpy, win);
1616 XFlush(dpy);
1620 void
1621 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1623 WWindow *wwin;
1624 WAppIcon *aicon;
1625 int pf; /* primary axis */
1626 int sf; /* secondary axis */
1627 int fullW;
1628 int fullH;
1629 int pi, si;
1630 int sx1, sx2, sy1, sy2; /* screen boundary */
1631 int sw, sh;
1632 int xo, yo;
1633 int xs, ys;
1634 int isize = wPreferences.icon_size;
1637 * Find out screen boundaries.
1639 sx1 = 0;
1640 sy1 = 0;
1641 sx2 = scr->scr_width;
1642 sy2 = scr->scr_height;
1643 if (scr->dock) {
1644 if (scr->dock->on_right_side)
1645 sx2 -= isize + DOCK_EXTRA_SPACE;
1646 else
1647 sx1 += isize + DOCK_EXTRA_SPACE;
1650 sw = isize * (scr->scr_width/isize);
1651 sh = isize * (scr->scr_height/isize);
1652 fullW = (sx2-sx1)/isize;
1653 fullH = (sy2-sy1)/isize;
1655 /* icon yard boundaries */
1656 if (wPreferences.icon_yard & IY_VERT) {
1657 pf = fullH;
1658 sf = fullW;
1659 } else {
1660 pf = fullW;
1661 sf = fullH;
1663 if (wPreferences.icon_yard & IY_RIGHT) {
1664 xo = sx2 - isize;
1665 xs = -1;
1666 } else {
1667 xo = sx1;
1668 xs = 1;
1670 if (wPreferences.icon_yard & IY_TOP) {
1671 yo = sy1;
1672 ys = 1;
1673 } else {
1674 yo = sy2 - isize;
1675 ys = -1;
1678 /* arrange icons putting the most recently focused window
1679 * as the last icon */
1680 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1681 : xo + xs*(pi*isize))
1682 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1683 : yo + ys*(si*isize))
1685 /* arrange application icons */
1686 aicon = scr->app_icon_list;
1687 /* reverse them to avoid unnecessarily sliding of icons */
1688 while (aicon && aicon->next)
1689 aicon = aicon->next;
1691 pi = 0;
1692 si = 0;
1693 while (aicon) {
1694 if (!aicon->docked) {
1695 if (aicon->x_pos != X || aicon->y_pos != Y) {
1696 #ifdef ANIMATIONS
1697 if (!wPreferences.no_animations) {
1698 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1699 X, Y);
1701 #endif /* ANIMATIONS */
1703 wAppIconMove(aicon, X, Y);
1704 pi++;
1706 /* we reversed the order so we use prev */
1707 aicon = aicon->prev;
1708 if (pi >= pf) {
1709 pi=0;
1710 si++;
1714 /* arrange miniwindows */
1716 wwin = scr->focused_window;
1717 /* reverse them to avoid unnecessarily shuffling */
1718 while (wwin && wwin->prev)
1719 wwin = wwin->prev;
1721 while (wwin) {
1722 if (wwin->icon && wwin->flags.miniaturized &&/*!wwin->flags.hidden &&*/
1723 (wwin->frame->workspace==scr->current_workspace ||
1724 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1726 if (arrangeAll || !wwin->flags.icon_moved) {
1727 if (wwin->icon_x != X || wwin->icon_y != Y) {
1728 #ifdef ANIMATIONS
1729 if (wPreferences.no_animations) {
1730 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1731 } else {
1732 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1733 wwin->icon_y, X, Y);
1735 #else
1736 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1737 #endif /* ANIMATIONS */
1739 wwin->icon_x = X;
1740 wwin->icon_y = Y;
1741 pi++;
1744 if (arrangeAll) {
1745 wwin->flags.icon_moved = 0;
1747 /* we reversed the order, so we use next */
1748 wwin = wwin->next;
1749 if (pi >= pf) {
1750 pi=0;
1751 si++;
1757 void
1758 wSelectWindow(WWindow *wwin, Bool flag)
1760 WScreen *scr = wwin->screen_ptr;
1761 if (flag) {
1762 wwin->flags.selected = 1;
1763 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1764 scr->selected_windows = list_cons(wwin, scr->selected_windows);
1765 } else {
1766 wwin->flags.selected = 0;
1767 XSetWindowBorder(dpy, wwin->frame->core->window,
1768 scr->frame_border_pixel);
1769 scr->selected_windows = list_remove_elem(scr->selected_windows, wwin);
1774 void
1775 wMakeWindowVisible(WWindow *wwin)
1777 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1779 if (wwin->flags.shaded) {
1780 wUnshadeWindow(wwin);
1782 if (wwin->flags.hidden) {
1783 WApplication *app;
1785 app = wApplicationOf(wwin->main_window);
1786 if (app)
1787 wUnhideApplication(app, False, False);
1788 } else if (wwin->flags.miniaturized) {
1789 wDeiconifyWindow(wwin);
1790 } else {
1791 wSetFocusTo(wwin->screen_ptr, wwin);
1792 wRaiseFrame(wwin->frame->core);