1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
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,
27 #include <X11/Xutil.h>
34 #include "WindowMaker.h"
41 #include "application.h"
47 #include "winspector.h"
48 #include "workspace.h"
52 /****** Global Variables ******/
53 extern Time LastTimestamp
;
54 extern Time LastFocusChange
;
56 extern Cursor wCursor
[WCUR_LAST
];
58 extern WPreferences wPreferences
;
60 extern Atom _XA_WM_TAKE_FOCUS
;
62 extern void ProcessPendingEvents();
64 /******* Local Variables *******/
70 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
71 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
72 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
73 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
74 SHADE_STEPS_US
, SHADE_DELAY_US
}};
76 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
77 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
79 static int compareTimes(Time t1
, Time t2
)
85 return (diff
< 60000) ? 1 : -1;
89 *----------------------------------------------------------------------
91 * Changes the window focus to the one passed as argument.
92 * If the window to focus is not already focused, it will be brought
93 * to the head of the list of windows. Previously focused window is
97 * Window list may be reordered and the window focus is changed.
99 *----------------------------------------------------------------------
101 void wSetFocusTo(WScreen
* scr
, WWindow
* wwin
)
103 static WScreen
*old_scr
= NULL
;
105 WWindow
*old_focused
;
106 WWindow
*focused
= scr
->focused_window
;
107 Time timestamp
= LastTimestamp
;
108 WApplication
*oapp
= NULL
, *napp
= NULL
;
111 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
116 old_focused
= old_scr
->focused_window
;
118 LastFocusChange
= timestamp
;
121 oapp
= wApplicationOf(old_focused
->main_window
);
124 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
126 wWindowUnfocus(old_focused
);
129 wAppMenuUnmap(oapp
->menu
);
131 wApplicationDeactivate(oapp
);
135 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
137 } else if (old_scr
!= scr
&& old_focused
) {
138 wWindowUnfocus(old_focused
);
141 wasfocused
= wwin
->flags
.focused
;
142 napp
= wApplicationOf(wwin
->main_window
);
144 /* remember last workspace where the app has been */
146 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
147 napp
->last_workspace
= wwin
->frame
->workspace
;
150 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
151 /* install colormap if colormap mode is lock mode */
152 if (wPreferences
.colormap_mode
== WCM_CLICK
)
153 wColormapInstallForWindow(scr
, wwin
);
155 /* set input focus */
156 switch (wwin
->focus_mode
) {
158 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
162 case WFM_LOCALLY_ACTIVE
:
163 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
166 case WFM_GLOBALLY_ACTIVE
:
170 if (wwin
->protocols
.TAKE_FOCUS
) {
171 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
175 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
177 if (WFLAGP(wwin
, no_focusable
))
180 /* if this is not the focused window focus it */
181 if (focused
!= wwin
) {
182 /* change the focus window list order */
184 wwin
->prev
->next
= wwin
->next
;
187 wwin
->next
->prev
= wwin
->prev
;
189 wwin
->prev
= focused
;
190 focused
->next
= wwin
;
192 scr
->focused_window
= wwin
;
194 if (oapp
&& oapp
!= napp
) {
195 wAppMenuUnmap(oapp
->menu
);
197 wApplicationDeactivate(oapp
);
202 wWindowFocus(wwin
, focused
);
204 if (napp
&& !wasfocused
) {
206 wUserMenuRefreshInstances(napp
->menu
, wwin
);
207 #endif /* USER_MENU */
209 if (wwin
->flags
.mapped
)
210 wAppMenuMap(napp
->menu
, wwin
);
212 wApplicationActivate(napp
);
220 void wShadeWindow(WWindow
* wwin
)
227 if (wwin
->flags
.shaded
)
232 XLowerWindow(dpy
, wwin
->client_win
);
234 wSoundPlay(WSOUND_SHADE
);
237 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
&& !wPreferences
.no_animations
) {
238 /* do the shading animation */
239 h
= wwin
->frame
->core
->height
;
243 w
= wwin
->frame
->core
->width
;
244 y
= wwin
->frame
->top_width
;
245 while (h
> wwin
->frame
->top_width
+ 1) {
246 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
247 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
250 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
253 if (SHADE_DELAY
> 0) {
254 wusleep(SHADE_DELAY
* 1000L);
261 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
263 #endif /* ANIMATIONS */
265 wwin
->flags
.skip_next_animation
= 0;
266 wwin
->flags
.shaded
= 1;
267 wwin
->flags
.mapped
= 0;
268 /* prevent window withdrawal when getting UnmapNotify */
269 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
270 XUnmapWindow(dpy
, wwin
->client_win
);
271 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
273 /* for the client it's just like iconification */
274 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
276 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
277 wWindowSynthConfigureNotify(wwin
);
280 wClientSetState(wwin, IconicState, None);
283 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
286 if (!wwin
->screen_ptr
->flags
.startup
) {
287 /* Catch up with events not processed while animation was running */
288 ProcessPendingEvents();
293 void wUnshadeWindow(WWindow
* wwin
)
298 #endif /* ANIMATIONS */
300 if (!wwin
->flags
.shaded
)
305 wwin
->flags
.shaded
= 0;
306 wwin
->flags
.mapped
= 1;
307 XMapWindow(dpy
, wwin
->client_win
);
309 wSoundPlay(WSOUND_UNSHADE
);
312 if (!wPreferences
.no_animations
&& !wwin
->flags
.skip_next_animation
) {
313 /* do the shading animation */
314 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
315 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
316 s
= abs(y
) / SHADE_STEPS
;
319 w
= wwin
->frame
->core
->width
;
320 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
322 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
323 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
324 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
326 if (SHADE_DELAY
> 0) {
327 wusleep(SHADE_DELAY
* 2000L / 3);
334 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
338 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
340 #endif /* ANIMATIONS */
342 wwin
->flags
.skip_next_animation
= 0;
343 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
344 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
346 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
347 wWindowSynthConfigureNotify(wwin
);
350 wClientSetState(wwin, NormalState, None);
352 /* if the window is focused, set the focus again as it was disabled during
354 if (wwin
->flags
.focused
)
355 wSetFocusTo(wwin
->screen_ptr
, wwin
);
357 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
360 void wMaximizeWindow(WWindow
* wwin
, int directions
)
363 unsigned int new_width
, new_height
;
364 int changed_h
, changed_v
, shrink_h
, shrink_v
;
365 WArea usableArea
, totalArea
;
367 if (!IS_RESIZABLE(wwin
))
372 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
373 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
374 usableArea
= totalArea
;
376 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
377 WScreen
*scr
= wwin
->screen_ptr
;
380 if (directions
& MAX_KEYBOARD
)
381 head
= wGetHeadForWindow(wwin
);
383 head
= wGetHeadForPointerLocation(scr
);
385 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
388 if (WFLAGP(wwin
, full_maximize
)) {
389 usableArea
= totalArea
;
392 if (wwin
->flags
.shaded
) {
393 wwin
->flags
.skip_next_animation
= 1;
394 wUnshadeWindow(wwin
);
396 /* Only save directions, not kbd or xinerama hints */
397 directions
&= (MAX_HORIZONTAL
|MAX_VERTICAL
|MAX_LEFTHALF
|MAX_RIGHTHALF
);
399 changed_h
= ((wwin
->flags
.maximized
^ directions
) & MAX_HORIZONTAL
);
400 changed_v
= ((wwin
->flags
.maximized
^ directions
) & MAX_VERTICAL
);
401 shrink_h
= (changed_h
&& (directions
& MAX_HORIZONTAL
) == 0);
402 shrink_v
= (changed_v
&& (directions
& MAX_VERTICAL
) == 0);
404 if (wwin
->flags
.maximized
) {
405 /* if already maximized in some direction, we only update the
406 * appropriate old x, old y coordinates. This is necessary to
407 * allow succesive maximizations in different directions without
408 * the need to first do an un-maximize (to avoid flicker).
410 if (!(wwin
->flags
.maximized
& (MAX_HORIZONTAL
|MAX_LEFTHALF
|MAX_RIGHTHALF
))) {
411 wwin
->old_geometry
.x
= wwin
->frame_x
;
413 if (!(wwin
->flags
.maximized
& MAX_VERTICAL
)) {
414 wwin
->old_geometry
.y
= wwin
->frame_y
;
417 wwin
->old_geometry
.width
= wwin
->client
.width
;
418 wwin
->old_geometry
.height
= wwin
->client
.height
;
419 wwin
->old_geometry
.x
= wwin
->frame_x
;
420 wwin
->old_geometry
.y
= wwin
->frame_y
;
422 wwin
->flags
.maximized
= directions
;
424 if (directions
& MAX_HORIZONTAL
) {
425 new_width
= usableArea
.x2
- usableArea
.x1
;
426 if (HAS_BORDER(wwin
))
427 new_width
-= FRAME_BORDER_WIDTH
* 2;
428 new_x
= usableArea
.x1
;
429 } else if (directions
& MAX_LEFTHALF
) {
430 new_width
= (usableArea
.x2
- usableArea
.x1
)/2;
431 if (HAS_BORDER(wwin
))
432 new_width
-= FRAME_BORDER_WIDTH
* 2;
433 new_x
= usableArea
.x1
;
434 } else if (directions
& MAX_RIGHTHALF
) {
435 new_width
= (usableArea
.x2
- usableArea
.x1
)/2;
436 if (HAS_BORDER(wwin
))
437 new_width
-= FRAME_BORDER_WIDTH
* 2;
438 new_x
= usableArea
.x1
+((usableArea
.x2
- usableArea
.x1
)/2);
439 } else if (shrink_h
) {
440 new_x
= wwin
->old_geometry
.x
;
441 new_width
= wwin
->old_geometry
.width
;
443 new_x
= wwin
->frame_x
;
444 new_width
= wwin
->frame
->core
->width
;
447 if (directions
& MAX_VERTICAL
) {
448 new_height
= usableArea
.y2
- usableArea
.y1
;
449 if (HAS_BORDER(wwin
))
450 new_height
-= FRAME_BORDER_WIDTH
* 2;
451 new_y
= usableArea
.y1
;
452 if (WFLAGP(wwin
, full_maximize
)) {
453 new_y
-= wwin
->frame
->top_width
;
454 new_height
+= wwin
->frame
->bottom_width
- 1;
456 } else if (shrink_v
) {
457 new_y
= wwin
->old_geometry
.y
;
458 new_height
= wwin
->old_geometry
.height
;
460 new_y
= wwin
->frame_y
;
461 new_height
= wwin
->frame
->core
->height
;
464 if (!WFLAGP(wwin
, full_maximize
)) {
465 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
468 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
470 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
471 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
473 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
475 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
477 wSoundPlay(WSOUND_MAXIMIZE
);
480 void wUnmaximizeWindow(WWindow
* wwin
)
484 if (!wwin
->flags
.maximized
)
487 if (wwin
->flags
.shaded
) {
488 wwin
->flags
.skip_next_animation
= 1;
489 wUnshadeWindow(wwin
);
491 x
= ((wwin
->flags
.maximized
& (MAX_HORIZONTAL
|MAX_LEFTHALF
|MAX_RIGHTHALF
)) && wwin
->old_geometry
.x
) ?
492 wwin
->old_geometry
.x
: wwin
->frame_x
;
493 y
= ((wwin
->flags
.maximized
& MAX_VERTICAL
) && wwin
->old_geometry
.y
) ?
494 wwin
->old_geometry
.y
: wwin
->frame_y
;
495 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
496 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
498 wwin
->flags
.maximized
= 0;
499 wWindowConfigure(wwin
, x
, y
, w
, h
);
501 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
503 wSoundPlay(WSOUND_UNMAXIMIZE
);
506 void wFullscreenWindow(WWindow
* wwin
)
511 if (wwin
->flags
.fullscreen
)
514 wwin
->flags
.fullscreen
= True
;
516 wWindowConfigureBorders(wwin
);
518 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
520 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
521 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
522 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
523 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
525 head
= wGetHeadForWindow(wwin
);
526 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
527 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
529 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
532 void wUnfullscreenWindow(WWindow
* wwin
)
534 if (!wwin
->flags
.fullscreen
)
537 wwin
->flags
.fullscreen
= False
;
539 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
540 if (WFLAGP(wwin
, sunken
)) {
541 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
542 } else if (WFLAGP(wwin
, floating
)) {
543 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
545 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
549 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
550 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
552 wWindowConfigureBorders(wwin
);
554 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
555 wFrameWindowPaint(wwin->frame);
558 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
562 static void animateResizeFlip(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
564 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
565 float cx
, cy
, cw
, ch
;
566 float xstep
, ystep
, wstep
, hstep
;
569 float angle
, final_angle
, delta
;
571 xstep
= (float)(fx
- x
) / steps
;
572 ystep
= (float)(fy
- y
) / steps
;
573 wstep
= (float)(fw
- w
) / steps
;
574 hstep
= (float)(fh
- h
) / steps
;
581 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
582 delta
= (float)(final_angle
/ FRAMES
);
583 for (angle
= 0;; angle
+= delta
) {
584 if (angle
> final_angle
)
587 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
588 dch
= (ch
/ 2) * cos(angle
);
589 midy
= cy
+ (ch
/ 2);
591 points
[0].x
= cx
+ dx
;
592 points
[0].y
= midy
- dch
;
593 points
[1].x
= cx
+ cw
- dx
;
594 points
[1].y
= points
[0].y
;
595 points
[2].x
= cx
+ cw
+ dx
;
596 points
[2].y
= midy
+ dch
;
597 points
[3].x
= cx
- dx
;
598 points
[3].y
= points
[2].y
;
599 points
[4].x
= points
[0].x
;
600 points
[4].y
= points
[0].y
;
603 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
605 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
606 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
611 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
617 if (angle
>= final_angle
)
627 animateResizeTwist(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
629 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
630 float cx
, cy
, cw
, ch
;
631 float xstep
, ystep
, wstep
, hstep
;
633 float angle
, final_angle
, a
, d
, delta
;
640 xstep
= (float)(fx
- x
) / steps
;
641 ystep
= (float)(fy
- y
) / steps
;
642 wstep
= (float)(fw
- w
) / steps
;
643 hstep
= (float)(fh
- h
) / steps
;
650 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
651 delta
= (float)(final_angle
/ FRAMES
);
652 for (angle
= 0;; angle
+= delta
) {
653 if (angle
> final_angle
)
657 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
659 points
[0].x
= cx
+ cos(angle
- a
) * d
;
660 points
[0].y
= cy
+ sin(angle
- a
) * d
;
661 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
662 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
663 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
664 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
665 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
666 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
667 points
[4].x
= cx
+ cos(angle
- a
) * d
;
668 points
[4].y
= cy
+ sin(angle
- a
) * d
;
670 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
672 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
673 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
678 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
684 if (angle
>= final_angle
)
693 static void animateResizeZoom(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
695 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
696 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
697 float xstep
, ystep
, wstep
, hstep
;
700 xstep
= (float)(fx
- x
) / steps
;
701 ystep
= (float)(fy
- y
) / steps
;
702 wstep
= (float)(fw
- w
) / steps
;
703 hstep
= (float)(fh
- h
) / steps
;
705 for (j
= 0; j
< FRAMES
; j
++) {
712 for (i
= 0; i
< steps
; i
++) {
713 for (j
= 0; j
< FRAMES
; j
++) {
714 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
715 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
718 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
719 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
723 for (j
= 0; j
< FRAMES
; j
++) {
724 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
725 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
726 if (j
< FRAMES
- 1) {
740 for (j
= 0; j
< FRAMES
; j
++) {
741 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
744 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
745 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
749 for (j
= 0; j
< FRAMES
; j
++) {
750 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
758 void animateResize(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int hiding
)
760 int style
= wPreferences
.iconification_style
; /* Catch the value */
763 if (style
== WIS_NONE
)
766 if (style
== WIS_RANDOM
) {
770 k
= (hiding
? 2 : 3);
774 steps
= (MINIATURIZE_ANIMATION_STEPS_T
* k
) / 3;
776 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
779 steps
= (MINIATURIZE_ANIMATION_STEPS_F
* k
) / 3;
781 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
785 steps
= (MINIATURIZE_ANIMATION_STEPS_Z
* k
) / 3;
787 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
791 #endif /* ANIMATIONS */
793 static void flushExpose()
797 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
798 WMHandleEvent(&tmpev
);
802 static void unmapTransientsFor(WWindow
* wwin
)
806 tmp
= wwin
->screen_ptr
->focused_window
;
808 /* unmap the transients for this transient */
809 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
810 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
811 unmapTransientsFor(tmp
);
812 tmp
->flags
.miniaturized
= 1;
813 if (!tmp
->flags
.shaded
) {
816 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
819 if (!tmp->flags.shaded)
821 wClientSetState(tmp
, IconicState
, None
);
823 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
829 static void mapTransientsFor(WWindow
* wwin
)
833 tmp
= wwin
->screen_ptr
->focused_window
;
835 /* recursively map the transients for this transient */
836 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
837 && tmp
->icon
== NULL
) {
838 mapTransientsFor(tmp
);
839 tmp
->flags
.miniaturized
= 0;
840 if (!tmp
->flags
.shaded
) {
843 XMapWindow(dpy
, tmp
->frame
->core
->window
);
845 tmp
->flags
.semi_focused
= 0;
847 if (!tmp->flags.shaded)
849 wClientSetState(tmp
, NormalState
, None
);
851 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
858 static void setupIconGrabs(WIcon
* icon
)
860 /* setup passive grabs on the icon */
861 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
862 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
863 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
864 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
865 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
866 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
871 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
878 /* hackish way to detect transient_for cycle */
879 i
= wwin
->screen_ptr
->window_count
+ 1;
881 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
882 wwin
= wWindowFor(wwin
->transient_for
);
885 if (i
== 0 && wwin
) {
886 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
894 static void removeIconGrabs(WIcon
* icon
)
896 /* remove passive grabs on the icon */
897 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
898 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
899 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
904 void wIconifyWindow(WWindow
* wwin
)
906 XWindowAttributes attribs
;
909 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
910 /* the window doesn't exist anymore */
914 if (wwin
->flags
.miniaturized
) {
918 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
919 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
921 if (owner
&& owner
->flags
.miniaturized
)
925 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
927 /* if the window is in another workspace, simplify process */
929 /* icon creation may take a while */
930 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
931 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
932 GrabModeAsync
, None
, None
, CurrentTime
);
935 if (!wPreferences
.disable_miniwindows
937 && !wwin
->flags
.net_handle_icon
940 if (!wwin
->flags
.icon_moved
) {
941 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
943 wwin
->icon
= wIconCreate(wwin
);
945 wwin
->icon
->mapped
= 1;
948 wwin
->flags
.miniaturized
= 1;
949 wwin
->flags
.mapped
= 0;
951 /* unmap transients */
953 unmapTransientsFor(wwin
);
956 wSoundPlay(WSOUND_ICONIFY
);
958 XUngrabPointer(dpy
, CurrentTime
);
960 /* let all Expose events arrive so that we can repaint
961 * something before the animation starts (and the server is grabbed) */
964 if (wPreferences
.disable_miniwindows
966 || wwin
->flags
.net_handle_icon
969 wClientSetState(wwin
, IconicState
, None
);
971 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
975 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
976 && !wPreferences
.no_animations
) {
979 if (!wPreferences
.disable_miniwindows
981 && !wwin
->flags
.net_handle_icon
986 iw
= wwin
->icon
->core
->width
;
987 ih
= wwin
->icon
->core
->height
;
990 if (wwin
->flags
.net_handle_icon
) {
1000 iw
= wwin
->screen_ptr
->scr_width
;
1001 ih
= wwin
->screen_ptr
->scr_height
;
1004 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1005 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
, False
);
1010 wwin
->flags
.skip_next_animation
= 0;
1012 if (!wPreferences
.disable_miniwindows
1014 && !wwin
->flags
.net_handle_icon
1018 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1019 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1021 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1023 AddToStackList(wwin
->icon
->core
);
1025 wLowerFrame(wwin
->icon
->core
);
1029 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1032 * It doesn't seem to be working and causes button event hangup
1033 * when deiconifying a transient window.
1034 setupIconGrabs(wwin->icon);
1036 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1037 && wPreferences
.focus_mode
== WKF_CLICK
) {
1042 if (!WFLAGP(tmp
, no_focusable
)
1043 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1044 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1048 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1049 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1050 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1053 if (!wwin
->screen_ptr
->flags
.startup
) {
1054 /* Catch up with events not processed while animation was running */
1055 Window clientwin
= wwin
->client_win
;
1057 ProcessPendingEvents();
1059 /* the window can disappear while ProcessPendingEvents() runs */
1060 if (!wWindowFor(clientwin
)) {
1067 /* maybe we want to do this regardless of net_handle_icon
1068 * it seems to me we might break behaviour this way.
1070 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1072 && !wwin
->flags
.net_handle_icon
1075 wIconSelect(wwin
->icon
);
1077 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1080 void wDeiconifyWindow(WWindow
* wwin
)
1083 /* we're hiding for show_desktop */
1084 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1085 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1087 int netwm_hidden
= False
;
1091 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1093 if (!wwin
->flags
.miniaturized
)
1096 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1097 WWindow
*owner
= recursiveTransientFor(wwin
);
1099 if (owner
&& owner
->flags
.miniaturized
) {
1100 wDeiconifyWindow(owner
);
1101 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1102 wRaiseFrame(wwin
->frame
->core
);
1107 wwin
->flags
.miniaturized
= 0;
1109 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1110 wwin
->flags
.mapped
= 1;
1113 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1114 /* maybe we want to do this regardless of net_handle_icon
1115 * it seems to me we might break behaviour this way.
1117 if (!wPreferences
.disable_miniwindows
1119 && !wwin
->flags
.net_handle_icon
1121 && wwin
->icon
!= NULL
) {
1122 if (wwin
->icon
->selected
)
1123 wIconSelect(wwin
->icon
);
1125 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1130 wSoundPlay(WSOUND_DEICONIFY
);
1132 /* if the window is in another workspace, do it silently */
1133 if (!netwm_hidden
) {
1135 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1136 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1139 if (!wPreferences
.disable_miniwindows
1141 && !wwin
->flags
.net_handle_icon
1146 iw
= wwin
->icon
->core
->width
;
1147 ih
= wwin
->icon
->core
->height
;
1150 if (wwin
->flags
.net_handle_icon
) {
1160 iw
= wwin
->screen_ptr
->scr_width
;
1161 ih
= wwin
->screen_ptr
->scr_height
;
1164 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1165 wwin
->frame_x
, wwin
->frame_y
,
1166 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, False
);
1168 #endif /* ANIMATIONS */
1169 wwin
->flags
.skip_next_animation
= 0;
1171 if (!wwin
->flags
.shaded
) {
1172 XMapWindow(dpy
, wwin
->client_win
);
1174 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1175 wRaiseFrame(wwin
->frame
->core
);
1176 if (!wwin
->flags
.shaded
) {
1177 wClientSetState(wwin
, NormalState
, None
);
1179 mapTransientsFor(wwin
);
1182 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1184 && !wwin
->flags
.net_handle_icon
1187 RemoveFromStackList(wwin
->icon
->core
);
1188 /* removeIconGrabs(wwin->icon); */
1189 wIconDestroy(wwin
->icon
);
1193 if (!netwm_hidden
) {
1196 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1199 if (!wwin
->screen_ptr
->flags
.startup
) {
1200 /* Catch up with events not processed while animation was running */
1201 Window clientwin
= wwin
->client_win
;
1203 ProcessPendingEvents();
1205 /* the window can disappear while ProcessPendingEvents() runs */
1206 if (!wWindowFor(clientwin
)) {
1213 if (wPreferences
.auto_arrange_icons
) {
1214 wArrangeIcons(wwin
->screen_ptr
, True
);
1217 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1219 /* In case we were shaded and iconified, also unshade */
1221 wUnshadeWindow(wwin
);
1224 static void hideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
)
1226 if (wwin
->flags
.miniaturized
) {
1228 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1229 wwin
->icon
->mapped
= 0;
1231 wwin
->flags
.hidden
= 1;
1233 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1237 if (wwin
->flags
.inspector_open
) {
1238 wHideInspectorForWindow(wwin
);
1241 wwin
->flags
.hidden
= 1;
1244 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1246 wSoundPlay(WSOUND_HIDE
);
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
, True
);
1255 wwin
->flags
.skip_next_animation
= 0;
1257 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1260 void wHideOtherApplications(WWindow
* awin
)
1267 wwin
= awin
->screen_ptr
->focused_window
;
1271 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1272 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1273 && !wwin
->flags
.internal_window
1274 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1276 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1277 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1278 wwin
->flags
.skip_next_animation
= 1;
1279 wIconifyWindow(wwin
);
1281 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1282 tapp
= wApplicationOf(wwin
->main_window
);
1284 tapp
->flags
.skip_next_animation
= 1;
1285 wHideApplication(tapp
);
1287 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1288 wwin
->flags
.skip_next_animation
= 1;
1289 wIconifyWindow(wwin
);
1297 wSetFocusTo(awin->screen_ptr, awin);
1301 void wHideApplication(WApplication
* wapp
)
1309 wwarning("trying to hide a non grouped window");
1312 if (!wapp
->main_window_desc
) {
1313 wwarning("group leader not found for window group");
1316 scr
= wapp
->main_window_desc
->screen_ptr
;
1318 wlist
= scr
->focused_window
;
1322 if (wlist
->main_window
== wapp
->main_window
)
1323 wapp
->last_focused
= wlist
;
1325 wapp
->last_focused
= NULL
;
1327 animate
= !wapp
->flags
.skip_next_animation
;
1330 if (wlist
->main_window
== wapp
->main_window
) {
1331 if (wlist
->flags
.focused
) {
1334 if (wapp
->app_icon
) {
1335 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1336 wapp
->app_icon
->y_pos
, wlist
, animate
);
1340 wlist
= wlist
->prev
;
1343 wapp
->flags
.skip_next_animation
= 0;
1346 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1347 wlist
= scr
->focused_window
;
1349 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1350 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1352 wlist
= wlist
->prev
;
1354 wSetFocusTo(scr
, wlist
);
1356 wSetFocusTo(scr
, NULL
);
1360 wapp
->flags
.hidden
= 1;
1362 if (wPreferences
.auto_arrange_icons
) {
1363 wArrangeIcons(scr
, True
);
1367 wAppIconPaint(wapp
->app_icon
);
1371 static void unhideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
, int bringToCurrentWS
)
1373 if (bringToCurrentWS
)
1374 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1376 wwin
->flags
.hidden
= 0;
1378 wSoundPlay(WSOUND_UNHIDE
);
1380 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1381 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1382 icon
->core
->width
, icon
->core
->height
,
1383 wwin
->frame_x
, wwin
->frame_y
,
1384 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, True
);
1387 wwin
->flags
.skip_next_animation
= 0;
1388 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1389 XMapWindow(dpy
, wwin
->client_win
);
1390 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1391 wClientSetState(wwin
, NormalState
, None
);
1392 wwin
->flags
.mapped
= 1;
1393 wRaiseFrame(wwin
->frame
->core
);
1395 if (wwin
->flags
.inspector_open
) {
1396 wUnhideInspectorForWindow(wwin
);
1399 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1402 void wUnhideApplication(WApplication
* wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1405 WWindow
*wlist
, *next
;
1406 WWindow
*focused
= NULL
;
1412 scr
= wapp
->main_window_desc
->screen_ptr
;
1413 wlist
= scr
->focused_window
;
1417 /* goto beginning of list */
1419 wlist
= wlist
->prev
;
1421 animate
= !wapp
->flags
.skip_next_animation
;
1426 if (wlist
->main_window
== wapp
->main_window
) {
1427 if (wlist
->flags
.focused
)
1429 else if (!focused
|| !focused
->flags
.focused
)
1432 if (wlist
->flags
.miniaturized
) {
1433 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1434 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1435 if (!wlist
->icon
->mapped
) {
1438 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1439 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1440 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1444 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1445 wlist
->icon
->mapped
= 1;
1447 wRaiseFrame(wlist
->icon
->core
);
1449 if (bringToCurrentWS
)
1450 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1451 wlist
->flags
.hidden
= 0;
1452 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1453 wDeiconifyWindow(wlist
);
1455 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1456 } else if (wlist
->flags
.shaded
) {
1457 if (bringToCurrentWS
)
1458 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1459 wlist
->flags
.hidden
= 0;
1460 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1461 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1463 wUnshadeWindow(wlist
);
1464 wRaiseFrame(wlist
->frame
->core
);
1467 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1468 } else if (wlist
->flags
.hidden
) {
1469 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1470 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1473 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1474 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1476 wRaiseFrame(wlist
->frame
->core
);
1482 wapp
->flags
.skip_next_animation
= 0;
1483 wapp
->flags
.hidden
= 0;
1485 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1486 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1487 wSetFocusTo(scr
, wapp
->last_focused
);
1488 } else if (focused
) {
1489 wSetFocusTo(scr
, focused
);
1491 wapp
->last_focused
= NULL
;
1492 if (wPreferences
.auto_arrange_icons
) {
1493 wArrangeIcons(scr
, True
);
1496 wAppIconPaint(wapp
->app_icon
);
1500 void wShowAllWindows(WScreen
* scr
)
1502 WWindow
*wwin
, *old_foc
;
1505 old_foc
= wwin
= scr
->focused_window
;
1507 if (!wwin
->flags
.internal_window
&&
1508 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1509 if (wwin
->flags
.miniaturized
) {
1510 wwin
->flags
.skip_next_animation
= 1;
1511 wDeiconifyWindow(wwin
);
1512 } else if (wwin
->flags
.hidden
) {
1513 wapp
= wApplicationOf(wwin
->main_window
);
1515 wUnhideApplication(wapp
, False
, False
);
1517 wwin
->flags
.skip_next_animation
= 1;
1518 wDeiconifyWindow(wwin
);
1524 wSetFocusTo(scr
, old_foc
);
1525 /*wRaiseFrame(old_foc->frame->core); */
1528 void wRefreshDesktop(WScreen
* scr
)
1531 XSetWindowAttributes attr
;
1533 attr
.backing_store
= NotUseful
;
1534 attr
.save_under
= False
;
1535 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1536 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1537 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1538 XMapRaised(dpy
, win
);
1539 XDestroyWindow(dpy
, win
);
1543 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1549 const int heads
= wXineramaHeads(scr
);
1552 int pf
; /* primary axis */
1553 int sf
; /* secondary axis */
1557 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1563 int isize
= wPreferences
.icon_size
;
1565 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1567 for (head
= 0; head
< heads
; ++head
) {
1569 WMRect rect
= wGetRectForHead(scr
, head
);
1571 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1572 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1575 vars
[head
].pi
= vars
[head
].si
= 0;
1576 vars
[head
].sx1
= rect
.pos
.x
;
1577 vars
[head
].sy1
= rect
.pos
.y
;
1578 vars
[head
].sw
= rect
.size
.width
;
1579 vars
[head
].sh
= rect
.size
.height
;
1580 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1581 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1585 if (scr
->dock
->on_right_side
)
1586 vars
[head
].sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1588 vars
[head
].sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1592 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1593 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1594 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1595 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1597 /* icon yard boundaries */
1598 if (wPreferences
.icon_yard
& IY_VERT
) {
1599 vars
[head
].pf
= vars
[head
].fullH
;
1600 vars
[head
].sf
= vars
[head
].fullW
;
1602 vars
[head
].pf
= vars
[head
].fullW
;
1603 vars
[head
].sf
= vars
[head
].fullH
;
1605 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1606 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1609 vars
[head
].xo
= vars
[head
].sx1
;
1612 if (wPreferences
.icon_yard
& IY_TOP
) {
1613 vars
[head
].yo
= vars
[head
].sy1
;
1616 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1621 #define X ((wPreferences.icon_yard & IY_VERT) \
1622 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1623 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1625 #define Y ((wPreferences.icon_yard & IY_VERT) \
1626 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1627 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1629 /* arrange application icons */
1630 aicon
= scr
->app_icon_list
;
1631 /* reverse them to avoid unnecessarily sliding of icons */
1632 while (aicon
&& aicon
->next
)
1633 aicon
= aicon
->next
;
1636 if (!aicon
->docked
) {
1637 /* CHECK: can icon be NULL here ? */
1638 /* The intention here is to place the AppIcon on the head that
1639 * contains most of the applications _main_ window. */
1640 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1642 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1644 if (!wPreferences
.no_animations
) {
1645 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1647 #endif /* ANIMATIONS */
1649 wAppIconMove(aicon
, X
, Y
);
1651 if (vars
[head
].pi
>= vars
[head
].pf
) {
1656 aicon
= aicon
->prev
;
1659 /* arrange miniwindows */
1660 wwin
= scr
->focused_window
;
1661 /* reverse them to avoid unnecessarily shuffling */
1662 while (wwin
&& wwin
->prev
)
1666 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1667 (wwin
->frame
->workspace
== scr
->current_workspace
||
1668 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1670 head
= wGetHeadForWindow(wwin
);
1672 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1673 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1675 if (wPreferences
.no_animations
) {
1676 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1678 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1679 wwin
->icon_y
, X
, Y
);
1682 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1683 #endif /* ANIMATIONS */
1689 if (vars
[head
].pi
>= vars
[head
].pf
) {
1696 wwin
->flags
.icon_moved
= 0;
1698 /* we reversed the order, so we use next */
1706 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1710 int pf
; /* primary axis */
1711 int sf
; /* secondary axis */
1715 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1719 int isize
= wPreferences
.icon_size
;
1722 * Find out screen boundaries.
1726 * Allows each head to have miniwindows
1728 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1732 sw
= rect
.size
.width
;
1733 sh
= rect
.size
.height
;
1737 if (scr
->dock
->on_right_side
)
1738 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1740 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1743 sw
= isize
* (scr
->scr_width
/ isize
);
1744 sh
= isize
* (scr
->scr_height
/ isize
);
1746 sw
= isize
* (sw
/ isize
);
1747 sh
= isize
* (sh
/ isize
);
1749 fullW
= (sx2
- sx1
) / isize
;
1750 fullH
= (sy2
- sy1
) / isize
;
1752 /* icon yard boundaries */
1753 if (wPreferences
.icon_yard
& IY_VERT
) {
1760 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1767 if (wPreferences
.icon_yard
& IY_TOP
) {
1775 /* arrange icons putting the most recently focused window
1776 * as the last icon */
1777 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1778 : xo + xs*(pi*isize))
1779 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1780 : yo + ys*(si*isize))
1782 /* arrange application icons */
1783 aicon
= scr
->app_icon_list
;
1784 /* reverse them to avoid unnecessarily sliding of icons */
1785 while (aicon
&& aicon
->next
)
1786 aicon
= aicon
->next
;
1791 if (!aicon
->docked
) {
1792 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1794 if (!wPreferences
.no_animations
) {
1795 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1797 #endif /* ANIMATIONS */
1799 wAppIconMove(aicon
, X
, Y
);
1802 /* we reversed the order so we use prev */
1803 aicon
= aicon
->prev
;
1810 /* arrange miniwindows */
1812 wwin
= scr
->focused_window
;
1813 /* reverse them to avoid unnecessarily shuffling */
1814 while (wwin
&& wwin
->prev
)
1818 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1819 (wwin
->frame
->workspace
== scr
->current_workspace
||
1820 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1822 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1823 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1825 if (wPreferences
.no_animations
) {
1826 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1828 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1829 wwin
->icon_y
, X
, Y
);
1832 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1833 #endif /* ANIMATIONS */
1841 wwin
->flags
.icon_moved
= 0;
1843 /* we reversed the order, so we use next */
1853 void wSelectWindow(WWindow
* wwin
, Bool flag
)
1855 WScreen
*scr
= wwin
->screen_ptr
;
1858 wwin
->flags
.selected
= 1;
1859 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1861 if (!HAS_BORDER(wwin
)) {
1862 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1865 if (!scr
->selected_windows
)
1866 scr
->selected_windows
= WMCreateArray(4);
1867 WMAddToArray(scr
->selected_windows
, wwin
);
1869 wwin
->flags
.selected
= 0;
1870 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1872 if (!HAS_BORDER(wwin
)) {
1873 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1876 if (scr
->selected_windows
) {
1877 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1882 void wMakeWindowVisible(WWindow
* wwin
)
1884 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1885 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1887 if (wwin
->flags
.shaded
) {
1888 wUnshadeWindow(wwin
);
1890 if (wwin
->flags
.hidden
) {
1893 app
= wApplicationOf(wwin
->main_window
);
1895 /* trick to get focus to this window */
1896 app
->last_focused
= wwin
;
1897 wUnhideApplication(app
, False
, False
);
1900 if (wwin
->flags
.miniaturized
) {
1901 wDeiconifyWindow(wwin
);
1903 if (!WFLAGP(wwin
, no_focusable
))
1904 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1905 wRaiseFrame(wwin
->frame
->core
);