added WMGetLabelFont()
[wmaker-crm.git] / src / actions.c
blobce27b36f4c6f3418854f29bc7d1f9e3fa6c0474a
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 WSOUND
59 #include "wsound.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 WSOUND
276 wSoundPlay(WSOUND_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 WSOUND
363 wSoundPlay(WSOUND_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 XFlush(dpy);
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;
429 WArea totalArea;
432 if (WFLAGP(wwin, no_resizable))
433 return;
435 totalArea.x1 = 0;
436 totalArea.y1 = 0;
437 totalArea.x2 = wwin->screen_ptr->scr_width;
438 totalArea.y2 = wwin->screen_ptr->scr_height;
440 #ifdef XINERAMA
441 if (wwin->screen_ptr->xine_count > 0
442 && !(directions & MAX_IGNORE_XINERAMA)) {
443 WScreen *scr = wwin->screen_ptr;
444 WMRect rect;
446 rect = wGetRectForHead(scr, wGetHeadForWindow(wwin));
447 totalArea.x1 = rect.pos.x;
448 totalArea.y1 = rect.pos.y;
449 totalArea.x2 = totalArea.x1 + rect.size.width;
450 totalArea.y2 = totalArea.y1 + rect.size.height;
452 usableArea.x1 = WMAX(totalArea.x1, usableArea.x1);
453 usableArea.y1 = WMAX(totalArea.y1, usableArea.y1);
454 usableArea.x2 = WMIN(totalArea.x2, usableArea.x2);
455 usableArea.y2 = WMIN(totalArea.y2, usableArea.y2);
457 #endif /* XINERAMA */
459 if (WFLAGP(wwin, full_maximize)) {
460 usableArea = totalArea;
463 if (wwin->flags.shaded) {
464 wwin->flags.skip_next_animation = 1;
465 wUnshadeWindow(wwin);
467 wwin->flags.maximized = directions;
468 wwin->old_geometry.width = wwin->client.width;
469 wwin->old_geometry.height = wwin->client.height;
470 wwin->old_geometry.x = wwin->frame_x;
471 wwin->old_geometry.y = wwin->frame_y;
473 #ifdef KWM_HINTS
474 wKWMUpdateClientGeometryRestore(wwin);
475 #endif
477 if (directions & MAX_HORIZONTAL) {
479 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
480 new_x = usableArea.x1;
482 } else {
484 new_x = wwin->frame_x;
485 new_width = wwin->frame->core->width;
489 if (directions & MAX_VERTICAL) {
491 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
492 new_y = usableArea.y1;
493 if (WFLAGP(wwin, full_maximize)) {
494 new_y -= wwin->frame->top_width;
495 new_height += wwin->frame->bottom_width - 1;
497 } else {
498 new_y = wwin->frame_y;
499 new_height = wwin->frame->core->height;
502 if (!WFLAGP(wwin, full_maximize)) {
503 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
506 wWindowConstrainSize(wwin, &new_width, &new_height);
507 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
509 #ifdef GNOME_STUFF
510 wGNOMEUpdateClientStateHint(wwin, False);
511 #endif
512 #ifdef KWM_HINTS
513 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
514 wKWMSendEventMessage(wwin, WKWMChangedClient);
515 #endif
517 #ifdef WSOUND
518 wSoundPlay(WSOUND_MAXIMIZE);
519 #endif
523 void
524 wUnmaximizeWindow(WWindow *wwin)
526 int restore_x, restore_y;
528 if (!wwin->flags.maximized)
529 return;
531 if (wwin->flags.shaded) {
532 wwin->flags.skip_next_animation = 1;
533 wUnshadeWindow(wwin);
535 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
536 wwin->old_geometry.x : wwin->frame_x;
537 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
538 wwin->old_geometry.y : wwin->frame_y;
539 wwin->flags.maximized = 0;
540 wWindowConfigure(wwin, restore_x, restore_y,
541 wwin->old_geometry.width, wwin->old_geometry.height);
543 #ifdef GNOME_STUFF
544 wGNOMEUpdateClientStateHint(wwin, False);
545 #endif
546 #ifdef KWM_HINTS
547 wKWMUpdateClientStateHint(wwin, KWMMaximizedFlag);
548 wKWMSendEventMessage(wwin, WKWMChangedClient);
549 #endif
551 #ifdef WSOUND
552 wSoundPlay(WSOUND_UNMAXIMIZE);
553 #endif
556 #ifdef ANIMATIONS
557 static void
558 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
559 int fx, int fy, int fw, int fh, int steps)
561 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
562 float cx, cy, cw, ch;
563 float xstep, ystep, wstep, hstep;
564 XPoint points[5];
565 float dx, dch, midy;
566 float angle, final_angle, delta;
568 xstep = (float)(fx-x)/steps;
569 ystep = (float)(fy-y)/steps;
570 wstep = (float)(fw-w)/steps;
571 hstep = (float)(fh-h)/steps;
573 cx = (float)x;
574 cy = (float)y;
575 cw = (float)w;
576 ch = (float)h;
578 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
579 delta = (float)(final_angle/FRAMES);
580 for (angle=0;; angle+=delta) {
581 if (angle > final_angle)
582 angle = final_angle;
584 dx = (cw/10) - ((cw/5) * sin(angle));
585 dch = (ch/2) * cos(angle);
586 midy = cy + (ch/2);
588 points[0].x = cx + dx; points[0].y = midy - dch;
589 points[1].x = cx + cw - dx; points[1].y = points[0].y;
590 points[2].x = cx + cw + dx; points[2].y = midy + dch;
591 points[3].x = cx - dx; points[3].y = points[2].y;
592 points[4].x = points[0].x; points[4].y = points[0].y;
594 XGrabServer(dpy);
595 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
596 XFlush(dpy);
597 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
598 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
599 #endif
601 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
602 XUngrabServer(dpy);
603 cx+=xstep;
604 cy+=ystep;
605 cw+=wstep;
606 ch+=hstep;
607 if (angle >= final_angle)
608 break;
611 XFlush(dpy);
613 #undef FRAMES
616 static void
617 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
618 int fx, int fy, int fw, int fh, int steps)
620 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
621 float cx, cy, cw, ch;
622 float xstep, ystep, wstep, hstep;
623 XPoint points[5];
624 float angle, final_angle, a, d, delta;
626 x += w/2;
627 y += h/2;
628 fx += fw/2;
629 fy += fh/2;
631 xstep = (float)(fx-x)/steps;
632 ystep = (float)(fy-y)/steps;
633 wstep = (float)(fw-w)/steps;
634 hstep = (float)(fh-h)/steps;
636 cx = (float)x;
637 cy = (float)y;
638 cw = (float)w;
639 ch = (float)h;
641 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
642 delta = (float)(final_angle/FRAMES);
643 for (angle=0;; angle+=delta) {
644 if (angle > final_angle)
645 angle = final_angle;
647 a = atan(ch/cw);
648 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
650 points[0].x = cx+cos(angle-a)*d;
651 points[0].y = cy+sin(angle-a)*d;
652 points[1].x = cx+cos(angle+a)*d;
653 points[1].y = cy+sin(angle+a)*d;
654 points[2].x = cx+cos(angle-a+WM_PI)*d;
655 points[2].y = cy+sin(angle-a+WM_PI)*d;
656 points[3].x = cx+cos(angle+a+WM_PI)*d;
657 points[3].y = cy+sin(angle+a+WM_PI)*d;
658 points[4].x = cx+cos(angle-a)*d;
659 points[4].y = cy+sin(angle-a)*d;
660 XGrabServer(dpy);
661 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
662 XFlush(dpy);
663 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
664 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
665 #endif
667 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
668 XUngrabServer(dpy);
669 cx+=xstep;
670 cy+=ystep;
671 cw+=wstep;
672 ch+=hstep;
673 if (angle >= final_angle)
674 break;
677 XFlush(dpy);
679 #undef FRAMES
682 static void
683 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
684 int fx, int fy, int fw, int fh, int steps)
686 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
687 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
688 float xstep, ystep, wstep, hstep;
689 int i, j;
691 xstep = (float)(fx-x)/steps;
692 ystep = (float)(fy-y)/steps;
693 wstep = (float)(fw-w)/steps;
694 hstep = (float)(fh-h)/steps;
696 for (j=0; j<FRAMES; j++) {
697 cx[j] = (float)x;
698 cy[j] = (float)y;
699 cw[j] = (float)w;
700 ch[j] = (float)h;
702 XGrabServer(dpy);
703 for (i=0; i<steps; i++) {
704 for (j=0; j<FRAMES; j++) {
705 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
706 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
708 XFlush(dpy);
709 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
710 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
711 #endif
712 for (j=0; j<FRAMES; j++) {
713 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
714 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
715 if (j<FRAMES-1) {
716 cx[j]=cx[j+1];
717 cy[j]=cy[j+1];
718 cw[j]=cw[j+1];
719 ch[j]=ch[j+1];
720 } else {
721 cx[j]+=xstep;
722 cy[j]+=ystep;
723 cw[j]+=wstep;
724 ch[j]+=hstep;
729 for (j=0; j<FRAMES; j++) {
730 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
731 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
733 XFlush(dpy);
734 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
735 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
736 #endif
737 for (j=0; j<FRAMES; j++) {
738 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
739 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
742 XUngrabServer(dpy);
744 #undef FRAMES
747 static void
748 animateResize(WScreen *scr, int x, int y, int w, int h,
749 int fx, int fy, int fw, int fh, int hiding)
751 int style = wPreferences.iconification_style; /* Catch the value */
752 int steps, k;
754 if (style == WIS_NONE)
755 return;
757 if (style == WIS_RANDOM) {
758 style = rand()%3;
761 k = (hiding ? 2 : 3);
762 switch(style) {
763 case WIS_TWIST:
764 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
765 if (steps>0)
766 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
767 break;
768 case WIS_FLIP:
769 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
770 if (steps>0)
771 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
772 break;
773 case WIS_ZOOM:
774 default:
775 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
776 if (steps>0)
777 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
778 break;
781 #endif /* ANIMATIONS */
784 static void
785 flushExpose()
787 XEvent tmpev;
789 while (XCheckTypedEvent(dpy, Expose, &tmpev))
790 WMHandleEvent(&tmpev);
791 XSync(dpy, 0);
794 static void
795 unmapTransientsFor(WWindow *wwin)
797 WWindow *tmp;
800 tmp = wwin->screen_ptr->focused_window;
801 while (tmp) {
802 /* unmap the transients for this transient */
803 if (tmp!=wwin && tmp->transient_for == wwin->client_win
804 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
805 || tmp->flags.shaded)) {
806 unmapTransientsFor(tmp);
807 tmp->flags.miniaturized = 1;
808 if (!tmp->flags.shaded) {
809 wWindowUnmap(tmp);
810 } else {
811 XUnmapWindow(dpy, tmp->frame->core->window);
814 if (!tmp->flags.shaded)
816 wClientSetState(tmp, IconicState, None);
817 #ifdef KWM_HINTS
818 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
819 wKWMSendEventMessage(tmp, WKWMRemoveWindow);
820 tmp->flags.kwm_hidden_for_modules = 1;
821 #endif
823 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
826 tmp = tmp->prev;
831 static void
832 mapTransientsFor(WWindow *wwin)
834 WWindow *tmp;
836 tmp = wwin->screen_ptr->focused_window;
837 while (tmp) {
838 /* recursively map the transients for this transient */
839 if (tmp!=wwin && tmp->transient_for == wwin->client_win
840 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
841 && tmp->icon==NULL) {
842 mapTransientsFor(tmp);
843 tmp->flags.miniaturized = 0;
844 if (!tmp->flags.shaded) {
845 wWindowMap(tmp);
846 } else {
847 XMapWindow(dpy, tmp->frame->core->window);
849 tmp->flags.semi_focused = 0;
851 if (!tmp->flags.shaded)
853 wClientSetState(tmp, NormalState, None);
854 #ifdef KWM_HINTS
855 wKWMUpdateClientStateHint(tmp, KWMIconifiedFlag);
856 if (tmp->flags.kwm_hidden_for_modules) {
857 wKWMSendEventMessage(tmp, WKWMAddWindow);
858 tmp->flags.kwm_hidden_for_modules = 0;
860 #endif
862 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
865 tmp = tmp->prev;
869 #if 0
870 static void
871 setupIconGrabs(WIcon *icon)
873 /* setup passive grabs on the icon */
874 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
875 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
876 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
877 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
878 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
879 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
880 XSync(dpy, 0);
882 #endif
884 static WWindow*
885 recursiveTransientFor(WWindow *wwin)
887 int i;
889 if (!wwin)
890 return None;
892 /* hackish way to detect transient_for cycle */
893 i = wwin->screen_ptr->window_count+1;
895 while (wwin && wwin->transient_for != None && i>0) {
896 wwin = wWindowFor(wwin->transient_for);
897 i--;
899 if (i==0 && wwin) {
900 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
901 wwin->frame->title);
902 return NULL;
905 return wwin;
908 #if 0
909 static void
910 removeIconGrabs(WIcon *icon)
912 /* remove passive grabs on the icon */
913 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
914 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
915 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
916 XSync(dpy, 0);
918 #endif
921 void
922 wIconifyWindow(WWindow *wwin)
924 XWindowAttributes attribs;
925 int present;
928 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
929 /* the window doesn't exist anymore */
930 return;
933 if (wwin->flags.miniaturized) {
934 return;
938 if (wwin->transient_for!=None) {
939 WWindow *owner = wWindowFor(wwin->transient_for);
941 if (owner && owner->flags.miniaturized)
942 return;
945 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
947 /* if the window is in another workspace, simplify process */
948 if (present) {
949 /* icon creation may take a while */
950 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
951 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
952 GrabModeAsync, None, None, CurrentTime);
955 if (!wPreferences.disable_miniwindows) {
956 if (!wwin->flags.icon_moved) {
957 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y);
959 wwin->icon = wIconCreate(wwin);
961 wwin->icon->mapped = 1;
964 wwin->flags.miniaturized = 1;
965 wwin->flags.mapped = 0;
967 /* unmap transients */
969 unmapTransientsFor(wwin);
971 if (present) {
972 #ifdef WSOUND
973 wSoundPlay(WSOUND_ICONIFY);
974 #endif
976 XUngrabPointer(dpy, CurrentTime);
977 wWindowUnmap(wwin);
978 /* let all Expose events arrive so that we can repaint
979 * something before the animation starts (and the server is grabbed) */
980 XSync(dpy, 0);
982 if (wPreferences.disable_miniwindows)
983 wClientSetState(wwin, IconicState, None);
984 else
985 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
987 flushExpose();
988 #ifdef ANIMATIONS
989 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
990 && !wPreferences.no_animations) {
991 int ix, iy, iw, ih;
993 if (!wPreferences.disable_miniwindows) {
994 ix = wwin->icon_x;
995 iy = wwin->icon_y;
996 iw = wwin->icon->core->width;
997 ih = wwin->icon->core->height;
998 } else {
999 #ifdef KWM_HINTS
1000 WArea area;
1002 if (wKWMGetIconGeometry(wwin, &area)) {
1003 ix = area.x1;
1004 iy = area.y1;
1005 iw = area.x2 - ix;
1006 ih = area.y2 - iy;
1007 } else
1008 #endif /* KWM_HINTS */
1010 ix = 0;
1011 iy = 0;
1012 iw = wwin->screen_ptr->scr_width;
1013 ih = wwin->screen_ptr->scr_height;
1016 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1017 wwin->frame->core->width, wwin->frame->core->height,
1018 ix, iy, iw, ih, False);
1020 #endif
1023 wwin->flags.skip_next_animation = 0;
1025 if (!wPreferences.disable_miniwindows) {
1027 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
1028 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1030 XMapWindow(dpy, wwin->icon->core->window);
1032 AddToStackList(wwin->icon->core);
1034 wLowerFrame(wwin->icon->core);
1037 if (present) {
1038 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1041 * It doesn't seem to be working and causes button event hangup
1042 * when deiconifying a transient window.
1043 setupIconGrabs(wwin->icon);
1045 if ((wwin->flags.focused
1046 || (owner && wwin->client_win == owner->client_win))
1047 && wPreferences.focus_mode==WKF_CLICK) {
1048 WWindow *tmp;
1050 tmp = wwin->prev;
1051 while (tmp) {
1052 if (!WFLAGP(tmp, no_focusable)
1053 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1054 && (wwin->frame->workspace == tmp->frame->workspace))
1055 break;
1056 tmp = tmp->prev;
1058 wSetFocusTo(wwin->screen_ptr, tmp);
1059 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1060 wSetFocusTo(wwin->screen_ptr, NULL);
1063 #ifdef ANIMATIONS
1064 if (!wwin->screen_ptr->flags.startup) {
1065 Window clientwin = wwin->client_win;
1067 XSync(dpy, 0);
1068 processEvents(XPending(dpy));
1070 /* the window can disappear while doing the processEvents() */
1071 if (!wWindowFor(clientwin))
1072 return;
1074 #endif
1078 if (wwin->flags.selected && !wPreferences.disable_miniwindows)
1079 wIconSelect(wwin->icon);
1081 #ifdef GNOME_STUFF
1082 wGNOMEUpdateClientStateHint(wwin, False);
1083 #endif
1084 #ifdef KWM_HINTS
1085 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1086 wKWMSendEventMessage(wwin, WKWMChangedClient);
1087 #endif
1089 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1095 void
1096 wDeiconifyWindow(WWindow *wwin)
1098 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1100 if (!wwin->flags.miniaturized)
1101 return;
1103 if (wwin->transient_for != None
1104 && wwin->transient_for != wwin->screen_ptr->root_win) {
1105 WWindow *owner = recursiveTransientFor(wwin);
1107 if (owner && owner->flags.miniaturized) {
1108 wDeiconifyWindow(owner);
1109 wSetFocusTo(wwin->screen_ptr, wwin);
1110 wRaiseFrame(wwin->frame->core);
1111 return;
1115 wwin->flags.miniaturized = 0;
1116 if (!wwin->flags.shaded)
1117 wwin->flags.mapped = 1;
1119 if (!wPreferences.disable_miniwindows) {
1120 if (wwin->icon->selected)
1121 wIconSelect(wwin->icon);
1123 XUnmapWindow(dpy, wwin->icon->core->window);
1126 #ifdef WSOUND
1127 wSoundPlay(WSOUND_DEICONIFY);
1128 #endif
1130 /* if the window is in another workspace, do it silently */
1131 #ifdef ANIMATIONS
1132 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1133 && !wwin->flags.skip_next_animation) {
1134 int ix, iy, iw, ih;
1136 if (!wPreferences.disable_miniwindows) {
1137 ix = wwin->icon_x;
1138 iy = wwin->icon_y;
1139 iw = wwin->icon->core->width;
1140 ih = wwin->icon->core->height;
1141 } else {
1142 #ifdef KWM_HINTS
1143 WArea area;
1145 if (wKWMGetIconGeometry(wwin, &area)) {
1146 ix = area.x1;
1147 iy = area.y1;
1148 iw = area.x2 - ix;
1149 ih = area.y2 - iy;
1150 } else
1151 #endif /* KWM_HINTS */
1153 ix = 0;
1154 iy = 0;
1155 iw = wwin->screen_ptr->scr_width;
1156 ih = wwin->screen_ptr->scr_height;
1159 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1160 wwin->frame_x, wwin->frame_y,
1161 wwin->frame->core->width, wwin->frame->core->height,
1162 False);
1164 #endif /* ANIMATIONS */
1165 wwin->flags.skip_next_animation = 0;
1166 XGrabServer(dpy);
1167 if (!wwin->flags.shaded) {
1168 XMapWindow(dpy, wwin->client_win);
1170 XMapWindow(dpy, wwin->frame->core->window);
1171 wRaiseFrame(wwin->frame->core);
1172 if (!wwin->flags.shaded) {
1173 wClientSetState(wwin, NormalState, None);
1175 mapTransientsFor(wwin);
1177 if (!wPreferences.disable_miniwindows) {
1178 RemoveFromStackList(wwin->icon->core);
1179 /* removeIconGrabs(wwin->icon);*/
1180 wIconDestroy(wwin->icon);
1181 wwin->icon = NULL;
1183 XUngrabServer(dpy);
1185 if (wPreferences.focus_mode==WKF_CLICK)
1186 wSetFocusTo(wwin->screen_ptr, wwin);
1188 #ifdef ANIMATIONS
1189 if (!wwin->screen_ptr->flags.startup) {
1190 Window clientwin = wwin->client_win;
1192 XSync(dpy, 0);
1193 processEvents(XPending(dpy));
1195 if (!wWindowFor(clientwin))
1196 return;
1198 #endif
1200 if (wPreferences.auto_arrange_icons) {
1201 wArrangeIcons(wwin->screen_ptr, True);
1204 #ifdef GNOME_STUFF
1205 wGNOMEUpdateClientStateHint(wwin, False);
1206 #endif
1207 #ifdef KWM_HINTS
1208 wKWMUpdateClientStateHint(wwin, KWMIconifiedFlag);
1209 wKWMSendEventMessage(wwin, WKWMChangedClient);
1210 #endif
1212 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1217 static void
1218 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1220 if (wwin->flags.miniaturized) {
1221 if (wwin->icon) {
1222 XUnmapWindow(dpy, wwin->icon->core->window);
1223 wwin->icon->mapped = 0;
1225 wwin->flags.hidden = 1;
1226 #ifdef GNOME_STUFF
1227 wGNOMEUpdateClientStateHint(wwin, False);
1228 #endif
1230 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1232 return;
1235 if (wwin->flags.inspector_open) {
1236 wHideInspectorForWindow(wwin);
1239 wwin->flags.hidden = 1;
1240 wWindowUnmap(wwin);
1242 wClientSetState(wwin, IconicState, icon->icon_win);
1243 flushExpose();
1244 #ifdef WSOUND
1245 wSoundPlay(WSOUND_HIDE);
1246 #endif
1247 #ifdef ANIMATIONS
1248 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1249 !wwin->flags.skip_next_animation && animate) {
1250 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1251 wwin->frame->core->width, wwin->frame->core->height,
1252 icon_x, icon_y, icon->core->width, icon->core->height,
1253 True);
1255 #endif
1256 wwin->flags.skip_next_animation = 0;
1258 #ifdef GNOME_STUFF
1259 wGNOMEUpdateClientStateHint(wwin, False);
1260 #endif
1262 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1267 void
1268 wHideOtherApplications(WWindow *awin)
1270 WWindow *wwin;
1271 WApplication *tapp;
1273 if (!awin)
1274 return;
1275 wwin = awin->screen_ptr->focused_window;
1278 while (wwin) {
1279 if (wwin!=awin
1280 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1281 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1282 && !wwin->flags.internal_window
1283 && wGetWindowOfInspectorForWindow(wwin) != awin
1284 && !WFLAGP(wwin, no_hide_others)) {
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 && awin->main_window != wwin->main_window) {
1293 tapp = wApplicationOf(wwin->main_window);
1294 if (tapp) {
1295 tapp->flags.skip_next_animation = 1;
1296 wHideApplication(tapp);
1297 } else {
1298 if (!WFLAGP(wwin, no_miniaturizable)) {
1299 wwin->flags.skip_next_animation = 1;
1300 wIconifyWindow(wwin);
1305 wwin = wwin->prev;
1308 wSetFocusTo(awin->screen_ptr, awin);
1314 void
1315 wHideApplication(WApplication *wapp)
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 scr = wapp->main_window_desc->screen_ptr;
1330 hadfocus = 0;
1331 wlist = scr->focused_window;
1332 if (!wlist)
1333 return;
1335 if (wlist->main_window == wapp->main_window)
1336 wapp->last_focused = wlist;
1337 else
1338 wapp->last_focused = NULL;
1339 while (wlist) {
1340 if (wlist->main_window == wapp->main_window) {
1341 if (wlist->flags.focused) {
1342 hadfocus = 1;
1344 if (wapp->app_icon)
1345 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1346 wapp->app_icon->y_pos, wlist,
1347 !wapp->flags.skip_next_animation);
1349 wlist = wlist->prev;
1352 wapp->flags.skip_next_animation = 0;
1354 if (hadfocus) {
1355 if (wPreferences.focus_mode==WKF_CLICK) {
1356 wlist = scr->focused_window;
1357 while (wlist) {
1358 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1359 && (wlist->flags.mapped || wlist->flags.shaded))
1360 break;
1361 wlist = wlist->prev;
1363 wSetFocusTo(scr, wlist);
1364 } else {
1365 wSetFocusTo(scr, NULL);
1369 wapp->flags.hidden = 1;
1371 if(wPreferences.auto_arrange_icons) {
1372 wArrangeIcons(scr, True);
1374 #ifdef HIDDENDOT
1375 if (wapp->app_icon)
1376 wAppIconPaint(wapp->app_icon);
1377 #endif
1383 static void
1384 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1385 int bringToCurrentWS)
1387 if (bringToCurrentWS)
1388 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1390 wwin->flags.hidden=0;
1391 wwin->flags.mapped=1;
1393 #ifdef WSOUND
1394 wSoundPlay(WSOUND_UNHIDE);
1395 #endif
1396 #ifdef ANIMATIONS
1397 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1398 && animate) {
1399 animateResize(wwin->screen_ptr, icon_x, icon_y,
1400 icon->core->width, icon->core->height,
1401 wwin->frame_x, wwin->frame_y,
1402 wwin->frame->core->width, wwin->frame->core->height,
1403 True);
1405 #endif
1406 wwin->flags.skip_next_animation = 0;
1407 XMapWindow(dpy, wwin->client_win);
1408 XMapWindow(dpy, wwin->frame->core->window);
1409 wClientSetState(wwin, NormalState, None);
1410 wRaiseFrame(wwin->frame->core);
1411 if (wwin->flags.inspector_open) {
1412 wUnhideInspectorForWindow(wwin);
1415 #ifdef GNOME_STUFF
1416 wGNOMEUpdateClientStateHint(wwin, False);
1417 #endif
1419 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1424 void
1425 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1427 WScreen *scr;
1428 WWindow *wlist, *next;
1429 WWindow *focused=NULL;
1431 if (!wapp) {
1432 return;
1434 scr = wapp->main_window_desc->screen_ptr;
1435 wlist = scr->focused_window;
1436 if (!wlist) return;
1437 /* goto beginning of list */
1438 while (wlist->prev)
1439 wlist = wlist->prev;
1441 while (wlist) {
1442 next = wlist->next;
1444 if (wlist->main_window == wapp->main_window) {
1445 if (wlist->flags.focused)
1446 focused = wlist;
1447 else if (!focused || !focused->flags.focused)
1448 focused = wlist;
1450 if (wlist->flags.miniaturized && wlist->icon) {
1451 if (bringToCurrentWS || wPreferences.sticky_icons
1452 || wlist->frame->workspace == scr->current_workspace) {
1453 if (!wlist->icon->mapped) {
1454 XMapWindow(dpy, wlist->icon->core->window);
1455 wlist->icon->mapped = 1;
1457 wlist->flags.hidden = 0;
1459 UpdateSwitchMenu(scr, wlist, ACTION_CHANGE_STATE);
1461 if (wlist->frame->workspace != scr->current_workspace)
1462 wWindowChangeWorkspace(wlist, scr->current_workspace);
1464 if (miniwindows) {
1465 wDeiconifyWindow(wlist);
1467 } else if (wlist->flags.hidden) {
1468 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1469 wapp->app_icon->y_pos, wlist,
1470 !wapp->flags.skip_next_animation,
1471 bringToCurrentWS);
1472 } else {
1473 if (bringToCurrentWS
1474 && wlist->frame->workspace != scr->current_workspace) {
1475 wWindowChangeWorkspace(wlist, scr->current_workspace);
1477 wRaiseFrame(wlist->frame->core);
1480 wlist = next;
1483 wapp->flags.skip_next_animation = 0;
1484 wapp->flags.hidden = 0;
1486 if (focused)
1487 wSetFocusTo(scr, focused);
1488 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1489 wSetFocusTo(scr, wapp->last_focused);
1490 wapp->last_focused = NULL;
1491 if (wPreferences.auto_arrange_icons) {
1492 wArrangeIcons(scr, True);
1494 #ifdef HIDDENDOT
1495 wAppIconPaint(wapp->app_icon);
1496 #endif
1501 void
1502 wShowAllWindows(WScreen *scr)
1504 WWindow *wwin, *old_foc;
1505 WApplication *wapp;
1507 old_foc = wwin = scr->focused_window;
1508 while (wwin) {
1509 if (!wwin->flags.internal_window &&
1510 (scr->current_workspace == wwin->frame->workspace
1511 || IS_OMNIPRESENT(wwin))) {
1512 if (wwin->flags.miniaturized) {
1513 wwin->flags.skip_next_animation = 1;
1514 wDeiconifyWindow(wwin);
1515 } else if (wwin->flags.hidden) {
1516 wapp = wApplicationOf(wwin->main_window);
1517 if (wapp) {
1518 wUnhideApplication(wapp, False, False);
1519 } else {
1520 wwin->flags.skip_next_animation = 1;
1521 wDeiconifyWindow(wwin);
1525 wwin = wwin->prev;
1527 wSetFocusTo(scr, old_foc);
1528 /*wRaiseFrame(old_foc->frame->core);*/
1532 void
1533 wRefreshDesktop(WScreen *scr)
1535 Window win;
1536 XSetWindowAttributes attr;
1538 attr.backing_store = NotUseful;
1539 attr.save_under = False;
1540 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1541 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1542 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1543 &attr);
1544 XMapRaised(dpy, win);
1545 XDestroyWindow(dpy, win);
1546 XFlush(dpy);
1550 void
1551 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1553 WWindow *wwin;
1554 WAppIcon *aicon;
1555 int pf; /* primary axis */
1556 int sf; /* secondary axis */
1557 int fullW;
1558 int fullH;
1559 int pi, si;
1560 int sx1, sx2, sy1, sy2; /* screen boundary */
1561 int sw, sh;
1562 int xo, yo;
1563 int xs, ys;
1564 int isize = wPreferences.icon_size;
1567 * Find out screen boundaries.
1569 sx1 = 0;
1570 sy1 = 0;
1571 sx2 = scr->scr_width;
1572 sy2 = scr->scr_height;
1573 if (scr->dock) {
1574 if (scr->dock->on_right_side)
1575 sx2 -= isize + DOCK_EXTRA_SPACE;
1576 else
1577 sx1 += isize + DOCK_EXTRA_SPACE;
1580 sw = isize * (scr->scr_width/isize);
1581 sh = isize * (scr->scr_height/isize);
1582 fullW = (sx2-sx1)/isize;
1583 fullH = (sy2-sy1)/isize;
1585 /* icon yard boundaries */
1586 if (wPreferences.icon_yard & IY_VERT) {
1587 pf = fullH;
1588 sf = fullW;
1589 } else {
1590 pf = fullW;
1591 sf = fullH;
1593 if (wPreferences.icon_yard & IY_RIGHT) {
1594 xo = sx2 - isize;
1595 xs = -1;
1596 } else {
1597 xo = sx1;
1598 xs = 1;
1600 if (wPreferences.icon_yard & IY_TOP) {
1601 yo = sy1;
1602 ys = 1;
1603 } else {
1604 yo = sy2 - isize;
1605 ys = -1;
1608 /* arrange icons putting the most recently focused window
1609 * as the last icon */
1610 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1611 : xo + xs*(pi*isize))
1612 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1613 : yo + ys*(si*isize))
1615 /* arrange application icons */
1616 aicon = scr->app_icon_list;
1617 /* reverse them to avoid unnecessarily sliding of icons */
1618 while (aicon && aicon->next)
1619 aicon = aicon->next;
1621 pi = 0;
1622 si = 0;
1623 while (aicon) {
1624 if (!aicon->docked && wAppIconIsFirstInstance(aicon)) {
1625 if (aicon->x_pos != X || aicon->y_pos != Y) {
1626 #ifdef ANIMATIONS
1627 if (!wPreferences.no_animations) {
1628 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1629 X, Y);
1631 #endif /* ANIMATIONS */
1633 wAppIconMove(aicon, X, Y);
1634 pi++;
1636 /* we reversed the order so we use prev */
1637 aicon = aicon->prev;
1638 if (pi >= pf) {
1639 pi=0;
1640 si++;
1644 /* arrange miniwindows */
1646 wwin = scr->focused_window;
1647 /* reverse them to avoid unnecessarily shuffling */
1648 while (wwin && wwin->prev)
1649 wwin = wwin->prev;
1651 while (wwin) {
1652 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1653 (wwin->frame->workspace==scr->current_workspace ||
1654 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1656 if (arrangeAll || !wwin->flags.icon_moved) {
1657 if (wwin->icon_x != X || wwin->icon_y != Y) {
1658 #ifdef ANIMATIONS
1659 if (wPreferences.no_animations) {
1660 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1661 } else {
1662 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1663 wwin->icon_y, X, Y);
1665 #else
1666 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1667 #endif /* ANIMATIONS */
1669 wwin->icon_x = X;
1670 wwin->icon_y = Y;
1671 pi++;
1674 if (arrangeAll) {
1675 wwin->flags.icon_moved = 0;
1677 /* we reversed the order, so we use next */
1678 wwin = wwin->next;
1679 if (pi >= pf) {
1680 pi=0;
1681 si++;
1687 void
1688 wSelectWindow(WWindow *wwin, Bool flag)
1690 WScreen *scr = wwin->screen_ptr;
1692 if (flag) {
1693 wwin->flags.selected = 1;
1694 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1696 if (WFLAGP(wwin, no_border)) {
1697 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1698 FRAME_BORDER_WIDTH);
1701 if (!scr->selected_windows)
1702 scr->selected_windows = WMCreateBag(4);
1703 WMPutInBag(scr->selected_windows, wwin);
1704 } else {
1705 wwin->flags.selected = 0;
1706 XSetWindowBorder(dpy, wwin->frame->core->window,
1707 scr->frame_border_pixel);
1709 if (WFLAGP(wwin, no_border)) {
1710 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1713 if (scr->selected_windows) {
1714 WMRemoveFromBag(scr->selected_windows, wwin);
1720 void
1721 wMakeWindowVisible(WWindow *wwin)
1723 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1724 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1726 if (wwin->flags.shaded) {
1727 wUnshadeWindow(wwin);
1729 if (wwin->flags.hidden) {
1730 WApplication *app;
1732 app = wApplicationOf(wwin->main_window);
1733 if (app)
1734 wUnhideApplication(app, False, False);
1735 } else if (wwin->flags.miniaturized) {
1736 wDeiconifyWindow(wwin);
1737 } else {
1738 if (!WFLAGP(wwin, no_focusable))
1739 wSetFocusTo(wwin->screen_ptr, wwin);
1740 wRaiseFrame(wwin->frame->core);