- Fixed sloppy focus bug
[wmaker-crm.git] / src / actions.c
bloba7c208e750026e8437b921c1b18143d9605b794b
1 /* action.c- misc. window commands (miniaturize, hide etc.)
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 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"
50 #include "wsound.h"
51 #include "xinerama.h"
53 #ifdef GNOME_STUFF
54 # include "gnome.h"
55 #endif
56 #ifdef KWM_HINTS
57 # include "kwm.h"
58 #endif
62 /****** Global Variables ******/
63 extern Time LastTimestamp;
64 extern Time LastFocusChange;
66 extern Cursor wCursor[WCUR_LAST];
68 extern WPreferences wPreferences;
70 extern Atom _XA_WM_TAKE_FOCUS;
73 /******* Local Variables *******/
74 static struct {
75 int steps;
76 int delay;
77 } shadePars[5] = {
78 {SHADE_STEPS_UF, SHADE_DELAY_UF},
79 {SHADE_STEPS_F, SHADE_DELAY_F},
80 {SHADE_STEPS_M, SHADE_DELAY_M},
81 {SHADE_STEPS_S, SHADE_DELAY_S},
82 {SHADE_STEPS_US, SHADE_DELAY_US}};
84 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
85 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
88 static int ignoreTimestamp=0;
91 #ifdef ANIMATIONS
92 static void
93 processEvents(int event_count)
95 XEvent event;
98 * This is a hack. When animations are enabled, processing of
99 * events ocurred during a animation are delayed until it's end.
100 * Calls that consider the TimeStamp, like XSetInputFocus(), will
101 * fail because the TimeStamp is too old. Then, for example, if
102 * the user changes window focus while a miniaturize animation is
103 * in course, the window will not get focus properly after the end
104 * of the animation. This tries to workaround it by passing CurrentTime
105 * as the TimeStamp for XSetInputFocus() for all events ocurred during
106 * the animation.
108 ignoreTimestamp=1;
109 while (XPending(dpy) && event_count--) {
110 WMNextEvent(dpy, &event);
111 WMHandleEvent(&event);
113 ignoreTimestamp=0;
115 #endif /* ANIMATIONS */
120 *----------------------------------------------------------------------
121 * wSetFocusTo--
122 * Changes the window focus to the one passed as argument.
123 * If the window to focus is not already focused, it will be brought
124 * to the head of the list of windows. Previously focused window is
125 * unfocused.
127 * Side effects:
128 * Window list may be reordered and the window focus is changed.
130 *----------------------------------------------------------------------
132 void
133 wSetFocusTo(WScreen *scr, WWindow *wwin)
135 static WScreen *old_scr=NULL;
137 WWindow *old_focused;
138 WWindow *focused=scr->focused_window;
139 int timestamp=LastTimestamp;
140 WApplication *oapp=NULL, *napp=NULL;
141 int wasfocused;
143 if (!old_scr)
144 old_scr=scr;
145 old_focused=old_scr->focused_window;
147 LastFocusChange = timestamp;
150 * This is a hack, because XSetInputFocus() should have a proper
151 * timestamp instead of CurrentTime but it seems that some times
152 * clients will not receive focus properly that way.
153 if (ignoreTimestamp)
155 timestamp = CurrentTime;
157 if (old_focused)
158 oapp = wApplicationOf(old_focused->main_window);
160 if (wwin == NULL) {
161 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
162 if (old_focused) {
163 wWindowUnfocus(old_focused);
165 if (oapp) {
166 wAppMenuUnmap(oapp->menu);
167 #ifdef NEWAPPICON
168 wApplicationDeactivate(oapp);
169 #endif
172 WMPostNotificationName(WMNChangedFocus, NULL, (void*)True);
173 return;
174 } else if (old_scr != scr && old_focused) {
175 wWindowUnfocus(old_focused);
178 wasfocused = wwin->flags.focused;
179 napp = wApplicationOf(wwin->main_window);
181 /* remember last workspace where the app has been */
182 if (napp) {
183 /*napp->last_workspace = wwin->screen_ptr->current_workspace;*/
184 napp->last_workspace = wwin->frame->workspace;
187 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
188 /* install colormap if colormap mode is lock mode */
189 if (wPreferences.colormap_mode==WCM_CLICK)
190 wColormapInstallForWindow(scr, wwin);
192 /* set input focus */
193 switch (wwin->focus_mode) {
194 case WFM_NO_INPUT:
195 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
196 break;
198 case WFM_PASSIVE:
199 case WFM_LOCALLY_ACTIVE:
200 XSetInputFocus(dpy, wwin->client_win, RevertToParent, timestamp);
201 break;
203 case WFM_GLOBALLY_ACTIVE:
204 break;
206 XFlush(dpy);
207 if (wwin->protocols.TAKE_FOCUS) {
208 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
210 XSync(dpy, False);
211 } else {
212 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
214 if (WFLAGP(wwin, no_focusable))
215 return;
217 /* if this is not the focused window focus it */
218 if (focused!=wwin) {
219 /* change the focus window list order */
220 if (wwin->prev)
221 wwin->prev->next = wwin->next;
223 if (wwin->next)
224 wwin->next->prev = wwin->prev;
226 wwin->prev = focused;
227 focused->next = wwin;
228 wwin->next = NULL;
229 scr->focused_window = wwin;
231 if (oapp && oapp != napp) {
232 wAppMenuUnmap(oapp->menu);
233 #ifdef NEWAPPICON
234 wApplicationDeactivate(oapp);
235 #endif
239 wWindowFocus(wwin, focused);
241 if (napp && !wasfocused) {
242 #ifdef USER_MENU
243 wUserMenuRefreshInstances(napp->menu, wwin);
244 #endif /* USER_MENU */
246 if (wwin->flags.mapped)
247 wAppMenuMap(napp->menu, wwin);
248 #ifdef NEWAPPICON
249 wApplicationActivate(napp);
250 #endif
253 XFlush(dpy);
254 old_scr=scr;
258 void
259 wShadeWindow(WWindow *wwin)
261 time_t time0;
262 #ifdef ANIMATIONS
263 int y, s, w, h;
264 #endif
266 if (wwin->flags.shaded)
267 return;
269 time0 = time(NULL);
271 XLowerWindow(dpy, wwin->client_win);
273 wSoundPlay(WSOUND_SHADE);
275 #ifdef ANIMATIONS
276 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
277 && !wPreferences.no_animations) {
278 /* do the shading animation */
279 h = wwin->frame->core->height;
280 s = h/SHADE_STEPS;
281 if (s < 1) s=1;
282 w = wwin->frame->core->width;
283 y = wwin->frame->top_width;
284 while (h>wwin->frame->top_width+1) {
285 XMoveWindow(dpy, wwin->client_win, 0, y);
286 XResizeWindow(dpy, wwin->frame->core->window, w, h);
287 XFlush(dpy);
289 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
290 break;
292 if (SHADE_DELAY > 0) {
293 wusleep(SHADE_DELAY*1000L);
294 } else {
295 wusleep(10);
297 h-=s;
298 y-=s;
300 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
302 #endif /* ANIMATIONS */
304 wwin->flags.skip_next_animation = 0;
305 wwin->flags.shaded = 1;
306 wwin->flags.mapped = 0;
307 /* prevent window withdrawal when getting UnmapNotify */
308 XSelectInput(dpy, wwin->client_win,
309 wwin->event_mask & ~StructureNotifyMask);
310 XUnmapWindow(dpy, wwin->client_win);
311 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
313 /* for the client it's just like iconification */
314 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
315 wwin->frame->top_width - 1);
317 wwin->client.y = wwin->frame_y - wwin->client.height
318 + wwin->frame->top_width;
319 wWindowSynthConfigureNotify(wwin);
322 wClientSetState(wwin, IconicState, None);
325 WMPostNotificationName(WMNChangedState, wwin, "shade");
327 #ifdef ANIMATIONS
328 if (!wwin->screen_ptr->flags.startup) {
329 /* Look at processEvents() for reason of this code. */
330 XSync(dpy, 0);
331 processEvents(XPending(dpy));
333 #endif
337 void
338 wUnshadeWindow(WWindow *wwin)
340 time_t time0;
341 #ifdef ANIMATIONS
342 int y, s, w, h;
343 #endif /* ANIMATIONS */
346 if (!wwin->flags.shaded)
347 return;
349 time0 = time(NULL);
351 wwin->flags.shaded = 0;
352 wwin->flags.mapped = 1;
353 XMapWindow(dpy, wwin->client_win);
355 wSoundPlay(WSOUND_UNSHADE);
357 #ifdef ANIMATIONS
358 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
359 /* do the shading animation */
360 h = wwin->frame->top_width + wwin->frame->bottom_width;
361 y = wwin->frame->top_width - wwin->client.height;
362 s = abs(y)/SHADE_STEPS;
363 if (s<1) s=1;
364 w = wwin->frame->core->width;
365 XMoveWindow(dpy, wwin->client_win, 0, y);
366 if (s>0) {
367 while (h < wwin->client.height + wwin->frame->top_width
368 + wwin->frame->bottom_width) {
369 XResizeWindow(dpy, wwin->frame->core->window, w, h);
370 XMoveWindow(dpy, wwin->client_win, 0, y);
371 XFlush(dpy);
372 if (SHADE_DELAY > 0) {
373 wusleep(SHADE_DELAY*2000L/3);
374 } else {
375 wusleep(10);
377 h+=s;
378 y+=s;
380 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
381 break;
384 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
386 #endif /* ANIMATIONS */
388 wwin->flags.skip_next_animation = 0;
389 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
390 wwin->frame->top_width + wwin->client.height
391 + wwin->frame->bottom_width);
393 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
394 wWindowSynthConfigureNotify(wwin);
397 wClientSetState(wwin, NormalState, None);
399 /* if the window is focused, set the focus again as it was disabled during
400 * shading */
401 if (wwin->flags.focused)
402 wSetFocusTo(wwin->screen_ptr, wwin);
404 WMPostNotificationName(WMNChangedState, wwin, "shade");
408 void
409 wMaximizeWindow(WWindow *wwin, int directions)
411 int new_width, new_height, new_x, new_y;
412 WArea usableArea, totalArea;
414 if (WFLAGP(wwin, no_resizable))
415 return;
417 usableArea = totalArea = (WArea){
418 0, 0,
419 wwin->screen_ptr->scr_width,
420 wwin->screen_ptr->scr_height
423 if (!(directions & MAX_IGNORE_XINERAMA)) {
424 WScreen *scr = wwin->screen_ptr;
425 int head;
427 if (directions & MAX_KEYBOARD)
428 head = wGetHeadForWindow(wwin);
429 else
430 head = wGetHeadForPointerLocation(scr);
432 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
435 if (WFLAGP(wwin, full_maximize)) {
436 usableArea = totalArea;
439 if (wwin->flags.shaded) {
440 wwin->flags.skip_next_animation = 1;
441 wUnshadeWindow(wwin);
443 wwin->flags.maximized = directions;
444 wwin->old_geometry.width = wwin->client.width;
445 wwin->old_geometry.height = wwin->client.height;
446 wwin->old_geometry.x = wwin->frame_x;
447 wwin->old_geometry.y = wwin->frame_y;
449 #ifdef KWM_HINTS
450 wKWMUpdateClientGeometryRestore(wwin);
451 #endif
453 if (directions & MAX_HORIZONTAL) {
454 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
455 new_x = usableArea.x1;
456 } else {
457 new_x = wwin->frame_x;
458 new_width = wwin->frame->core->width;
461 if (directions & MAX_VERTICAL) {
462 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
463 new_y = usableArea.y1;
464 if (WFLAGP(wwin, full_maximize)) {
465 new_y -= wwin->frame->top_width;
466 new_height += wwin->frame->bottom_width - 1;
468 } else {
469 new_y = wwin->frame_y;
470 new_height = wwin->frame->core->height;
473 if (!WFLAGP(wwin, full_maximize)) {
474 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
477 wWindowConstrainSize(wwin, &new_width, &new_height);
479 wWindowCropSize(wwin, usableArea.x2-usableArea.x1,
480 usableArea.y2-usableArea.y1,
481 &new_width, &new_height);
483 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
486 WMPostNotificationName(WMNChangedState, wwin, "maximize");
488 wSoundPlay(WSOUND_MAXIMIZE);
492 void
493 wUnmaximizeWindow(WWindow *wwin)
495 int restore_x, restore_y;
497 if (!wwin->flags.maximized)
498 return;
500 if (wwin->flags.shaded) {
501 wwin->flags.skip_next_animation = 1;
502 wUnshadeWindow(wwin);
504 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
505 wwin->old_geometry.x : wwin->frame_x;
506 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
507 wwin->old_geometry.y : wwin->frame_y;
508 wwin->flags.maximized = 0;
509 wWindowConfigure(wwin, restore_x, restore_y,
510 wwin->old_geometry.width, wwin->old_geometry.height);
512 WMPostNotificationName(WMNChangedState, wwin, "maximize");
514 wSoundPlay(WSOUND_UNMAXIMIZE);
517 #ifdef ANIMATIONS
518 static void
519 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
520 int fx, int fy, int fw, int fh, int steps)
522 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
523 float cx, cy, cw, ch;
524 float xstep, ystep, wstep, hstep;
525 XPoint points[5];
526 float dx, dch, midy;
527 float angle, final_angle, delta;
529 xstep = (float)(fx-x)/steps;
530 ystep = (float)(fy-y)/steps;
531 wstep = (float)(fw-w)/steps;
532 hstep = (float)(fh-h)/steps;
534 cx = (float)x;
535 cy = (float)y;
536 cw = (float)w;
537 ch = (float)h;
539 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
540 delta = (float)(final_angle/FRAMES);
541 for (angle=0;; angle+=delta) {
542 if (angle > final_angle)
543 angle = final_angle;
545 dx = (cw/10) - ((cw/5) * sin(angle));
546 dch = (ch/2) * cos(angle);
547 midy = cy + (ch/2);
549 points[0].x = cx + dx; points[0].y = midy - dch;
550 points[1].x = cx + cw - dx; points[1].y = points[0].y;
551 points[2].x = cx + cw + dx; points[2].y = midy + dch;
552 points[3].x = cx - dx; points[3].y = points[2].y;
553 points[4].x = points[0].x; points[4].y = points[0].y;
555 XGrabServer(dpy);
556 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
557 XFlush(dpy);
558 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
559 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
560 #else
561 wusleep(10);
562 #endif
564 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
565 XUngrabServer(dpy);
566 cx+=xstep;
567 cy+=ystep;
568 cw+=wstep;
569 ch+=hstep;
570 if (angle >= final_angle)
571 break;
574 XFlush(dpy);
576 #undef FRAMES
579 static void
580 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
581 int fx, int fy, int fw, int fh, int steps)
583 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
584 float cx, cy, cw, ch;
585 float xstep, ystep, wstep, hstep;
586 XPoint points[5];
587 float angle, final_angle, a, d, delta;
589 x += w/2;
590 y += h/2;
591 fx += fw/2;
592 fy += fh/2;
594 xstep = (float)(fx-x)/steps;
595 ystep = (float)(fy-y)/steps;
596 wstep = (float)(fw-w)/steps;
597 hstep = (float)(fh-h)/steps;
599 cx = (float)x;
600 cy = (float)y;
601 cw = (float)w;
602 ch = (float)h;
604 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
605 delta = (float)(final_angle/FRAMES);
606 for (angle=0;; angle+=delta) {
607 if (angle > final_angle)
608 angle = final_angle;
610 a = atan(ch/cw);
611 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
613 points[0].x = cx+cos(angle-a)*d;
614 points[0].y = cy+sin(angle-a)*d;
615 points[1].x = cx+cos(angle+a)*d;
616 points[1].y = cy+sin(angle+a)*d;
617 points[2].x = cx+cos(angle-a+WM_PI)*d;
618 points[2].y = cy+sin(angle-a+WM_PI)*d;
619 points[3].x = cx+cos(angle+a+WM_PI)*d;
620 points[3].y = cy+sin(angle+a+WM_PI)*d;
621 points[4].x = cx+cos(angle-a)*d;
622 points[4].y = cy+sin(angle-a)*d;
623 XGrabServer(dpy);
624 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
625 XFlush(dpy);
626 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
627 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
628 #else
629 wusleep(10);
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 #else
677 wusleep(10);
678 #endif
679 for (j=0; j<FRAMES; j++) {
680 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
681 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
682 if (j<FRAMES-1) {
683 cx[j]=cx[j+1];
684 cy[j]=cy[j+1];
685 cw[j]=cw[j+1];
686 ch[j]=ch[j+1];
687 } else {
688 cx[j]+=xstep;
689 cy[j]+=ystep;
690 cw[j]+=wstep;
691 ch[j]+=hstep;
696 for (j=0; j<FRAMES; j++) {
697 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
698 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
700 XFlush(dpy);
701 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
702 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
703 #else
704 wusleep(10);
705 #endif
706 for (j=0; j<FRAMES; j++) {
707 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
708 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
711 XUngrabServer(dpy);
713 #undef FRAMES
716 void
717 animateResize(WScreen *scr, int x, int y, int w, int h,
718 int fx, int fy, int fw, int fh, int hiding)
720 int style = wPreferences.iconification_style; /* Catch the value */
721 int steps, k;
723 if (style == WIS_NONE)
724 return;
726 if (style == WIS_RANDOM) {
727 style = rand()%3;
730 k = (hiding ? 2 : 3);
731 switch(style) {
732 case WIS_TWIST:
733 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
734 if (steps>0)
735 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
736 break;
737 case WIS_FLIP:
738 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
739 if (steps>0)
740 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
741 break;
742 case WIS_ZOOM:
743 default:
744 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
745 if (steps>0)
746 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
747 break;
750 #endif /* ANIMATIONS */
753 static void
754 flushExpose()
756 XEvent tmpev;
758 while (XCheckTypedEvent(dpy, Expose, &tmpev))
759 WMHandleEvent(&tmpev);
760 XSync(dpy, 0);
763 static void
764 unmapTransientsFor(WWindow *wwin)
766 WWindow *tmp;
769 tmp = wwin->screen_ptr->focused_window;
770 while (tmp) {
771 /* unmap the transients for this transient */
772 if (tmp!=wwin && tmp->transient_for == wwin->client_win
773 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
774 || tmp->flags.shaded)) {
775 unmapTransientsFor(tmp);
776 tmp->flags.miniaturized = 1;
777 if (!tmp->flags.shaded) {
778 wWindowUnmap(tmp);
779 } else {
780 XUnmapWindow(dpy, tmp->frame->core->window);
783 if (!tmp->flags.shaded)
785 wClientSetState(tmp, IconicState, None);
787 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
789 tmp = tmp->prev;
794 static void
795 mapTransientsFor(WWindow *wwin)
797 WWindow *tmp;
799 tmp = wwin->screen_ptr->focused_window;
800 while (tmp) {
801 /* recursively map the transients for this transient */
802 if (tmp!=wwin && tmp->transient_for == wwin->client_win
803 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
804 && tmp->icon==NULL) {
805 mapTransientsFor(tmp);
806 tmp->flags.miniaturized = 0;
807 if (!tmp->flags.shaded) {
808 wWindowMap(tmp);
809 } else {
810 XMapWindow(dpy, tmp->frame->core->window);
812 tmp->flags.semi_focused = 0;
814 if (!tmp->flags.shaded)
816 wClientSetState(tmp, NormalState, None);
818 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
820 tmp = tmp->prev;
824 #if 0
825 static void
826 setupIconGrabs(WIcon *icon)
828 /* setup passive grabs on the icon */
829 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
830 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
831 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
832 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
833 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
834 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
835 XSync(dpy, 0);
837 #endif
839 static WWindow*
840 recursiveTransientFor(WWindow *wwin)
842 int i;
844 if (!wwin)
845 return None;
847 /* hackish way to detect transient_for cycle */
848 i = wwin->screen_ptr->window_count+1;
850 while (wwin && wwin->transient_for != None && i>0) {
851 wwin = wWindowFor(wwin->transient_for);
852 i--;
854 if (i==0 && wwin) {
855 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
856 wwin->frame->title);
857 return NULL;
860 return wwin;
863 #if 0
864 static void
865 removeIconGrabs(WIcon *icon)
867 /* remove passive grabs on the icon */
868 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
869 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
870 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
871 XSync(dpy, 0);
873 #endif
876 void
877 wIconifyWindow(WWindow *wwin)
879 XWindowAttributes attribs;
880 int present;
883 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
884 /* the window doesn't exist anymore */
885 return;
888 if (wwin->flags.miniaturized) {
889 return;
892 if (wwin->transient_for!=None &&
893 wwin->transient_for!=wwin->screen_ptr->root_win) {
894 WWindow *owner = wWindowFor(wwin->transient_for);
896 if (owner && owner->flags.miniaturized)
897 return;
900 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
902 /* if the window is in another workspace, simplify process */
903 if (present) {
904 /* icon creation may take a while */
905 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
906 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
907 GrabModeAsync, None, None, CurrentTime);
910 if (!wPreferences.disable_miniwindows) {
911 if (!wwin->flags.icon_moved) {
912 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
914 wwin->icon = wIconCreate(wwin);
916 wwin->icon->mapped = 1;
919 wwin->flags.miniaturized = 1;
920 wwin->flags.mapped = 0;
922 /* unmap transients */
924 unmapTransientsFor(wwin);
926 if (present) {
927 wSoundPlay(WSOUND_ICONIFY);
929 XUngrabPointer(dpy, CurrentTime);
930 wWindowUnmap(wwin);
931 /* let all Expose events arrive so that we can repaint
932 * something before the animation starts (and the server is grabbed) */
933 XSync(dpy, 0);
935 if (wPreferences.disable_miniwindows)
936 wClientSetState(wwin, IconicState, None);
937 else
938 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
940 flushExpose();
941 #ifdef ANIMATIONS
942 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
943 && !wPreferences.no_animations) {
944 int ix, iy, iw, ih;
946 if (!wPreferences.disable_miniwindows) {
947 ix = wwin->icon_x;
948 iy = wwin->icon_y;
949 iw = wwin->icon->core->width;
950 ih = wwin->icon->core->height;
951 } else {
952 #ifdef KWM_HINTS
953 WArea area;
955 if (wKWMGetIconGeometry(wwin, &area)) {
956 ix = area.x1;
957 iy = area.y1;
958 iw = area.x2 - ix;
959 ih = area.y2 - iy;
960 } else
961 #endif /* KWM_HINTS */
963 ix = 0;
964 iy = 0;
965 iw = wwin->screen_ptr->scr_width;
966 ih = wwin->screen_ptr->scr_height;
969 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
970 wwin->frame->core->width, wwin->frame->core->height,
971 ix, iy, iw, ih, False);
973 #endif
976 wwin->flags.skip_next_animation = 0;
978 if (!wPreferences.disable_miniwindows) {
980 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
981 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
983 XMapWindow(dpy, wwin->icon->core->window);
985 AddToStackList(wwin->icon->core);
987 wLowerFrame(wwin->icon->core);
990 if (present) {
991 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
994 * It doesn't seem to be working and causes button event hangup
995 * when deiconifying a transient window.
996 setupIconGrabs(wwin->icon);
998 if ((wwin->flags.focused
999 || (owner && wwin->client_win == owner->client_win))
1000 && wPreferences.focus_mode==WKF_CLICK) {
1001 WWindow *tmp;
1003 tmp = wwin->prev;
1004 while (tmp) {
1005 if (!WFLAGP(tmp, no_focusable)
1006 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1007 && (wwin->frame->workspace == tmp->frame->workspace))
1008 break;
1009 tmp = tmp->prev;
1011 wSetFocusTo(wwin->screen_ptr, tmp);
1012 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1013 wSetFocusTo(wwin->screen_ptr, NULL);
1016 #ifdef ANIMATIONS
1017 if (!wwin->screen_ptr->flags.startup) {
1018 Window clientwin = wwin->client_win;
1020 XSync(dpy, 0);
1021 processEvents(XPending(dpy));
1023 /* the window can disappear while doing the processEvents() */
1024 if (!wWindowFor(clientwin))
1025 return;
1027 #endif
1031 if (wwin->flags.selected && !wPreferences.disable_miniwindows)
1032 wIconSelect(wwin->icon);
1034 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1040 void
1041 wDeiconifyWindow(WWindow *wwin)
1043 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1045 if (!wwin->flags.miniaturized)
1046 return;
1048 if (wwin->transient_for != None
1049 && wwin->transient_for != wwin->screen_ptr->root_win) {
1050 WWindow *owner = recursiveTransientFor(wwin);
1052 if (owner && owner->flags.miniaturized) {
1053 wDeiconifyWindow(owner);
1054 wSetFocusTo(wwin->screen_ptr, wwin);
1055 wRaiseFrame(wwin->frame->core);
1056 return;
1060 wwin->flags.miniaturized = 0;
1061 if (!wwin->flags.shaded)
1062 wwin->flags.mapped = 1;
1064 if (!wPreferences.disable_miniwindows && wwin->icon != NULL) {
1065 if (wwin->icon->selected)
1066 wIconSelect(wwin->icon);
1068 XUnmapWindow(dpy, wwin->icon->core->window);
1071 wSoundPlay(WSOUND_DEICONIFY);
1073 /* if the window is in another workspace, do it silently */
1074 #ifdef ANIMATIONS
1075 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1076 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1077 int ix, iy, iw, ih;
1079 if (!wPreferences.disable_miniwindows) {
1080 ix = wwin->icon_x;
1081 iy = wwin->icon_y;
1082 iw = wwin->icon->core->width;
1083 ih = wwin->icon->core->height;
1084 } else {
1085 #ifdef KWM_HINTS
1086 WArea area;
1088 if (wKWMGetIconGeometry(wwin, &area)) {
1089 ix = area.x1;
1090 iy = area.y1;
1091 iw = area.x2 - ix;
1092 ih = area.y2 - iy;
1093 } else
1094 #endif /* KWM_HINTS */
1096 ix = 0;
1097 iy = 0;
1098 iw = wwin->screen_ptr->scr_width;
1099 ih = wwin->screen_ptr->scr_height;
1102 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1103 wwin->frame_x, wwin->frame_y,
1104 wwin->frame->core->width, wwin->frame->core->height,
1105 False);
1107 #endif /* ANIMATIONS */
1108 wwin->flags.skip_next_animation = 0;
1109 XGrabServer(dpy);
1110 if (!wwin->flags.shaded) {
1111 XMapWindow(dpy, wwin->client_win);
1113 XMapWindow(dpy, wwin->frame->core->window);
1114 wRaiseFrame(wwin->frame->core);
1115 if (!wwin->flags.shaded) {
1116 wClientSetState(wwin, NormalState, None);
1118 mapTransientsFor(wwin);
1120 if (!wPreferences.disable_miniwindows && wwin->icon != NULL) {
1121 RemoveFromStackList(wwin->icon->core);
1122 /* removeIconGrabs(wwin->icon);*/
1123 wIconDestroy(wwin->icon);
1124 wwin->icon = NULL;
1126 XUngrabServer(dpy);
1128 if (wPreferences.focus_mode==WKF_CLICK)
1129 wSetFocusTo(wwin->screen_ptr, wwin);
1131 #ifdef ANIMATIONS
1132 if (!wwin->screen_ptr->flags.startup) {
1133 Window clientwin = wwin->client_win;
1135 XSync(dpy, 0);
1136 processEvents(XPending(dpy));
1138 if (!wWindowFor(clientwin))
1139 return;
1141 #endif
1143 if (wPreferences.auto_arrange_icons) {
1144 wArrangeIcons(wwin->screen_ptr, True);
1147 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1149 /* In case we were shaded and iconified, also unshade */
1150 wUnshadeWindow(wwin);
1155 static void
1156 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1158 if (wwin->flags.miniaturized) {
1159 if (wwin->icon) {
1160 XUnmapWindow(dpy, wwin->icon->core->window);
1161 wwin->icon->mapped = 0;
1163 wwin->flags.hidden = 1;
1165 WMPostNotificationName(WMNChangedState, wwin, "hide");
1166 return;
1169 if (wwin->flags.inspector_open) {
1170 wHideInspectorForWindow(wwin);
1173 wwin->flags.hidden = 1;
1174 wWindowUnmap(wwin);
1176 wClientSetState(wwin, IconicState, icon->icon_win);
1177 flushExpose();
1178 wSoundPlay(WSOUND_HIDE);
1179 #ifdef ANIMATIONS
1180 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1181 !wwin->flags.skip_next_animation && animate) {
1182 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1183 wwin->frame->core->width, wwin->frame->core->height,
1184 icon_x, icon_y, icon->core->width, icon->core->height,
1185 True);
1187 #endif
1188 wwin->flags.skip_next_animation = 0;
1190 WMPostNotificationName(WMNChangedState, wwin, "hide");
1195 void
1196 wHideOtherApplications(WWindow *awin)
1198 WWindow *wwin;
1199 WApplication *tapp;
1201 if (!awin)
1202 return;
1203 wwin = awin->screen_ptr->focused_window;
1206 while (wwin) {
1207 if (wwin!=awin
1208 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1209 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1210 && !wwin->flags.internal_window
1211 && wGetWindowOfInspectorForWindow(wwin) != awin
1212 && !WFLAGP(wwin, no_hide_others)) {
1214 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1215 if (!WFLAGP(wwin, no_miniaturizable)) {
1216 wwin->flags.skip_next_animation = 1;
1217 wIconifyWindow(wwin);
1219 } else if (wwin->main_window!=None
1220 && awin->main_window != wwin->main_window) {
1221 tapp = wApplicationOf(wwin->main_window);
1222 if (tapp) {
1223 tapp->flags.skip_next_animation = 1;
1224 wHideApplication(tapp);
1225 } else {
1226 if (!WFLAGP(wwin, no_miniaturizable)) {
1227 wwin->flags.skip_next_animation = 1;
1228 wIconifyWindow(wwin);
1233 wwin = wwin->prev;
1236 wSetFocusTo(awin->screen_ptr, awin);
1242 void
1243 wHideApplication(WApplication *wapp)
1245 WScreen *scr;
1246 WWindow *wlist;
1247 int hadfocus;
1249 if (!wapp) {
1250 wwarning("trying to hide a non grouped window");
1251 return;
1253 if (!wapp->main_window_desc) {
1254 wwarning("group leader not found for window group");
1255 return;
1257 scr = wapp->main_window_desc->screen_ptr;
1258 hadfocus = 0;
1259 wlist = scr->focused_window;
1260 if (!wlist)
1261 return;
1263 if (wlist->main_window == wapp->main_window)
1264 wapp->last_focused = wlist;
1265 else
1266 wapp->last_focused = NULL;
1267 while (wlist) {
1268 if (wlist->main_window == wapp->main_window) {
1269 if (wlist->flags.focused) {
1270 hadfocus = 1;
1272 if (wapp->app_icon)
1273 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1274 wapp->app_icon->y_pos, wlist,
1275 !wapp->flags.skip_next_animation);
1277 wlist = wlist->prev;
1280 wapp->flags.skip_next_animation = 0;
1282 if (hadfocus) {
1283 if (wPreferences.focus_mode==WKF_CLICK) {
1284 wlist = scr->focused_window;
1285 while (wlist) {
1286 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1287 && (wlist->flags.mapped || wlist->flags.shaded))
1288 break;
1289 wlist = wlist->prev;
1291 wSetFocusTo(scr, wlist);
1292 } else {
1293 wSetFocusTo(scr, NULL);
1297 wapp->flags.hidden = 1;
1299 if(wPreferences.auto_arrange_icons) {
1300 wArrangeIcons(scr, True);
1302 #ifdef HIDDENDOT
1303 if (wapp->app_icon)
1304 wAppIconPaint(wapp->app_icon);
1305 #endif
1311 static void
1312 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1313 int bringToCurrentWS)
1315 if (bringToCurrentWS)
1316 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1318 wwin->flags.hidden=0;
1320 wSoundPlay(WSOUND_UNHIDE);
1321 #ifdef ANIMATIONS
1322 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1323 && animate) {
1324 animateResize(wwin->screen_ptr, icon_x, icon_y,
1325 icon->core->width, icon->core->height,
1326 wwin->frame_x, wwin->frame_y,
1327 wwin->frame->core->width, wwin->frame->core->height,
1328 True);
1330 #endif
1331 wwin->flags.skip_next_animation = 0;
1332 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1333 XMapWindow(dpy, wwin->client_win);
1334 XMapWindow(dpy, wwin->frame->core->window);
1335 wClientSetState(wwin, NormalState, None);
1336 wwin->flags.mapped=1;
1337 wRaiseFrame(wwin->frame->core);
1339 if (wwin->flags.inspector_open) {
1340 wUnhideInspectorForWindow(wwin);
1343 WMPostNotificationName(WMNChangedState, wwin, "hide");
1347 void
1348 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1350 WScreen *scr;
1351 WWindow *wlist, *next;
1352 WWindow *focused=NULL;
1353 Bool shouldArrangeIcons = False;
1355 if (!wapp)
1356 return;
1358 scr = wapp->main_window_desc->screen_ptr;
1359 wlist = scr->focused_window;
1360 if (!wlist)
1361 return;
1363 /* goto beginning of list */
1364 while (wlist->prev)
1365 wlist = wlist->prev;
1367 while (wlist) {
1368 next = wlist->next;
1370 if (wlist->main_window == wapp->main_window) {
1371 if (wlist->flags.focused)
1372 focused = wlist;
1373 else if (!focused || !focused->flags.focused)
1374 focused = wlist;
1376 if (wlist->flags.miniaturized) {
1377 if (bringToCurrentWS || wPreferences.sticky_icons ||
1378 wlist->frame->workspace == scr->current_workspace) {
1379 if (wlist->icon && !wlist->icon->mapped) {
1380 XMapWindow(dpy, wlist->icon->core->window);
1381 wlist->icon->mapped = 1;
1384 if (bringToCurrentWS)
1385 wWindowChangeWorkspace(wlist, scr->current_workspace);
1386 wlist->flags.hidden = 0;
1387 if (miniwindows &&
1388 wlist->frame->workspace == scr->current_workspace) {
1389 wDeiconifyWindow(wlist);
1391 shouldArrangeIcons = True;
1392 WMPostNotificationName(WMNChangedState, wlist, "hide");
1393 } else if (wlist->flags.shaded) {
1394 if (bringToCurrentWS)
1395 wWindowChangeWorkspace(wlist, scr->current_workspace);
1396 wlist->flags.hidden = 0;
1397 if (wlist->frame->workspace == scr->current_workspace) {
1398 XMapWindow(dpy, wlist->frame->core->window);
1399 if (miniwindows) {
1400 wUnshadeWindow(wlist);
1401 wRaiseFrame(wlist->frame->core);
1404 WMPostNotificationName(WMNChangedState, wlist, "hide");
1405 } else if (wlist->flags.hidden) {
1406 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1407 wapp->app_icon->y_pos, wlist,
1408 !wapp->flags.skip_next_animation,
1409 bringToCurrentWS);
1410 } else {
1411 if (bringToCurrentWS
1412 && wlist->frame->workspace != scr->current_workspace) {
1413 wWindowChangeWorkspace(wlist, scr->current_workspace);
1415 wRaiseFrame(wlist->frame->core);
1418 wlist = next;
1421 wapp->flags.skip_next_animation = 0;
1422 wapp->flags.hidden = 0;
1424 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1425 wRaiseFrame(wapp->last_focused->frame->core);
1426 wSetFocusTo(scr, wapp->last_focused);
1427 } else if (focused) {
1428 wSetFocusTo(scr, focused);
1430 wapp->last_focused = NULL;
1431 if (shouldArrangeIcons || wPreferences.auto_arrange_icons) {
1432 wArrangeIcons(scr, True);
1434 #ifdef HIDDENDOT
1435 wAppIconPaint(wapp->app_icon);
1436 #endif
1441 void
1442 wShowAllWindows(WScreen *scr)
1444 WWindow *wwin, *old_foc;
1445 WApplication *wapp;
1447 old_foc = wwin = scr->focused_window;
1448 while (wwin) {
1449 if (!wwin->flags.internal_window &&
1450 (scr->current_workspace == wwin->frame->workspace
1451 || IS_OMNIPRESENT(wwin))) {
1452 if (wwin->flags.miniaturized) {
1453 wwin->flags.skip_next_animation = 1;
1454 wDeiconifyWindow(wwin);
1455 } else if (wwin->flags.hidden) {
1456 wapp = wApplicationOf(wwin->main_window);
1457 if (wapp) {
1458 wUnhideApplication(wapp, False, False);
1459 } else {
1460 wwin->flags.skip_next_animation = 1;
1461 wDeiconifyWindow(wwin);
1465 wwin = wwin->prev;
1467 wSetFocusTo(scr, old_foc);
1468 /*wRaiseFrame(old_foc->frame->core);*/
1472 void
1473 wRefreshDesktop(WScreen *scr)
1475 Window win;
1476 XSetWindowAttributes attr;
1478 attr.backing_store = NotUseful;
1479 attr.save_under = False;
1480 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1481 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1482 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1483 &attr);
1484 XMapRaised(dpy, win);
1485 XDestroyWindow(dpy, win);
1486 XFlush(dpy);
1490 void
1491 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1493 WWindow *wwin;
1494 WAppIcon *aicon;
1496 int head;
1497 const int heads = wXineramaHeads(scr);
1499 struct {
1500 int pf; /* primary axis */
1501 int sf; /* secondary axis */
1502 int fullW;
1503 int fullH;
1504 int pi, si;
1505 int sx1, sx2, sy1, sy2; /* screen boundary */
1506 int sw, sh;
1507 int xo, yo;
1508 int xs, ys;
1509 } vars[heads];
1511 int isize = wPreferences.icon_size;
1513 for (head = 0; head < heads; ++head) {
1514 #if 0
1515 WMRect rect = wGetRectForHead(scr, head);
1516 #else
1517 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1518 WMRect rect = (WMRect){ area.x1, area.y1, area.x2-area.x1, area.y2-area.y1 };
1519 #endif
1521 vars[head].pi = vars[head].si = 0;
1522 vars[head].sx1 = rect.pos.x;
1523 vars[head].sy1 = rect.pos.y;
1524 vars[head].sw = rect.size.width;
1525 vars[head].sh = rect.size.height;
1526 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1527 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1529 #if 0
1530 if (scr->dock) {
1531 if (scr->dock->on_right_side)
1532 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1533 else
1534 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1536 #endif
1538 vars[head].sw = isize * (vars[head].sw/isize);
1539 vars[head].sh = isize * (vars[head].sh/isize);
1540 vars[head].fullW = (vars[head].sx2-vars[head].sx1)/isize;
1541 vars[head].fullH = (vars[head].sy2-vars[head].sy1)/isize;
1543 /* icon yard boundaries */
1544 if (wPreferences.icon_yard & IY_VERT) {
1545 vars[head].pf = vars[head].fullH;
1546 vars[head].sf = vars[head].fullW;
1547 } else {
1548 vars[head].pf = vars[head].fullW;
1549 vars[head].sf = vars[head].fullH;
1551 if (wPreferences.icon_yard & IY_RIGHT) {
1552 vars[head].xo = vars[head].sx2 - isize;
1553 vars[head].xs = -1;
1554 } else {
1555 vars[head].xo = vars[head].sx1;
1556 vars[head].xs = 1;
1558 if (wPreferences.icon_yard & IY_TOP) {
1559 vars[head].yo = vars[head].sy1;
1560 vars[head].ys = 1;
1561 } else {
1562 vars[head].yo = vars[head].sy2 - isize;
1563 vars[head].ys = -1;
1567 #define X ((wPreferences.icon_yard & IY_VERT) \
1568 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1569 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1571 #define Y ((wPreferences.icon_yard & IY_VERT) \
1572 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1573 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1576 /* arrange application icons */
1577 aicon = scr->app_icon_list;
1578 /* reverse them to avoid unnecessarily sliding of icons */
1579 while (aicon && aicon->next)
1580 aicon = aicon->next;
1582 while (aicon) {
1583 if (!aicon->docked) {
1584 /* XXX: can: icon == NULL ? */
1585 /* The intention here is to place the AppIcon on the head that contains most of the applications _main_ window. */
1586 /* printf( "appicon: %x %x\n", aicon->icon->core->window, aicon->main_window); */
1587 head = wGetHeadForWindow(aicon->icon->owner);
1589 if (aicon->x_pos != X || aicon->y_pos != Y) {
1590 #ifdef ANIMATIONS
1591 if (!wPreferences.no_animations) {
1592 SlideWindow(aicon->icon->core->window,
1593 aicon->x_pos, aicon->y_pos, X, Y);
1595 #endif /* ANIMATIONS */
1597 wAppIconMove(aicon, X, Y);
1598 vars[head].pi++;
1599 if (vars[head].pi >= vars[head].pf) {
1600 vars[head].pi = 0;
1601 vars[head].si++;
1604 aicon = aicon->prev;
1607 /* arrange miniwindows */
1608 wwin = scr->focused_window;
1609 /* reverse them to avoid unnecessarily shuffling */
1610 while (wwin && wwin->prev)
1611 wwin = wwin->prev;
1613 while (wwin) {
1614 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1615 (wwin->frame->workspace==scr->current_workspace ||
1616 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1618 head = wGetHeadForWindow(wwin);
1620 if (arrangeAll || !wwin->flags.icon_moved) {
1621 if (wwin->icon_x != X || wwin->icon_y != Y) {
1622 #ifdef ANIMATIONS
1623 if (wPreferences.no_animations) {
1624 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1625 } else {
1626 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1627 wwin->icon_y, X, Y);
1629 #else
1630 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1631 #endif /* ANIMATIONS */
1633 wwin->icon_x = X;
1634 wwin->icon_y = Y;
1636 vars[head].pi++;
1637 if (vars[head].pi >= vars[head].pf) {
1638 vars[head].pi = 0;
1639 vars[head].si++;
1643 if (arrangeAll) {
1644 wwin->flags.icon_moved = 0;
1646 /* we reversed the order, so we use next */
1647 wwin = wwin->next;
1651 #if 0
1652 void
1653 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1655 WWindow *wwin;
1656 WAppIcon *aicon;
1657 int pf; /* primary axis */
1658 int sf; /* secondary axis */
1659 int fullW;
1660 int fullH;
1661 int pi, si;
1662 int sx1, sx2, sy1, sy2; /* screen boundary */
1663 int sw, sh;
1664 int xo, yo;
1665 int xs, ys;
1666 int isize = wPreferences.icon_size;
1669 * Find out screen boundaries.
1673 * Allows each head to have miniwindows
1675 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1677 sx1 = rect.pos.x;
1678 sy1 = rect.pos.y;
1679 sw = rect.size.width;
1680 sh = rect.size.height;
1681 sx2 = sx1 + sw;
1682 sy2 = sy1 + sh;
1683 if (scr->dock) {
1684 if (scr->dock->on_right_side)
1685 sx2 -= isize + DOCK_EXTRA_SPACE;
1686 else
1687 sx1 += isize + DOCK_EXTRA_SPACE;
1690 #if 0
1691 sw = isize * (scr->scr_width/isize);
1692 sh = isize * (scr->scr_height/isize);
1693 #else
1694 sw = isize * (sw/isize);
1695 sh = isize * (sh/isize);
1696 #endif
1697 fullW = (sx2-sx1)/isize;
1698 fullH = (sy2-sy1)/isize;
1700 /* icon yard boundaries */
1701 if (wPreferences.icon_yard & IY_VERT) {
1702 pf = fullH;
1703 sf = fullW;
1704 } else {
1705 pf = fullW;
1706 sf = fullH;
1708 if (wPreferences.icon_yard & IY_RIGHT) {
1709 xo = sx2 - isize;
1710 xs = -1;
1711 } else {
1712 xo = sx1;
1713 xs = 1;
1715 if (wPreferences.icon_yard & IY_TOP) {
1716 yo = sy1;
1717 ys = 1;
1718 } else {
1719 yo = sy2 - isize;
1720 ys = -1;
1723 /* arrange icons putting the most recently focused window
1724 * as the last icon */
1725 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1726 : xo + xs*(pi*isize))
1727 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1728 : yo + ys*(si*isize))
1730 /* arrange application icons */
1731 aicon = scr->app_icon_list;
1732 /* reverse them to avoid unnecessarily sliding of icons */
1733 while (aicon && aicon->next)
1734 aicon = aicon->next;
1736 pi = 0;
1737 si = 0;
1738 while (aicon) {
1739 if (!aicon->docked) {
1740 if (aicon->x_pos != X || aicon->y_pos != Y) {
1741 #ifdef ANIMATIONS
1742 if (!wPreferences.no_animations) {
1743 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1744 X, Y);
1746 #endif /* ANIMATIONS */
1748 wAppIconMove(aicon, X, Y);
1749 pi++;
1751 /* we reversed the order so we use prev */
1752 aicon = aicon->prev;
1753 if (pi >= pf) {
1754 pi=0;
1755 si++;
1759 /* arrange miniwindows */
1761 wwin = scr->focused_window;
1762 /* reverse them to avoid unnecessarily shuffling */
1763 while (wwin && wwin->prev)
1764 wwin = wwin->prev;
1766 while (wwin) {
1767 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1768 (wwin->frame->workspace==scr->current_workspace ||
1769 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1771 if (arrangeAll || !wwin->flags.icon_moved) {
1772 if (wwin->icon_x != X || wwin->icon_y != Y) {
1773 #ifdef ANIMATIONS
1774 if (wPreferences.no_animations) {
1775 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1776 } else {
1777 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1778 wwin->icon_y, X, Y);
1780 #else
1781 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1782 #endif /* ANIMATIONS */
1784 wwin->icon_x = X;
1785 wwin->icon_y = Y;
1786 pi++;
1789 if (arrangeAll) {
1790 wwin->flags.icon_moved = 0;
1792 /* we reversed the order, so we use next */
1793 wwin = wwin->next;
1794 if (pi >= pf) {
1795 pi=0;
1796 si++;
1800 #endif
1802 void
1803 wSelectWindow(WWindow *wwin, Bool flag)
1805 WScreen *scr = wwin->screen_ptr;
1807 if (flag) {
1808 wwin->flags.selected = 1;
1809 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1811 if (WFLAGP(wwin, no_border)) {
1812 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1813 FRAME_BORDER_WIDTH);
1816 if (!scr->selected_windows)
1817 scr->selected_windows = WMCreateArray(4);
1818 WMAddToArray(scr->selected_windows, wwin);
1819 } else {
1820 wwin->flags.selected = 0;
1821 XSetWindowBorder(dpy, wwin->frame->core->window,
1822 scr->frame_border_pixel);
1824 if (WFLAGP(wwin, no_border)) {
1825 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1828 if (scr->selected_windows) {
1829 WMRemoveFromArray(scr->selected_windows, wwin);
1835 void
1836 wMakeWindowVisible(WWindow *wwin)
1838 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1839 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1841 if (wwin->flags.shaded) {
1842 wUnshadeWindow(wwin);
1844 if (wwin->flags.hidden) {
1845 WApplication *app;
1847 app = wApplicationOf(wwin->main_window);
1848 if (app) {
1849 /* trick to get focus to this window */
1850 app->last_focused = wwin;
1851 wUnhideApplication(app, False, False);
1854 if (wwin->flags.miniaturized) {
1855 wDeiconifyWindow(wwin);
1856 } else {
1857 if (!WFLAGP(wwin, no_focusable))
1858 wSetFocusTo(wwin->screen_ptr, wwin);
1859 wRaiseFrame(wwin->frame->core);