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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
33 #include "WindowMaker.h"
39 #include "application.h"
45 #include "winspector.h"
46 #include "workspace.h"
50 /****** Global Variables ******/
52 int ignore_wks_change
= 0;
53 extern Time LastTimestamp
;
54 extern Time LastFocusChange
;
55 extern WPreferences wPreferences
;
56 extern Atom _XA_WM_TAKE_FOCUS
;
57 extern void ProcessPendingEvents();
58 extern int calcIntersectionLength(int p1
, int l1
, int p2
, int l2
);
60 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
61 unsigned int *new_width
, unsigned int *new_height
);
62 static void save_old_geometry(WWindow
*wwin
, int directions
);
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
}};
78 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
79 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
81 static int compareTimes(Time t1
, Time t2
)
87 return (diff
< 60000) ? 1 : -1;
91 static void shade_animate(WWindow
*wwin
, Bool what
);
93 static void shade_animate(WWindow
*wwin
, Bool what
) { }
97 *----------------------------------------------------------------------
99 * Changes the window focus to the one passed as argument.
100 * If the window to focus is not already focused, it will be brought
101 * to the head of the list of windows. Previously focused window is
105 * Window list may be reordered and the window focus is changed.
107 *----------------------------------------------------------------------
109 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
111 static WScreen
*old_scr
= NULL
;
113 WWindow
*old_focused
;
114 WWindow
*focused
= scr
->focused_window
;
115 Time timestamp
= LastTimestamp
;
116 WApplication
*oapp
= NULL
, *napp
= NULL
;
119 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
125 old_focused
= old_scr
->focused_window
;
127 LastFocusChange
= timestamp
;
130 oapp
= wApplicationOf(old_focused
->main_window
);
133 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
135 wWindowUnfocus(old_focused
);
138 wAppMenuUnmap(oapp
->menu
);
139 wApplicationDeactivate(oapp
);
142 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
146 if (old_scr
!= scr
&& old_focused
)
147 wWindowUnfocus(old_focused
);
149 wasfocused
= wwin
->flags
.focused
;
150 napp
= wApplicationOf(wwin
->main_window
);
152 /* remember last workspace where the app has been */
154 napp
->last_workspace
= wwin
->frame
->workspace
;
156 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
157 /* install colormap if colormap mode is lock mode */
158 if (wPreferences
.colormap_mode
== WCM_CLICK
)
159 wColormapInstallForWindow(scr
, wwin
);
161 /* set input focus */
162 switch (wwin
->focus_mode
) {
164 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
167 case WFM_LOCALLY_ACTIVE
:
168 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
170 case WFM_GLOBALLY_ACTIVE
:
175 if (wwin
->protocols
.TAKE_FOCUS
)
176 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
180 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
183 if (WFLAGP(wwin
, no_focusable
))
186 /* if this is not the focused window focus it */
187 if (focused
!= wwin
) {
188 /* change the focus window list order */
190 wwin
->prev
->next
= wwin
->next
;
193 wwin
->next
->prev
= wwin
->prev
;
195 wwin
->prev
= focused
;
196 focused
->next
= wwin
;
198 scr
->focused_window
= wwin
;
200 if (oapp
&& oapp
!= napp
) {
201 wAppMenuUnmap(oapp
->menu
);
202 wApplicationDeactivate(oapp
);
206 wWindowFocus(wwin
, focused
);
208 if (napp
&& !wasfocused
) {
210 wUserMenuRefreshInstances(napp
->menu
, wwin
);
211 #endif /* USER_MENU */
213 if (wwin
->flags
.mapped
)
214 wAppMenuMap(napp
->menu
, wwin
);
217 wApplicationActivate(napp
);
223 void wShadeWindow(WWindow
*wwin
)
226 if (wwin
->flags
.shaded
)
229 XLowerWindow(dpy
, wwin
->client_win
);
230 shade_animate(wwin
, SHADE
);
232 wwin
->flags
.skip_next_animation
= 0;
233 wwin
->flags
.shaded
= 1;
234 wwin
->flags
.mapped
= 0;
235 /* prevent window withdrawal when getting UnmapNotify */
236 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
237 XUnmapWindow(dpy
, wwin
->client_win
);
238 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
240 /* for the client it's just like iconification */
241 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
243 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
244 wWindowSynthConfigureNotify(wwin
);
247 wClientSetState(wwin, IconicState, None);
250 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
253 if (!wwin
->screen_ptr
->flags
.startup
) {
254 /* Catch up with events not processed while animation was running */
255 ProcessPendingEvents();
260 void wUnshadeWindow(WWindow
*wwin
)
263 if (!wwin
->flags
.shaded
)
266 wwin
->flags
.shaded
= 0;
267 wwin
->flags
.mapped
= 1;
268 XMapWindow(dpy
, wwin
->client_win
);
270 shade_animate(wwin
, UNSHADE
);
272 wwin
->flags
.skip_next_animation
= 0;
273 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
274 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
276 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
277 wWindowSynthConfigureNotify(wwin
);
279 /* if the window is focused, set the focus again as it was disabled during
281 if (wwin
->flags
.focused
)
282 wSetFocusTo(wwin
->screen_ptr
, wwin
);
284 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
287 /* Set the old coordinates using the current values */
288 static void save_old_geometry(WWindow
*wwin
, int directions
)
290 /* never been saved? */
291 if (! wwin
->old_geometry
.width
)
292 directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
293 if (! wwin
->old_geometry
.height
)
294 directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
296 if (directions
& SAVE_GEOMETRY_X
)
297 wwin
->old_geometry
.x
= wwin
->frame_x
;
298 if (directions
& SAVE_GEOMETRY_Y
)
299 wwin
->old_geometry
.y
= wwin
->frame_y
;
300 if (directions
& SAVE_GEOMETRY_WIDTH
)
301 wwin
->old_geometry
.width
= wwin
->client
.width
;
302 if (directions
& SAVE_GEOMETRY_HEIGHT
)
303 wwin
->old_geometry
.height
= wwin
->client
.height
;
306 static void remember_geometry(WWindow
*wwin
, int *x
, int *y
, int *w
, int *h
)
308 WMRect old_geom_rect
;
312 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
313 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
314 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
315 *x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
316 *y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
317 *w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
318 *h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
321 /* Remember geometry for unmaximizing */
322 void update_saved_geometry(WWindow
*wwin
)
324 /* NOT if we aren't already maximized
325 * we'll save geometry when maximizing */
326 if (!wwin
->flags
.maximized
)
329 /* NOT if we are fully maximized */
330 if ((wwin
->flags
.maximized
& MAX_MAXIMUS
) ||
331 ((wwin
->flags
.maximized
& MAX_HORIZONTAL
) &&
332 (wwin
->flags
.maximized
& MAX_VERTICAL
)))
335 /* save the co-ordinate in the axis in which we AREN'T maximized */
336 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
337 save_old_geometry(wwin
, SAVE_GEOMETRY_Y
);
338 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
339 save_old_geometry(wwin
, SAVE_GEOMETRY_X
);
342 #define IS_MAX_HORIZONTALLY(directions) ((directions & MAX_HORIZONTAL) | (directions & MAX_LEFTHALF) | (directions & MAX_RIGHTHALF))
343 void wMaximizeWindow(WWindow
*wwin
, int directions
)
346 unsigned int new_width
, new_height
, half_scr_width
;
349 unsigned int maximus_width
= 0;
350 unsigned int maximus_height
= 0;
351 WArea usableArea
, totalArea
;
353 int save_directions
= 0;
356 if (!IS_RESIZABLE(wwin
))
359 if (!HAS_BORDER(wwin
))
362 /* the size to adjust the geometry */
363 adj_size
= FRAME_BORDER_WIDTH
* 2 * has_border
;
365 /* save old coordinates before we change the current values
366 * always if the window is not currently maximized at all
367 * but never if the window has been Maximusized */
368 if (!wwin
->flags
.maximized
)
369 save_directions
|= SAVE_GEOMETRY_ALL
;
370 else if (!(wwin
->flags
.old_maximized
& MAX_MAXIMUS
)) {
371 if ((directions
& MAX_VERTICAL
) &&
372 !(wwin
->flags
.maximized
& MAX_VERTICAL
))
373 save_directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
374 if (IS_MAX_HORIZONTALLY(directions
) &&
375 !IS_MAX_HORIZONTALLY(wwin
->flags
.maximized
))
376 save_directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
378 if ((directions
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
379 save_directions
|= SAVE_GEOMETRY_ALL
;
380 save_old_geometry(wwin
, save_directions
);
384 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
385 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
386 usableArea
= totalArea
;
388 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
389 WScreen
*scr
= wwin
->screen_ptr
;
392 if (directions
& MAX_KEYBOARD
)
393 head
= wGetHeadForWindow(wwin
);
395 head
= wGetHeadForPointerLocation(scr
);
397 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
400 /* remember Maximus geometry if we'll need it later */
401 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) || (directions
& MAX_MAXIMUS
))
402 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
404 /* Only save directions, not kbd or xinerama hints */
405 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
407 if (WFLAGP(wwin
, full_maximize
)) {
408 usableArea
= totalArea
;
410 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
412 if (wwin
->flags
.shaded
) {
413 wwin
->flags
.skip_next_animation
= 1;
414 wUnshadeWindow(wwin
);
417 if (directions
& MAX_HORIZONTAL
) {
418 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
419 new_x
= usableArea
.x1
;
420 } else if (directions
& MAX_LEFTHALF
) {
421 new_width
= half_scr_width
- adj_size
;
422 new_x
= usableArea
.x1
;
423 wwin
->flags
.old_maximized
|= MAX_LEFTHALF
;
424 wwin
->flags
.old_maximized
&= ~MAX_RIGHTHALF
;
425 } else if (directions
& MAX_RIGHTHALF
) {
426 new_width
= half_scr_width
- adj_size
;
427 new_x
= usableArea
.x1
+ half_scr_width
;
428 wwin
->flags
.old_maximized
|= MAX_RIGHTHALF
;
429 wwin
->flags
.old_maximized
&= ~MAX_LEFTHALF
;
430 } else if (wwin
->flags
.old_maximized
& MAX_MAXIMUS
) {
432 new_width
= maximus_width
- adj_size
;
433 } else if (IS_MAX_HORIZONTALLY(wwin
->flags
.maximized
)) {
434 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
435 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
437 wwin
->flags
.old_maximized
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
438 new_x
= wwin
->frame_x
;
439 new_width
= wwin
->frame
->core
->width
;
442 if (directions
& MAX_VERTICAL
) {
443 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
444 new_y
= usableArea
.y1
;
445 if (WFLAGP(wwin
, full_maximize
)) {
446 new_y
-= wwin
->frame
->top_width
;
447 new_height
+= wwin
->frame
->bottom_width
- 1;
449 } else if (wwin
->flags
.old_maximized
& MAX_MAXIMUS
) {
451 new_height
= maximus_height
- adj_size
;
452 /* HACK: this will be subtracted again below */
453 new_height
+= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
454 } else if (wwin
->flags
.maximized
& MAX_VERTICAL
) {
455 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
456 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
457 /* HACK: this will be subtracted again below */
458 new_height
+= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
459 wwin
->flags
.old_maximized
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
461 new_y
= wwin
->frame_y
;
462 new_height
= wwin
->frame
->core
->height
;
465 if (!WFLAGP(wwin
, full_maximize
)) {
466 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
469 if (directions
& MAX_MAXIMUS
) {
472 new_width
= maximus_width
- adj_size
;
473 new_height
= maximus_height
- adj_size
;
474 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
475 new_y
-= wwin
->frame
->top_width
;
476 new_height
+= wwin
->frame
->top_width
- 1;
478 wwin
->maximus_x
= new_x
;
479 wwin
->maximus_y
= new_y
;
480 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
483 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
485 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
486 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
488 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
489 wWindowSynthConfigureNotify(wwin
);
491 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
493 /* set maximization state */
494 wwin
->flags
.maximized
= directions
;
495 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
496 wwin
->flags
.maximized
= MAX_MAXIMUS
;
499 /* generic (un)maximizer */
500 void handleMaximize(WWindow
*wwin
, int directions
)
502 int current
= wwin
->flags
.maximized
;
503 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
504 int effective
= requested
^ current
;
505 int flags
= directions
& ~requested
;
508 /* allow wMaximizeWindow to restore the Maximusized size */
509 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
510 !(requested
& MAX_MAXIMUS
))
511 wMaximizeWindow(wwin
, flags
);
513 wUnmaximizeWindow(wwin
);
516 /* MAX_MAXIMUS takes precedence */
517 effective
&= ~MAX_MAXIMUS
;
518 if (requested
& MAX_MAXIMUS
) {
519 /* window was previously Maximusized then maximized */
520 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !current
) {
521 wUnmaximizeWindow(wwin
);
525 effective
= MAX_MAXIMUS
;
527 else if (requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
))
528 effective
= requested
;
530 /* handle MAX_HORIZONTAL -> MAX_(LEFT|RIGHT)HALF */
531 if (IS_MAX_HORIZONTALLY(current
)) {
532 if (IS_MAX_HORIZONTALLY(requested
)) {
533 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
);
534 effective
|= (requested
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
));
535 if (requested
& MAX_HORIZONTAL
) {
536 /* restore to half maximization */
537 if (wwin
->flags
.old_maximized
& MAX_LEFTHALF
)
538 effective
|= MAX_LEFTHALF
;
539 else if (wwin
->flags
.old_maximized
& MAX_RIGHTHALF
)
540 effective
|= MAX_RIGHTHALF
;
542 /* MAX_VERTICAL is implicit with MAX_(LEFT|RIGHT)HALF */
544 effective
|= MAX_VERTICAL
;
546 /* toggling MAX_VERTICAL */
547 if ((requested
& MAX_VERTICAL
) &&
548 (current
& MAX_VERTICAL
)) {
549 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_VERTICAL
);
553 /* handle MAX_VERTICAL -> MAX_(LEFT|RIGHT)HALF */
554 if (current
& MAX_VERTICAL
) {
555 if ((requested
& MAX_LEFTHALF
) ||
556 (requested
& MAX_RIGHTHALF
)) {
557 effective
|= MAX_VERTICAL
;
560 /* toggling MAX_HORIZONTAL */
561 if ((requested
& MAX_HORIZONTAL
) &&
562 (current
& MAX_HORIZONTAL
))
563 effective
&= ~MAX_HORIZONTAL
;
565 wMaximizeWindow(wwin
, effective
| flags
);
570 /* the window boundary coordinates */
580 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
582 obs
->left
= wwin
->frame_x
;
583 obs
->top
= wwin
->frame_y
;
584 obs
->width
= wwin
->frame
->core
->width
;
585 obs
->height
= wwin
->frame
->core
->height
;
586 obs
->bottom
= obs
->top
+ obs
->height
;
587 obs
->right
= obs
->left
+ obs
->width
;
591 * Maximus: tiled maximization (maximize without overlapping other windows)
593 * The original window 'orig' will be maximized to new coordinates 'new'.
594 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
596 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
597 unsigned int *new_width
, unsigned int *new_height
)
600 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
601 short int adjust_height
;
602 int x_intsect
, y_intsect
;
603 /* the obstructing, original and new windows */
604 win_coords obs
, orig
, new;
606 /* set the original coordinate positions of the window to be Maximumized */
607 if (wwin
->flags
.maximized
) {
608 /* window is already maximized; consider original geometry */
609 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
610 orig
.bottom
= orig
.top
+ orig
.height
;
611 orig
.right
= orig
.left
+ orig
.width
;
614 set_window_coords(wwin
, &orig
);
616 /* Try to fully maximize first, then readjust later */
617 new.left
= usableArea
.x1
;
618 new.right
= usableArea
.x2
;
619 new.top
= usableArea
.y1
;
620 new.bottom
= usableArea
.y2
;
622 if (HAS_TITLEBAR(wwin
))
623 tbar_height_0
= TITLEBAR_HEIGHT
;
624 if (HAS_RESIZEBAR(wwin
))
625 rbar_height_0
= RESIZEBAR_HEIGHT
;
626 if (HAS_BORDER(wwin
))
627 bd_width_0
= FRAME_BORDER_WIDTH
;
629 /* the length to be subtracted if the window has titlebar, etc */
630 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
633 /* The focused window is always the last in the list */
635 /* ignore windows in other workspaces etc */
636 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
637 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
643 /* Set the coordinates of obstructing window */
644 set_window_coords(tmp
, &obs
);
646 /* Try to maximize in the y direction first */
647 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
648 if (x_intsect
!= 0) {
649 /* TODO: Consider the case when coords are equal */
650 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
651 /* w_0 is below the bottom of w_j */
652 new.top
= obs
.bottom
+ 1;
654 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
655 /* The bottom of w_0 is above the top of w_j */
656 new.bottom
= obs
.top
- 1;
663 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
664 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
670 set_window_coords(tmp
, &obs
);
673 * Use the new.top and new.height instead of original values
674 * as they may have different intersections with the obstructing windows
676 new.height
= new.bottom
- new.top
- adjust_height
;
677 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
678 if (y_intsect
!= 0) {
679 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
680 /* w_0 is completely to the right of w_j */
681 new.left
= obs
.right
+ 1;
683 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
684 /* w_0 is completely to the left of w_j */
685 new.right
= obs
.left
- 1;
692 /* xcalc needs -7 here, but other apps don't */
693 *new_height
= new.bottom
- new.top
- adjust_height
- 1;;
694 *new_width
= new.right
- new.left
;
697 void wUnmaximizeWindow(WWindow
*wwin
)
701 if (!wwin
->flags
.maximized
)
704 if (wwin
->flags
.shaded
) {
705 wwin
->flags
.skip_next_animation
= 1;
706 wUnshadeWindow(wwin
);
709 /* Use old coordinates if they are set, current values otherwise */
710 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
712 /* unMaximusize relative to original position */
713 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
714 x
+= wwin
->frame_x
- wwin
->maximus_x
;
715 y
+= wwin
->frame_y
- wwin
->maximus_y
;
718 wwin
->flags
.maximized
= 0;
719 wwin
->flags
.old_maximized
= 0;
720 wWindowConfigure(wwin
, x
, y
, w
, h
);
721 wWindowSynthConfigureNotify(wwin
);
723 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
726 void wFullscreenWindow(WWindow
*wwin
)
731 if (wwin
->flags
.fullscreen
)
734 wwin
->flags
.fullscreen
= True
;
736 wWindowConfigureBorders(wwin
);
738 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
740 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
741 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
742 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
743 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
745 head
= wGetHeadForWindow(wwin
);
746 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
747 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
749 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
752 void wUnfullscreenWindow(WWindow
*wwin
)
754 if (!wwin
->flags
.fullscreen
)
757 wwin
->flags
.fullscreen
= False
;
759 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
760 if (WFLAGP(wwin
, sunken
)) {
761 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
762 } else if (WFLAGP(wwin
, floating
)) {
763 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
765 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
769 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
770 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
772 wWindowConfigureBorders(wwin
);
774 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
775 wFrameWindowPaint(wwin->frame);
778 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
782 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
784 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
785 float cx
, cy
, cw
, ch
;
786 float xstep
, ystep
, wstep
, hstep
;
789 float angle
, final_angle
, delta
;
791 xstep
= (float)(fx
- x
) / steps
;
792 ystep
= (float)(fy
- y
) / steps
;
793 wstep
= (float)(fw
- w
) / steps
;
794 hstep
= (float)(fh
- h
) / steps
;
801 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
802 delta
= (float)(final_angle
/ FRAMES
);
803 for (angle
= 0;; angle
+= delta
) {
804 if (angle
> final_angle
)
807 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
808 dch
= (ch
/ 2) * cos(angle
);
809 midy
= cy
+ (ch
/ 2);
811 points
[0].x
= cx
+ dx
;
812 points
[0].y
= midy
- dch
;
813 points
[1].x
= cx
+ cw
- dx
;
814 points
[1].y
= points
[0].y
;
815 points
[2].x
= cx
+ cw
+ dx
;
816 points
[2].y
= midy
+ dch
;
817 points
[3].x
= cx
- dx
;
818 points
[3].y
= points
[2].y
;
819 points
[4].x
= points
[0].x
;
820 points
[4].y
= points
[0].y
;
823 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
825 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
827 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
833 if (angle
>= final_angle
)
843 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
845 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
846 float cx
, cy
, cw
, ch
;
847 float xstep
, ystep
, wstep
, hstep
;
849 float angle
, final_angle
, a
, d
, delta
;
856 xstep
= (float)(fx
- x
) / steps
;
857 ystep
= (float)(fy
- y
) / steps
;
858 wstep
= (float)(fw
- w
) / steps
;
859 hstep
= (float)(fh
- h
) / steps
;
866 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
867 delta
= (float)(final_angle
/ FRAMES
);
868 for (angle
= 0;; angle
+= delta
) {
869 if (angle
> final_angle
)
873 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
875 points
[0].x
= cx
+ cos(angle
- a
) * d
;
876 points
[0].y
= cy
+ sin(angle
- a
) * d
;
877 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
878 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
879 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
880 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
881 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
882 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
883 points
[4].x
= cx
+ cos(angle
- a
) * d
;
884 points
[4].y
= cy
+ sin(angle
- a
) * d
;
886 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
888 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
890 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
896 if (angle
>= final_angle
)
905 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
907 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
908 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
909 float xstep
, ystep
, wstep
, hstep
;
912 xstep
= (float)(fx
- x
) / steps
;
913 ystep
= (float)(fy
- y
) / steps
;
914 wstep
= (float)(fw
- w
) / steps
;
915 hstep
= (float)(fh
- h
) / steps
;
917 for (j
= 0; j
< FRAMES
; j
++) {
924 for (i
= 0; i
< steps
; i
++) {
925 for (j
= 0; j
< FRAMES
; j
++) {
926 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
927 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
930 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
932 for (j
= 0; j
< FRAMES
; j
++) {
933 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
934 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
935 if (j
< FRAMES
- 1) {
949 for (j
= 0; j
< FRAMES
; j
++) {
950 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
953 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
955 for (j
= 0; j
< FRAMES
; j
++) {
956 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
964 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
966 int style
= wPreferences
.iconification_style
; /* Catch the value */
969 if (style
== WIS_NONE
)
972 if (style
== WIS_RANDOM
) {
978 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
980 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
983 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
985 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
989 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
991 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
995 #endif /* ANIMATIONS */
997 static void flushExpose(void)
1001 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
1002 WMHandleEvent(&tmpev
);
1006 static void unmapTransientsFor(WWindow
*wwin
)
1010 tmp
= wwin
->screen_ptr
->focused_window
;
1012 /* unmap the transients for this transient */
1013 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
1014 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
1015 unmapTransientsFor(tmp
);
1016 tmp
->flags
.miniaturized
= 1;
1017 if (!tmp
->flags
.shaded
) {
1020 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
1023 if (!tmp->flags.shaded)
1025 wClientSetState(tmp
, IconicState
, None
);
1027 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1033 static void mapTransientsFor(WWindow
*wwin
)
1037 tmp
= wwin
->screen_ptr
->focused_window
;
1039 /* recursively map the transients for this transient */
1040 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1041 && tmp
->icon
== NULL
) {
1042 mapTransientsFor(tmp
);
1043 tmp
->flags
.miniaturized
= 0;
1044 if (!tmp
->flags
.shaded
) {
1047 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1049 tmp
->flags
.semi_focused
= 0;
1051 if (!tmp->flags.shaded)
1053 wClientSetState(tmp
, NormalState
, None
);
1055 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1061 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
1068 /* hackish way to detect transient_for cycle */
1069 i
= wwin
->screen_ptr
->window_count
+ 1;
1071 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1072 wwin
= wWindowFor(wwin
->transient_for
);
1075 if (i
== 0 && wwin
) {
1076 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
1083 void wIconifyWindow(WWindow
* wwin
)
1085 XWindowAttributes attribs
;
1088 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1089 return; /* the window doesn't exist anymore */
1091 if (wwin
->flags
.miniaturized
)
1092 return; /* already miniaturized */
1094 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1095 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1097 if (owner
&& owner
->flags
.miniaturized
)
1101 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1103 /* if the window is in another workspace, simplify process */
1105 /* icon creation may take a while */
1106 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1107 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1108 GrabModeAsync
, None
, None
, CurrentTime
);
1111 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1112 if (!wwin
->flags
.icon_moved
)
1113 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1115 wwin
->icon
= icon_create_for_wwindow(wwin
);
1116 wwin
->icon
->mapped
= 1;
1119 wwin
->flags
.miniaturized
= 1;
1120 wwin
->flags
.mapped
= 0;
1122 /* unmap transients */
1123 unmapTransientsFor(wwin
);
1126 XUngrabPointer(dpy
, CurrentTime
);
1128 /* let all Expose events arrive so that we can repaint
1129 * something before the animation starts (and the server is grabbed) */
1132 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1133 wClientSetState(wwin
, IconicState
, None
);
1135 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1139 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1140 && !wPreferences
.no_animations
) {
1143 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1146 iw
= wwin
->icon
->core
->width
;
1147 ih
= wwin
->icon
->core
->height
;
1149 if (wwin
->flags
.net_handle_icon
) {
1157 iw
= wwin
->screen_ptr
->scr_width
;
1158 ih
= wwin
->screen_ptr
->scr_height
;
1161 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1162 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1167 wwin
->flags
.skip_next_animation
= 0;
1169 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1170 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1171 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1172 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1174 AddToStackList(wwin
->icon
->core
);
1175 wLowerFrame(wwin
->icon
->core
);
1179 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1182 * It doesn't seem to be working and causes button event hangup
1183 * when deiconifying a transient window.
1184 setupIconGrabs(wwin->icon);
1186 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1187 && wPreferences
.focus_mode
== WKF_CLICK
) {
1192 if (!WFLAGP(tmp
, no_focusable
)
1193 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1194 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1198 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1199 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1200 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1203 if (!wwin
->screen_ptr
->flags
.startup
) {
1204 /* Catch up with events not processed while animation was running */
1205 Window clientwin
= wwin
->client_win
;
1207 ProcessPendingEvents();
1209 /* the window can disappear while ProcessPendingEvents() runs */
1210 if (!wWindowFor(clientwin
)) {
1217 /* maybe we want to do this regardless of net_handle_icon
1218 * it seems to me we might break behaviour this way.
1220 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1221 && !wwin
->flags
.net_handle_icon
)
1222 wIconSelect(wwin
->icon
);
1224 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1226 if (wPreferences
.auto_arrange_icons
)
1227 wArrangeIcons(wwin
->screen_ptr
, True
);
1230 void wDeiconifyWindow(WWindow
*wwin
)
1232 /* Let's avoid changing workspace while deiconifying */
1233 ignore_wks_change
= 1;
1235 /* we're hiding for show_desktop */
1236 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1237 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1240 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1242 if (!wwin
->flags
.miniaturized
)
1245 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1246 WWindow
*owner
= recursiveTransientFor(wwin
);
1248 if (owner
&& owner
->flags
.miniaturized
) {
1249 wDeiconifyWindow(owner
);
1250 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1251 wRaiseFrame(wwin
->frame
->core
);
1256 wwin
->flags
.miniaturized
= 0;
1258 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1259 wwin
->flags
.mapped
= 1;
1261 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1262 /* maybe we want to do this regardless of net_handle_icon
1263 * it seems to me we might break behaviour this way.
1265 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1266 && wwin
->icon
!= NULL
) {
1267 if (wwin
->icon
->selected
)
1268 wIconSelect(wwin
->icon
);
1270 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1274 /* if the window is in another workspace, do it silently */
1275 if (!netwm_hidden
) {
1277 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1278 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1281 if (!wPreferences
.disable_miniwindows
1282 && !wwin
->flags
.net_handle_icon
) {
1285 iw
= wwin
->icon
->core
->width
;
1286 ih
= wwin
->icon
->core
->height
;
1288 if (wwin
->flags
.net_handle_icon
) {
1296 iw
= wwin
->screen_ptr
->scr_width
;
1297 ih
= wwin
->screen_ptr
->scr_height
;
1300 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1301 wwin
->frame_x
, wwin
->frame_y
,
1302 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1304 #endif /* ANIMATIONS */
1305 wwin
->flags
.skip_next_animation
= 0;
1307 if (!wwin
->flags
.shaded
)
1308 XMapWindow(dpy
, wwin
->client_win
);
1310 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1311 wRaiseFrame(wwin
->frame
->core
);
1312 if (!wwin
->flags
.shaded
)
1313 wClientSetState(wwin
, NormalState
, None
);
1315 mapTransientsFor(wwin
);
1318 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1319 && !wwin
->flags
.net_handle_icon
) {
1320 RemoveFromStackList(wwin
->icon
->core
);
1321 /* removeIconGrabs(wwin->icon); */
1322 wIconDestroy(wwin
->icon
);
1326 if (!netwm_hidden
) {
1329 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1332 if (!wwin
->screen_ptr
->flags
.startup
) {
1333 /* Catch up with events not processed while animation was running */
1334 Window clientwin
= wwin
->client_win
;
1336 ProcessPendingEvents();
1338 /* the window can disappear while ProcessPendingEvents() runs */
1339 if (!wWindowFor(clientwin
))
1345 if (wPreferences
.auto_arrange_icons
)
1346 wArrangeIcons(wwin
->screen_ptr
, True
);
1348 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1350 /* In case we were shaded and iconified, also unshade */
1352 wUnshadeWindow(wwin
);
1354 ignore_wks_change
= 0;
1357 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1359 if (wwin
->flags
.miniaturized
) {
1361 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1362 wwin
->icon
->mapped
= 0;
1364 wwin
->flags
.hidden
= 1;
1366 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1370 if (wwin
->flags
.inspector_open
) {
1371 wHideInspectorForWindow(wwin
);
1374 wwin
->flags
.hidden
= 1;
1377 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1381 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1382 !wwin
->flags
.skip_next_animation
&& animate
) {
1383 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1384 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1385 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1388 wwin
->flags
.skip_next_animation
= 0;
1390 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1393 void wHideAll(WScreen
*scr
)
1398 unsigned int wcount
= 0;
1404 menu
= scr
->switch_menu
;
1406 windows
= wmalloc(sizeof(WWindow
*));
1409 for (i
= 0; i
< menu
->entry_no
; i
++) {
1410 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1412 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1415 wwin
= scr
->focused_window
;
1418 windows
[wcount
] = wwin
;
1420 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1426 for (i
= 0; i
< wcount
; i
++) {
1428 if (wwin
->frame
->workspace
== scr
->current_workspace
1429 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1430 && !wwin
->flags
.internal_window
1431 && !WFLAGP(wwin
, no_miniaturizable
)
1433 wwin
->flags
.skip_next_animation
= 1;
1434 wIconifyWindow(wwin
);
1441 void wHideOtherApplications(WWindow
*awin
)
1448 wwin
= awin
->screen_ptr
->focused_window
;
1452 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1453 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1454 && !wwin
->flags
.internal_window
1455 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1457 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1458 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1459 wwin
->flags
.skip_next_animation
= 1;
1460 wIconifyWindow(wwin
);
1462 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1463 tapp
= wApplicationOf(wwin
->main_window
);
1465 tapp
->flags
.skip_next_animation
= 1;
1466 wHideApplication(tapp
);
1468 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1469 wwin
->flags
.skip_next_animation
= 1;
1470 wIconifyWindow(wwin
);
1478 wSetFocusTo(awin->screen_ptr, awin);
1482 void wHideApplication(WApplication
*wapp
)
1490 wwarning("trying to hide a non grouped window");
1493 if (!wapp
->main_window_desc
) {
1494 wwarning("group leader not found for window group");
1497 scr
= wapp
->main_window_desc
->screen_ptr
;
1499 wlist
= scr
->focused_window
;
1503 if (wlist
->main_window
== wapp
->main_window
)
1504 wapp
->last_focused
= wlist
;
1506 wapp
->last_focused
= NULL
;
1508 animate
= !wapp
->flags
.skip_next_animation
;
1511 if (wlist
->main_window
== wapp
->main_window
) {
1512 if (wlist
->flags
.focused
) {
1515 if (wapp
->app_icon
) {
1516 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1517 wapp
->app_icon
->y_pos
, wlist
, animate
);
1521 wlist
= wlist
->prev
;
1524 wapp
->flags
.skip_next_animation
= 0;
1527 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1528 wlist
= scr
->focused_window
;
1530 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1531 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1533 wlist
= wlist
->prev
;
1535 wSetFocusTo(scr
, wlist
);
1537 wSetFocusTo(scr
, NULL
);
1541 wapp
->flags
.hidden
= 1;
1543 if (wPreferences
.auto_arrange_icons
)
1544 wArrangeIcons(scr
, True
);
1548 wAppIconPaint(wapp
->app_icon
);
1552 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1554 if (bringToCurrentWS
)
1555 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1557 wwin
->flags
.hidden
= 0;
1560 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1561 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1562 icon
->core
->width
, icon
->core
->height
,
1563 wwin
->frame_x
, wwin
->frame_y
,
1564 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1567 wwin
->flags
.skip_next_animation
= 0;
1568 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1569 XMapWindow(dpy
, wwin
->client_win
);
1570 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1571 wClientSetState(wwin
, NormalState
, None
);
1572 wwin
->flags
.mapped
= 1;
1573 wRaiseFrame(wwin
->frame
->core
);
1575 if (wwin
->flags
.inspector_open
) {
1576 wUnhideInspectorForWindow(wwin
);
1579 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1582 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1585 WWindow
*wlist
, *next
;
1586 WWindow
*focused
= NULL
;
1592 scr
= wapp
->main_window_desc
->screen_ptr
;
1593 wlist
= scr
->focused_window
;
1597 /* goto beginning of list */
1599 wlist
= wlist
->prev
;
1601 animate
= !wapp
->flags
.skip_next_animation
;
1606 if (wlist
->main_window
== wapp
->main_window
) {
1607 if (wlist
->flags
.focused
)
1609 else if (!focused
|| !focused
->flags
.focused
)
1612 if (wlist
->flags
.miniaturized
) {
1613 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1614 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1615 if (!wlist
->icon
->mapped
) {
1618 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1619 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1620 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1624 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1625 wlist
->icon
->mapped
= 1;
1627 wRaiseFrame(wlist
->icon
->core
);
1629 if (bringToCurrentWS
)
1630 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1631 wlist
->flags
.hidden
= 0;
1632 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1633 wDeiconifyWindow(wlist
);
1635 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1636 } else if (wlist
->flags
.shaded
) {
1637 if (bringToCurrentWS
)
1638 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1639 wlist
->flags
.hidden
= 0;
1640 wRaiseFrame(wlist
->frame
->core
);
1641 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1642 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1644 wUnshadeWindow(wlist
);
1647 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1648 } else if (wlist
->flags
.hidden
) {
1649 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1650 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1653 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1654 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1656 wRaiseFrame(wlist
->frame
->core
);
1662 wapp
->flags
.skip_next_animation
= 0;
1663 wapp
->flags
.hidden
= 0;
1665 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1666 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1667 wSetFocusTo(scr
, wapp
->last_focused
);
1668 } else if (focused
) {
1669 wSetFocusTo(scr
, focused
);
1671 wapp
->last_focused
= NULL
;
1672 if (wPreferences
.auto_arrange_icons
)
1673 wArrangeIcons(scr
, True
);
1676 wAppIconPaint(wapp
->app_icon
);
1680 void wShowAllWindows(WScreen
*scr
)
1682 WWindow
*wwin
, *old_foc
;
1685 old_foc
= wwin
= scr
->focused_window
;
1687 if (!wwin
->flags
.internal_window
&&
1688 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1689 if (wwin
->flags
.miniaturized
) {
1690 wwin
->flags
.skip_next_animation
= 1;
1691 wDeiconifyWindow(wwin
);
1692 } else if (wwin
->flags
.hidden
) {
1693 wapp
= wApplicationOf(wwin
->main_window
);
1695 wUnhideApplication(wapp
, False
, False
);
1697 wwin
->flags
.skip_next_animation
= 1;
1698 wDeiconifyWindow(wwin
);
1704 wSetFocusTo(scr
, old_foc
);
1705 /*wRaiseFrame(old_foc->frame->core); */
1708 void wRefreshDesktop(WScreen
*scr
)
1711 XSetWindowAttributes attr
;
1713 attr
.backing_store
= NotUseful
;
1714 attr
.save_under
= False
;
1715 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1716 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1717 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1718 XMapRaised(dpy
, win
);
1719 XDestroyWindow(dpy
, win
);
1723 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1729 const int heads
= wXineramaHeads(scr
);
1732 int pf
; /* primary axis */
1733 int sf
; /* secondary axis */
1737 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1743 int isize
= wPreferences
.icon_size
;
1745 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1747 for (head
= 0; head
< heads
; ++head
) {
1748 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1749 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1750 vars
[head
].pi
= vars
[head
].si
= 0;
1751 vars
[head
].sx1
= rect
.pos
.x
;
1752 vars
[head
].sy1
= rect
.pos
.y
;
1753 vars
[head
].sw
= rect
.size
.width
;
1754 vars
[head
].sh
= rect
.size
.height
;
1755 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1756 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1757 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1758 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1759 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1760 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1762 /* icon yard boundaries */
1763 if (wPreferences
.icon_yard
& IY_VERT
) {
1764 vars
[head
].pf
= vars
[head
].fullH
;
1765 vars
[head
].sf
= vars
[head
].fullW
;
1767 vars
[head
].pf
= vars
[head
].fullW
;
1768 vars
[head
].sf
= vars
[head
].fullH
;
1770 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1771 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1774 vars
[head
].xo
= vars
[head
].sx1
;
1777 if (wPreferences
.icon_yard
& IY_TOP
) {
1778 vars
[head
].yo
= vars
[head
].sy1
;
1781 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1786 #define X ((wPreferences.icon_yard & IY_VERT) \
1787 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1788 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1790 #define Y ((wPreferences.icon_yard & IY_VERT) \
1791 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1792 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1794 /* arrange application icons */
1795 aicon
= scr
->app_icon_list
;
1796 /* reverse them to avoid unnecessarily sliding of icons */
1797 while (aicon
&& aicon
->next
)
1798 aicon
= aicon
->next
;
1801 if (!aicon
->docked
) {
1802 /* CHECK: can icon be NULL here ? */
1803 /* The intention here is to place the AppIcon on the head that
1804 * contains most of the applications _main_ window. */
1805 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1807 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1809 if (!wPreferences
.no_animations
)
1810 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1811 #endif /* ANIMATIONS */
1813 wAppIconMove(aicon
, X
, Y
);
1815 if (vars
[head
].pi
>= vars
[head
].pf
) {
1820 aicon
= aicon
->prev
;
1823 /* arrange miniwindows */
1824 wwin
= scr
->focused_window
;
1825 /* reverse them to avoid unnecessarily shuffling */
1826 while (wwin
&& wwin
->prev
)
1830 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1831 (wwin
->frame
->workspace
== scr
->current_workspace
||
1832 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1834 head
= wGetHeadForWindow(wwin
);
1836 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1837 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1838 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1844 if (vars
[head
].pi
>= vars
[head
].pf
) {
1851 wwin
->flags
.icon_moved
= 0;
1853 /* we reversed the order, so we use next */
1860 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1862 WScreen
*scr
= wwin
->screen_ptr
;
1865 wwin
->flags
.selected
= 1;
1866 if (wwin
->frame
->selected_border_pixel
)
1867 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1869 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1871 if (!HAS_BORDER(wwin
)) {
1872 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1875 if (!scr
->selected_windows
)
1876 scr
->selected_windows
= WMCreateArray(4);
1877 WMAddToArray(scr
->selected_windows
, wwin
);
1879 wwin
->flags
.selected
= 0;
1880 if (wwin
->frame
->border_pixel
)
1881 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1883 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1885 if (!HAS_BORDER(wwin
)) {
1886 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1889 if (scr
->selected_windows
) {
1890 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1895 void wMakeWindowVisible(WWindow
*wwin
)
1897 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1898 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1900 if (wwin
->flags
.shaded
) {
1901 wUnshadeWindow(wwin
);
1903 if (wwin
->flags
.hidden
) {
1906 app
= wApplicationOf(wwin
->main_window
);
1908 /* trick to get focus to this window */
1909 app
->last_focused
= wwin
;
1910 wUnhideApplication(app
, False
, False
);
1913 if (wwin
->flags
.miniaturized
) {
1914 wDeiconifyWindow(wwin
);
1916 if (!WFLAGP(wwin
, no_focusable
))
1917 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1918 wRaiseFrame(wwin
->frame
->core
);
1923 * Do the animation while shading (called with what = SHADE)
1924 * or unshading (what = UNSHADE).
1927 static void shade_animate(WWindow
*wwin
, Bool what
)
1930 time_t time0
= time(NULL
);
1932 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1937 if (!wwin
->screen_ptr
->flags
.startup
) {
1938 /* do the shading animation */
1939 h
= wwin
->frame
->core
->height
;
1940 s
= h
/ SHADE_STEPS
;
1943 w
= wwin
->frame
->core
->width
;
1944 y
= wwin
->frame
->top_width
;
1945 while (h
> wwin
->frame
->top_width
+ 1) {
1946 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1947 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1950 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1953 if (SHADE_DELAY
> 0) {
1954 wusleep(SHADE_DELAY
* 1000L);
1961 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1966 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1967 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1968 s
= abs(y
) / SHADE_STEPS
;
1971 w
= wwin
->frame
->core
->width
;
1972 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1974 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1975 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1976 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1978 if (SHADE_DELAY
> 0) {
1979 wusleep(SHADE_DELAY
* 2000L / 3);
1986 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1990 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);