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"
49 #include "placement.h"
53 /****** Global Variables ******/
55 int ignore_wks_change
= 0;
57 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
58 unsigned int *new_width
, unsigned int *new_height
);
59 static void save_old_geometry(WWindow
*wwin
, int directions
);
61 /******* Local Variables *******/
67 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
68 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
69 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
70 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
71 SHADE_STEPS_US
, SHADE_DELAY_US
}};
75 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
76 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
78 static int compareTimes(Time t1
, Time t2
)
84 return (diff
< 60000) ? 1 : -1;
88 static void shade_animate(WWindow
*wwin
, Bool what
);
90 static void shade_animate(WWindow
*wwin
, Bool what
) { }
94 *----------------------------------------------------------------------
96 * Changes the window focus to the one passed as argument.
97 * If the window to focus is not already focused, it will be brought
98 * to the head of the list of windows. Previously focused window is
102 * Window list may be reordered and the window focus is changed.
104 *----------------------------------------------------------------------
106 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
108 static WScreen
*old_scr
= NULL
;
110 WWindow
*old_focused
;
111 WWindow
*focused
= scr
->focused_window
;
112 Time timestamp
= w_global
.timestamp
.last_event
;
113 WApplication
*oapp
= NULL
, *napp
= NULL
;
116 if (scr
->flags
.ignore_focus_events
|| compareTimes(w_global
.timestamp
.focus_change
, timestamp
) > 0)
122 old_focused
= old_scr
->focused_window
;
124 w_global
.timestamp
.focus_change
= timestamp
;
127 oapp
= wApplicationOf(old_focused
->main_window
);
130 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
132 wWindowUnfocus(old_focused
);
135 wAppMenuUnmap(oapp
->menu
);
136 if (wPreferences
.highlight_active_app
)
137 wApplicationDeactivate(oapp
);
140 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
144 if (old_scr
!= scr
&& old_focused
)
145 wWindowUnfocus(old_focused
);
147 wasfocused
= wwin
->flags
.focused
;
148 napp
= wApplicationOf(wwin
->main_window
);
150 /* remember last workspace where the app has been */
152 napp
->last_workspace
= wwin
->frame
->workspace
;
154 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
155 /* install colormap if colormap mode is lock mode */
156 if (wPreferences
.colormap_mode
== WCM_CLICK
)
157 wColormapInstallForWindow(scr
, wwin
);
159 /* set input focus */
160 switch (wwin
->focus_mode
) {
162 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
165 case WFM_LOCALLY_ACTIVE
:
166 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
168 case WFM_GLOBALLY_ACTIVE
:
173 if (wwin
->protocols
.TAKE_FOCUS
)
174 wClientSendProtocol(wwin
, w_global
.atom
.wm
.take_focus
, timestamp
);
178 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
181 if (WFLAGP(wwin
, no_focusable
))
184 /* if this is not the focused window focus it */
185 if (focused
!= wwin
) {
186 /* change the focus window list order */
188 wwin
->prev
->next
= wwin
->next
;
191 wwin
->next
->prev
= wwin
->prev
;
193 wwin
->prev
= focused
;
194 focused
->next
= wwin
;
196 scr
->focused_window
= wwin
;
198 if (oapp
&& oapp
!= napp
) {
199 wAppMenuUnmap(oapp
->menu
);
200 if (wPreferences
.highlight_active_app
)
201 wApplicationDeactivate(oapp
);
205 wWindowFocus(wwin
, focused
);
207 if (napp
&& !wasfocused
) {
209 wUserMenuRefreshInstances(napp
->menu
, wwin
);
210 #endif /* USER_MENU */
212 if (wwin
->flags
.mapped
)
213 wAppMenuMap(napp
->menu
, wwin
);
215 if (napp
&& wPreferences
.highlight_active_app
)
216 wApplicationActivate(napp
);
222 void wShadeWindow(WWindow
*wwin
)
225 if (wwin
->flags
.shaded
)
228 XLowerWindow(dpy
, wwin
->client_win
);
229 shade_animate(wwin
, SHADE
);
231 wwin
->flags
.skip_next_animation
= 0;
232 wwin
->flags
.shaded
= 1;
233 wwin
->flags
.mapped
= 0;
234 /* prevent window withdrawal when getting UnmapNotify */
235 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
236 XUnmapWindow(dpy
, wwin
->client_win
);
237 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
239 /* for the client it's just like iconification */
240 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
242 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
243 wWindowSynthConfigureNotify(wwin
);
246 wClientSetState(wwin, IconicState, None);
249 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
252 if (!wwin
->screen_ptr
->flags
.startup
) {
253 /* Catch up with events not processed while animation was running */
254 ProcessPendingEvents();
259 void wUnshadeWindow(WWindow
*wwin
)
262 if (!wwin
->flags
.shaded
)
265 wwin
->flags
.shaded
= 0;
266 wwin
->flags
.mapped
= 1;
267 XMapWindow(dpy
, wwin
->client_win
);
269 shade_animate(wwin
, UNSHADE
);
271 wwin
->flags
.skip_next_animation
= 0;
272 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
273 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
275 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
276 wWindowSynthConfigureNotify(wwin
);
278 /* if the window is focused, set the focus again as it was disabled during
280 if (wwin
->flags
.focused
)
281 wSetFocusTo(wwin
->screen_ptr
, wwin
);
283 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
286 /* Set the old coordinates using the current values */
287 static void save_old_geometry(WWindow
*wwin
, int directions
)
289 /* never been saved? */
290 if (! wwin
->old_geometry
.width
)
291 directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
292 if (! wwin
->old_geometry
.height
)
293 directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
295 if (directions
& SAVE_GEOMETRY_X
)
296 wwin
->old_geometry
.x
= wwin
->frame_x
;
297 if (directions
& SAVE_GEOMETRY_Y
)
298 wwin
->old_geometry
.y
= wwin
->frame_y
;
299 if (directions
& SAVE_GEOMETRY_WIDTH
)
300 wwin
->old_geometry
.width
= wwin
->client
.width
;
301 if (directions
& SAVE_GEOMETRY_HEIGHT
)
302 wwin
->old_geometry
.height
= wwin
->client
.height
;
305 static void remember_geometry(WWindow
*wwin
, int *x
, int *y
, int *w
, int *h
)
307 WMRect old_geom_rect
;
311 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
312 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
313 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
314 *x
= ((wwin
->old_geometry
.x
|| wwin
->old_geometry
.width
) && same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
315 *y
= ((wwin
->old_geometry
.y
|| wwin
->old_geometry
.height
) && same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
316 *w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
317 *h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
320 /* Remember geometry for unmaximizing */
321 void update_saved_geometry(WWindow
*wwin
)
323 /* NOT if we aren't already maximized
324 * we'll save geometry when maximizing */
325 if (!wwin
->flags
.maximized
)
328 /* NOT if we are fully maximized */
329 if ((wwin
->flags
.maximized
& MAX_MAXIMUS
) ||
330 ((wwin
->flags
.maximized
& MAX_HORIZONTAL
) &&
331 (wwin
->flags
.maximized
& MAX_VERTICAL
)))
334 /* save the co-ordinate in the axis in which we AREN'T maximized */
335 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
336 save_old_geometry(wwin
, SAVE_GEOMETRY_Y
);
337 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
338 save_old_geometry(wwin
, SAVE_GEOMETRY_X
);
341 void wMaximizeWindow(WWindow
*wwin
, int directions
)
343 unsigned int new_width
, new_height
, half_scr_width
, half_scr_height
;
348 unsigned int maximus_width
= 0;
349 unsigned int maximus_height
= 0;
350 WArea usableArea
, totalArea
;
354 if (!IS_RESIZABLE(wwin
))
357 if (!HAS_BORDER(wwin
))
360 /* the size to adjust the geometry */
361 adj_size
= wwin
->screen_ptr
->frame_border_width
* 2 * has_border
;
363 /* save old coordinates before we change the current values */
364 if (!wwin
->flags
.maximized
)
365 save_old_geometry(wwin
, SAVE_GEOMETRY_ALL
);
367 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
368 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
371 usableArea
= totalArea
;
373 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
374 WScreen
*scr
= wwin
->screen_ptr
;
377 if (directions
& MAX_KEYBOARD
)
378 head
= wGetHeadForWindow(wwin
);
380 head
= wGetHeadForPointerLocation(scr
);
382 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
385 /* Only save directions, not kbd or xinerama hints */
386 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
388 if (WFLAGP(wwin
, full_maximize
)) {
389 usableArea
= totalArea
;
391 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
392 half_scr_height
= (usableArea
.y2
- usableArea
.y1
)/2;
394 if (wwin
->flags
.shaded
) {
395 wwin
->flags
.skip_next_animation
= 1;
396 wUnshadeWindow(wwin
);
399 if (directions
& MAX_MAXIMUS
) {
400 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
401 new_width
= maximus_width
- adj_size
;
402 new_height
= maximus_height
- adj_size
;
405 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0)) {
406 new_height
+= wwin
->frame
->bottom_width
- 1;
407 new_y
-= wwin
->frame
->top_width
;
410 wwin
->maximus_x
= new_x
;
411 wwin
->maximus_y
= new_y
;
412 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
414 /* set default values if no option set then */
415 if (!(directions
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
))) {
416 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
417 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
419 if (!(directions
& (MAX_VERTICAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
))) {
420 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
421 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
424 /* left|right position */
425 if (directions
& MAX_LEFTHALF
) {
426 new_width
= half_scr_width
- adj_size
;
427 new_x
= usableArea
.x1
;
428 } else if (directions
& MAX_RIGHTHALF
) {
429 new_width
= half_scr_width
- adj_size
;
430 new_x
= usableArea
.x1
+ half_scr_width
;
432 /* top|bottom position */
433 if (directions
& MAX_TOPHALF
) {
434 new_height
= half_scr_height
- adj_size
;
435 new_y
= usableArea
.y1
;
436 } else if (directions
& MAX_BOTTOMHALF
) {
437 new_height
= half_scr_height
- adj_size
;
438 new_y
= usableArea
.y1
+ half_scr_height
;
441 /* vertical|horizontal position */
442 if (directions
& MAX_HORIZONTAL
) {
443 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
444 new_x
= usableArea
.x1
;
446 if (directions
& MAX_VERTICAL
) {
447 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
448 new_y
= usableArea
.y1
;
449 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0))
450 new_y
-= wwin
->frame
->top_width
;
454 if (!WFLAGP(wwin
, full_maximize
) && !(directions
== MAX_MAXIMUS
|| directions
== MAX_HORIZONTAL
))
455 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
457 /* set maximization state */
458 wwin
->flags
.maximized
= directions
;
459 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
460 wwin
->flags
.maximized
= MAX_MAXIMUS
;
462 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
464 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
465 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
467 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
468 wWindowSynthConfigureNotify(wwin
);
470 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
473 /* generic (un)maximizer */
474 void handleMaximize(WWindow
*wwin
, int directions
)
476 int current
= wwin
->flags
.maximized
;
477 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
478 int effective
= requested
^ current
;
479 int flags
= directions
& ~requested
;
482 /* allow wMaximizeWindow to restore the Maximusized size */
483 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
484 !(requested
& MAX_MAXIMUS
))
485 wMaximizeWindow(wwin
, MAX_MAXIMUS
| flags
);
487 wUnmaximizeWindow(wwin
);
488 /* these alone mean vertical|horizontal toggle */
489 } else if ((effective
== MAX_LEFTHALF
) ||
490 (effective
== MAX_RIGHTHALF
) ||
491 (effective
== MAX_TOPHALF
) ||
492 (effective
== MAX_BOTTOMHALF
))
493 wUnmaximizeWindow(wwin
);
495 if ((requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
)) ||
496 (requested
== MAX_MAXIMUS
))
497 effective
= requested
;
499 if (requested
& MAX_LEFTHALF
) {
500 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
501 effective
|= MAX_VERTICAL
;
503 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
504 effective
|= MAX_LEFTHALF
;
505 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
506 } else if (requested
& MAX_RIGHTHALF
) {
507 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
508 effective
|= MAX_VERTICAL
;
510 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
511 effective
|= MAX_RIGHTHALF
;
512 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
514 if (requested
& MAX_TOPHALF
) {
515 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
516 effective
|= MAX_HORIZONTAL
;
518 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
519 effective
|= MAX_TOPHALF
;
520 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
521 } else if (requested
& MAX_BOTTOMHALF
) {
522 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
523 effective
|= MAX_HORIZONTAL
;
525 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
526 effective
|= MAX_BOTTOMHALF
;
527 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
529 if (requested
& MAX_HORIZONTAL
)
530 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
531 if (requested
& MAX_VERTICAL
)
532 effective
&= ~(MAX_TOPHALF
| MAX_BOTTOMHALF
);
533 effective
&= ~MAX_MAXIMUS
;
535 wMaximizeWindow(wwin
, effective
| flags
);
539 /* the window boundary coordinates */
549 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
551 obs
->left
= wwin
->frame_x
;
552 obs
->top
= wwin
->frame_y
;
553 obs
->width
= wwin
->frame
->core
->width
;
554 obs
->height
= wwin
->frame
->core
->height
;
555 obs
->bottom
= obs
->top
+ obs
->height
;
556 obs
->right
= obs
->left
+ obs
->width
;
560 * Maximus: tiled maximization (maximize without overlapping other windows)
562 * The original window 'orig' will be maximized to new coordinates 'new'.
563 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
565 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
566 unsigned int *new_width
, unsigned int *new_height
)
569 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
570 short int adjust_height
;
571 int x_intsect
, y_intsect
;
572 /* the obstructing, original and new windows */
573 win_coords obs
, orig
, new;
575 /* set the original coordinate positions of the window to be Maximumized */
576 if (wwin
->flags
.maximized
) {
577 /* window is already maximized; consider original geometry */
578 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
579 orig
.bottom
= orig
.top
+ orig
.height
;
580 orig
.right
= orig
.left
+ orig
.width
;
583 set_window_coords(wwin
, &orig
);
585 /* Try to fully maximize first, then readjust later */
586 new.left
= usableArea
.x1
;
587 new.right
= usableArea
.x2
;
588 new.top
= usableArea
.y1
;
589 new.bottom
= usableArea
.y2
;
591 if (HAS_TITLEBAR(wwin
))
592 tbar_height_0
= TITLEBAR_HEIGHT
;
593 if (HAS_RESIZEBAR(wwin
))
594 rbar_height_0
= RESIZEBAR_HEIGHT
;
595 if (HAS_BORDER(wwin
))
596 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
598 /* the length to be subtracted if the window has titlebar, etc */
599 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
602 /* The focused window is always the last in the list */
604 /* ignore windows in other workspaces etc */
605 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
606 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
612 /* Set the coordinates of obstructing window */
613 set_window_coords(tmp
, &obs
);
615 /* Try to maximize in the y direction first */
616 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
617 if (x_intsect
!= 0) {
618 /* TODO: Consider the case when coords are equal */
619 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
620 /* w_0 is below the bottom of w_j */
621 new.top
= obs
.bottom
+ 1;
623 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
624 /* The bottom of w_0 is above the top of w_j */
625 new.bottom
= obs
.top
- 1;
632 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
633 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
639 set_window_coords(tmp
, &obs
);
642 * Use the new.top and new.height instead of original values
643 * as they may have different intersections with the obstructing windows
645 new.height
= new.bottom
- new.top
- adjust_height
;
646 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
647 if (y_intsect
!= 0) {
648 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
649 /* w_0 is completely to the right of w_j */
650 new.left
= obs
.right
+ 1;
652 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
653 /* w_0 is completely to the left of w_j */
654 new.right
= obs
.left
- 1;
661 /* xcalc needs -7 here, but other apps don't */
662 *new_height
= new.bottom
- new.top
- adjust_height
- 1;;
663 *new_width
= new.right
- new.left
;
666 void wUnmaximizeWindow(WWindow
*wwin
)
670 if (!wwin
->flags
.maximized
)
673 if (wwin
->flags
.shaded
) {
674 wwin
->flags
.skip_next_animation
= 1;
675 wUnshadeWindow(wwin
);
678 /* Use old coordinates if they are set, current values otherwise */
679 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
681 /* unMaximusize relative to original position */
682 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
683 x
+= wwin
->frame_x
- wwin
->maximus_x
;
684 y
+= wwin
->frame_y
- wwin
->maximus_y
;
687 wwin
->flags
.maximized
= 0;
688 wwin
->flags
.old_maximized
= 0;
689 wWindowConfigure(wwin
, x
, y
, w
, h
);
690 wWindowSynthConfigureNotify(wwin
);
692 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
695 void wFullscreenWindow(WWindow
*wwin
)
700 if (wwin
->flags
.fullscreen
)
703 wwin
->flags
.fullscreen
= True
;
705 wWindowConfigureBorders(wwin
);
707 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
709 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
710 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
711 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
712 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
714 head
= wGetHeadForWindow(wwin
);
715 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
716 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
718 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
721 void wUnfullscreenWindow(WWindow
*wwin
)
723 if (!wwin
->flags
.fullscreen
)
726 wwin
->flags
.fullscreen
= False
;
728 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
729 if (WFLAGP(wwin
, sunken
)) {
730 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
731 } else if (WFLAGP(wwin
, floating
)) {
732 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
734 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
738 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
739 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
741 wWindowConfigureBorders(wwin
);
743 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
744 wFrameWindowPaint(wwin->frame);
747 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
751 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
753 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
754 float cx
, cy
, cw
, ch
;
755 float xstep
, ystep
, wstep
, hstep
;
758 float angle
, final_angle
, delta
;
760 xstep
= (float)(fx
- x
) / steps
;
761 ystep
= (float)(fy
- y
) / steps
;
762 wstep
= (float)(fw
- w
) / steps
;
763 hstep
= (float)(fh
- h
) / steps
;
770 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
771 delta
= (float)(final_angle
/ FRAMES
);
772 for (angle
= 0;; angle
+= delta
) {
773 if (angle
> final_angle
)
776 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
777 dch
= (ch
/ 2) * cos(angle
);
778 midy
= cy
+ (ch
/ 2);
780 points
[0].x
= cx
+ dx
;
781 points
[0].y
= midy
- dch
;
782 points
[1].x
= cx
+ cw
- dx
;
783 points
[1].y
= points
[0].y
;
784 points
[2].x
= cx
+ cw
+ dx
;
785 points
[2].y
= midy
+ dch
;
786 points
[3].x
= cx
- dx
;
787 points
[3].y
= points
[2].y
;
788 points
[4].x
= points
[0].x
;
789 points
[4].y
= points
[0].y
;
792 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
794 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
796 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
802 if (angle
>= final_angle
)
812 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
814 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
815 float cx
, cy
, cw
, ch
;
816 float xstep
, ystep
, wstep
, hstep
;
818 float angle
, final_angle
, a
, d
, delta
;
825 xstep
= (float)(fx
- x
) / steps
;
826 ystep
= (float)(fy
- y
) / steps
;
827 wstep
= (float)(fw
- w
) / steps
;
828 hstep
= (float)(fh
- h
) / steps
;
835 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
836 delta
= (float)(final_angle
/ FRAMES
);
837 for (angle
= 0;; angle
+= delta
) {
838 if (angle
> final_angle
)
842 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
844 points
[0].x
= cx
+ cos(angle
- a
) * d
;
845 points
[0].y
= cy
+ sin(angle
- a
) * d
;
846 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
847 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
848 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
849 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
850 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
851 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
852 points
[4].x
= cx
+ cos(angle
- a
) * d
;
853 points
[4].y
= cy
+ sin(angle
- a
) * d
;
855 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
857 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
859 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
865 if (angle
>= final_angle
)
874 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
876 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
877 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
878 float xstep
, ystep
, wstep
, hstep
;
881 xstep
= (float)(fx
- x
) / steps
;
882 ystep
= (float)(fy
- y
) / steps
;
883 wstep
= (float)(fw
- w
) / steps
;
884 hstep
= (float)(fh
- h
) / steps
;
886 for (j
= 0; j
< FRAMES
; j
++) {
893 for (i
= 0; i
< steps
; i
++) {
894 for (j
= 0; j
< FRAMES
; j
++) {
895 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
896 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
899 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
901 for (j
= 0; j
< FRAMES
; j
++) {
902 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
903 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
904 if (j
< FRAMES
- 1) {
918 for (j
= 0; j
< FRAMES
; j
++) {
919 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
922 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
924 for (j
= 0; j
< FRAMES
; j
++) {
925 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
933 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
935 int style
= wPreferences
.iconification_style
; /* Catch the value */
938 if (style
== WIS_NONE
)
941 if (style
== WIS_RANDOM
) {
947 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
949 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
952 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
954 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
958 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
960 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
964 #endif /* ANIMATIONS */
966 static void flushExpose(void)
970 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
971 WMHandleEvent(&tmpev
);
975 static void unmapTransientsFor(WWindow
*wwin
)
979 tmp
= wwin
->screen_ptr
->focused_window
;
981 /* unmap the transients for this transient */
982 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
983 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
984 unmapTransientsFor(tmp
);
985 tmp
->flags
.miniaturized
= 1;
986 if (!tmp
->flags
.shaded
) {
989 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
992 if (!tmp->flags.shaded)
994 wClientSetState(tmp
, IconicState
, None
);
996 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1002 static void mapTransientsFor(WWindow
*wwin
)
1006 tmp
= wwin
->screen_ptr
->focused_window
;
1008 /* recursively map the transients for this transient */
1009 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1010 && tmp
->icon
== NULL
) {
1011 mapTransientsFor(tmp
);
1012 tmp
->flags
.miniaturized
= 0;
1013 if (!tmp
->flags
.shaded
) {
1016 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1018 tmp
->flags
.semi_focused
= 0;
1020 if (!tmp->flags.shaded)
1022 wClientSetState(tmp
, NormalState
, None
);
1024 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1030 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
1037 /* hackish way to detect transient_for cycle */
1038 i
= wwin
->screen_ptr
->window_count
+ 1;
1040 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1041 wwin
= wWindowFor(wwin
->transient_for
);
1044 if (i
== 0 && wwin
) {
1045 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
1052 void wIconifyWindow(WWindow
* wwin
)
1054 XWindowAttributes attribs
;
1057 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1058 return; /* the window doesn't exist anymore */
1060 if (wwin
->flags
.miniaturized
)
1061 return; /* already miniaturized */
1063 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1064 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1066 if (owner
&& owner
->flags
.miniaturized
)
1070 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1072 /* if the window is in another workspace, simplify process */
1074 /* icon creation may take a while */
1075 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1076 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1077 GrabModeAsync
, None
, None
, CurrentTime
);
1080 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1081 if (!wwin
->flags
.icon_moved
)
1082 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1084 wwin
->icon
= icon_create_for_wwindow(wwin
);
1085 wwin
->icon
->mapped
= 1;
1088 wwin
->flags
.miniaturized
= 1;
1089 wwin
->flags
.mapped
= 0;
1091 /* unmap transients */
1092 unmapTransientsFor(wwin
);
1095 XUngrabPointer(dpy
, CurrentTime
);
1097 /* let all Expose events arrive so that we can repaint
1098 * something before the animation starts (and the server is grabbed) */
1101 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1102 wClientSetState(wwin
, IconicState
, None
);
1104 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1108 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1109 && !wPreferences
.no_animations
) {
1112 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1115 iw
= wwin
->icon
->core
->width
;
1116 ih
= wwin
->icon
->core
->height
;
1118 if (wwin
->flags
.net_handle_icon
) {
1126 iw
= wwin
->screen_ptr
->scr_width
;
1127 ih
= wwin
->screen_ptr
->scr_height
;
1130 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1131 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1136 wwin
->flags
.skip_next_animation
= 0;
1138 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1139 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1140 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1141 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1143 AddToStackList(wwin
->icon
->core
);
1144 wLowerFrame(wwin
->icon
->core
);
1148 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1151 * It doesn't seem to be working and causes button event hangup
1152 * when deiconifying a transient window.
1153 setupIconGrabs(wwin->icon);
1155 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1156 && wPreferences
.focus_mode
== WKF_CLICK
) {
1161 if (!WFLAGP(tmp
, no_focusable
)
1162 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1163 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1167 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1168 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1169 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1172 if (!wwin
->screen_ptr
->flags
.startup
) {
1173 /* Catch up with events not processed while animation was running */
1174 Window clientwin
= wwin
->client_win
;
1176 ProcessPendingEvents();
1178 /* the window can disappear while ProcessPendingEvents() runs */
1179 if (!wWindowFor(clientwin
)) {
1186 /* maybe we want to do this regardless of net_handle_icon
1187 * it seems to me we might break behaviour this way.
1189 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1190 && !wwin
->flags
.net_handle_icon
)
1191 wIconSelect(wwin
->icon
);
1193 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1195 if (wPreferences
.auto_arrange_icons
)
1196 wArrangeIcons(wwin
->screen_ptr
, True
);
1199 void wDeiconifyWindow(WWindow
*wwin
)
1201 /* Let's avoid changing workspace while deiconifying */
1202 ignore_wks_change
= 1;
1204 /* we're hiding for show_desktop */
1205 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1206 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1209 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1211 if (!wwin
->flags
.miniaturized
) {
1212 ignore_wks_change
= 0;
1216 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1217 WWindow
*owner
= recursiveTransientFor(wwin
);
1219 if (owner
&& owner
->flags
.miniaturized
) {
1220 wDeiconifyWindow(owner
);
1221 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1222 wRaiseFrame(wwin
->frame
->core
);
1223 ignore_wks_change
= 0;
1228 wwin
->flags
.miniaturized
= 0;
1230 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1231 wwin
->flags
.mapped
= 1;
1233 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1234 /* maybe we want to do this regardless of net_handle_icon
1235 * it seems to me we might break behaviour this way.
1237 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1238 && wwin
->icon
!= NULL
) {
1239 if (wwin
->icon
->selected
)
1240 wIconSelect(wwin
->icon
);
1242 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1246 /* if the window is in another workspace, do it silently */
1247 if (!netwm_hidden
) {
1249 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1250 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1253 if (!wPreferences
.disable_miniwindows
1254 && !wwin
->flags
.net_handle_icon
) {
1257 iw
= wwin
->icon
->core
->width
;
1258 ih
= wwin
->icon
->core
->height
;
1260 if (wwin
->flags
.net_handle_icon
) {
1268 iw
= wwin
->screen_ptr
->scr_width
;
1269 ih
= wwin
->screen_ptr
->scr_height
;
1272 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1273 wwin
->frame_x
, wwin
->frame_y
,
1274 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1276 #endif /* ANIMATIONS */
1277 wwin
->flags
.skip_next_animation
= 0;
1279 if (!wwin
->flags
.shaded
)
1280 XMapWindow(dpy
, wwin
->client_win
);
1282 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1283 wRaiseFrame(wwin
->frame
->core
);
1284 if (!wwin
->flags
.shaded
)
1285 wClientSetState(wwin
, NormalState
, None
);
1287 mapTransientsFor(wwin
);
1290 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1291 && !wwin
->flags
.net_handle_icon
) {
1292 RemoveFromStackList(wwin
->icon
->core
);
1293 /* removeIconGrabs(wwin->icon); */
1294 wIconDestroy(wwin
->icon
);
1298 if (!netwm_hidden
) {
1301 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1304 if (!wwin
->screen_ptr
->flags
.startup
) {
1305 /* Catch up with events not processed while animation was running */
1306 Window clientwin
= wwin
->client_win
;
1308 ProcessPendingEvents();
1310 /* the window can disappear while ProcessPendingEvents() runs */
1311 if (!wWindowFor(clientwin
)) {
1312 ignore_wks_change
= 0;
1319 if (wPreferences
.auto_arrange_icons
)
1320 wArrangeIcons(wwin
->screen_ptr
, True
);
1322 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1324 /* In case we were shaded and iconified, also unshade */
1326 wUnshadeWindow(wwin
);
1328 ignore_wks_change
= 0;
1331 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1333 if (wwin
->flags
.miniaturized
) {
1335 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1336 wwin
->icon
->mapped
= 0;
1338 wwin
->flags
.hidden
= 1;
1340 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1344 if (wwin
->flags
.inspector_open
) {
1345 wHideInspectorForWindow(wwin
);
1348 wwin
->flags
.hidden
= 1;
1351 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1355 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1356 !wwin
->flags
.skip_next_animation
&& animate
) {
1357 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1358 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1359 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1362 wwin
->flags
.skip_next_animation
= 0;
1364 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1367 void wHideAll(WScreen
*scr
)
1372 unsigned int wcount
= 0;
1378 menu
= scr
->switch_menu
;
1380 windows
= wmalloc(sizeof(WWindow
*));
1383 for (i
= 0; i
< menu
->entry_no
; i
++) {
1384 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1386 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1389 wwin
= scr
->focused_window
;
1392 windows
[wcount
] = wwin
;
1394 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1400 for (i
= 0; i
< wcount
; i
++) {
1402 if (wwin
->frame
->workspace
== scr
->current_workspace
1403 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1404 && !wwin
->flags
.internal_window
1405 && !WFLAGP(wwin
, no_miniaturizable
)
1407 wwin
->flags
.skip_next_animation
= 1;
1408 wIconifyWindow(wwin
);
1415 void wHideOtherApplications(WWindow
*awin
)
1422 wwin
= awin
->screen_ptr
->focused_window
;
1426 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1427 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1428 && !wwin
->flags
.internal_window
1429 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1431 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1432 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1433 wwin
->flags
.skip_next_animation
= 1;
1434 wIconifyWindow(wwin
);
1436 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1437 tapp
= wApplicationOf(wwin
->main_window
);
1439 tapp
->flags
.skip_next_animation
= 1;
1440 wHideApplication(tapp
);
1442 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1443 wwin
->flags
.skip_next_animation
= 1;
1444 wIconifyWindow(wwin
);
1452 wSetFocusTo(awin->screen_ptr, awin);
1456 void wHideApplication(WApplication
*wapp
)
1464 wwarning("trying to hide a non grouped window");
1467 if (!wapp
->main_window_desc
) {
1468 wwarning("group leader not found for window group");
1471 scr
= wapp
->main_window_desc
->screen_ptr
;
1473 wlist
= scr
->focused_window
;
1477 if (wlist
->main_window
== wapp
->main_window
)
1478 wapp
->last_focused
= wlist
;
1480 wapp
->last_focused
= NULL
;
1482 animate
= !wapp
->flags
.skip_next_animation
;
1485 if (wlist
->main_window
== wapp
->main_window
) {
1486 if (wlist
->flags
.focused
) {
1489 if (wapp
->app_icon
) {
1490 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1491 wapp
->app_icon
->y_pos
, wlist
, animate
);
1495 wlist
= wlist
->prev
;
1498 wapp
->flags
.skip_next_animation
= 0;
1501 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1502 wlist
= scr
->focused_window
;
1504 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1505 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1507 wlist
= wlist
->prev
;
1509 wSetFocusTo(scr
, wlist
);
1511 wSetFocusTo(scr
, NULL
);
1515 wapp
->flags
.hidden
= 1;
1517 if (wPreferences
.auto_arrange_icons
)
1518 wArrangeIcons(scr
, True
);
1522 wAppIconPaint(wapp
->app_icon
);
1526 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1528 if (bringToCurrentWS
)
1529 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1531 wwin
->flags
.hidden
= 0;
1534 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1535 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1536 icon
->core
->width
, icon
->core
->height
,
1537 wwin
->frame_x
, wwin
->frame_y
,
1538 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1541 wwin
->flags
.skip_next_animation
= 0;
1542 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1543 XMapWindow(dpy
, wwin
->client_win
);
1544 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1545 wClientSetState(wwin
, NormalState
, None
);
1546 wwin
->flags
.mapped
= 1;
1547 wRaiseFrame(wwin
->frame
->core
);
1549 if (wwin
->flags
.inspector_open
) {
1550 wUnhideInspectorForWindow(wwin
);
1553 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1556 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1559 WWindow
*wlist
, *next
;
1560 WWindow
*focused
= NULL
;
1566 scr
= wapp
->main_window_desc
->screen_ptr
;
1567 wlist
= scr
->focused_window
;
1571 /* goto beginning of list */
1573 wlist
= wlist
->prev
;
1575 animate
= !wapp
->flags
.skip_next_animation
;
1580 if (wlist
->main_window
== wapp
->main_window
) {
1581 if (wlist
->flags
.focused
)
1583 else if (!focused
|| !focused
->flags
.focused
)
1586 if (wlist
->flags
.miniaturized
) {
1587 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1588 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1589 if (!wlist
->icon
->mapped
) {
1592 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1593 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1594 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1598 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1599 wlist
->icon
->mapped
= 1;
1601 wRaiseFrame(wlist
->icon
->core
);
1603 if (bringToCurrentWS
)
1604 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1605 wlist
->flags
.hidden
= 0;
1606 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1607 wDeiconifyWindow(wlist
);
1609 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1610 } else if (wlist
->flags
.shaded
) {
1611 if (bringToCurrentWS
)
1612 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1613 wlist
->flags
.hidden
= 0;
1614 wRaiseFrame(wlist
->frame
->core
);
1615 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1616 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1618 wUnshadeWindow(wlist
);
1621 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1622 } else if (wlist
->flags
.hidden
) {
1623 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1624 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1627 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
)
1628 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1630 wRaiseFrame(wlist
->frame
->core
);
1636 wapp
->flags
.skip_next_animation
= 0;
1637 wapp
->flags
.hidden
= 0;
1639 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1640 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1641 wSetFocusTo(scr
, wapp
->last_focused
);
1642 } else if (focused
) {
1643 wSetFocusTo(scr
, focused
);
1645 wapp
->last_focused
= NULL
;
1646 if (wPreferences
.auto_arrange_icons
)
1647 wArrangeIcons(scr
, True
);
1650 wAppIconPaint(wapp
->app_icon
);
1654 void wShowAllWindows(WScreen
*scr
)
1656 WWindow
*wwin
, *old_foc
;
1659 old_foc
= wwin
= scr
->focused_window
;
1661 if (!wwin
->flags
.internal_window
&&
1662 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1663 if (wwin
->flags
.miniaturized
) {
1664 wwin
->flags
.skip_next_animation
= 1;
1665 wDeiconifyWindow(wwin
);
1666 } else if (wwin
->flags
.hidden
) {
1667 wapp
= wApplicationOf(wwin
->main_window
);
1669 wUnhideApplication(wapp
, False
, False
);
1671 wwin
->flags
.skip_next_animation
= 1;
1672 wDeiconifyWindow(wwin
);
1678 wSetFocusTo(scr
, old_foc
);
1679 /*wRaiseFrame(old_foc->frame->core); */
1682 void wRefreshDesktop(WScreen
*scr
)
1685 XSetWindowAttributes attr
;
1687 attr
.backing_store
= NotUseful
;
1688 attr
.save_under
= False
;
1689 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1690 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1691 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1692 XMapRaised(dpy
, win
);
1693 XDestroyWindow(dpy
, win
);
1697 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1703 const int heads
= wXineramaHeads(scr
);
1706 int pf
; /* primary axis */
1707 int sf
; /* secondary axis */
1711 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1717 int isize
= wPreferences
.icon_size
;
1719 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1721 for (head
= 0; head
< heads
; ++head
) {
1722 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1723 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1724 vars
[head
].pi
= vars
[head
].si
= 0;
1725 vars
[head
].sx1
= rect
.pos
.x
;
1726 vars
[head
].sy1
= rect
.pos
.y
;
1727 vars
[head
].sw
= rect
.size
.width
;
1728 vars
[head
].sh
= rect
.size
.height
;
1729 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1730 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1731 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1732 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1733 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1734 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1736 /* icon yard boundaries */
1737 if (wPreferences
.icon_yard
& IY_VERT
) {
1738 vars
[head
].pf
= vars
[head
].fullH
;
1739 vars
[head
].sf
= vars
[head
].fullW
;
1741 vars
[head
].pf
= vars
[head
].fullW
;
1742 vars
[head
].sf
= vars
[head
].fullH
;
1744 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1745 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1748 vars
[head
].xo
= vars
[head
].sx1
;
1751 if (wPreferences
.icon_yard
& IY_TOP
) {
1752 vars
[head
].yo
= vars
[head
].sy1
;
1755 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1760 #define X ((wPreferences.icon_yard & IY_VERT) \
1761 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1762 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1764 #define Y ((wPreferences.icon_yard & IY_VERT) \
1765 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1766 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1768 /* arrange application icons */
1769 aicon
= scr
->app_icon_list
;
1770 /* reverse them to avoid unnecessarily sliding of icons */
1771 while (aicon
&& aicon
->next
)
1772 aicon
= aicon
->next
;
1775 if (!aicon
->docked
) {
1776 /* CHECK: can icon be NULL here ? */
1777 /* The intention here is to place the AppIcon on the head that
1778 * contains most of the applications _main_ window. */
1779 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1781 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1783 if (!wPreferences
.no_animations
)
1784 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1785 #endif /* ANIMATIONS */
1787 wAppIconMove(aicon
, X
, Y
);
1789 if (vars
[head
].pi
>= vars
[head
].pf
) {
1794 aicon
= aicon
->prev
;
1797 /* arrange miniwindows */
1798 wwin
= scr
->focused_window
;
1799 /* reverse them to avoid unnecessarily shuffling */
1800 while (wwin
&& wwin
->prev
)
1804 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1805 (wwin
->frame
->workspace
== scr
->current_workspace
||
1806 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1808 head
= wGetHeadForWindow(wwin
);
1810 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1811 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1812 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1818 if (vars
[head
].pi
>= vars
[head
].pf
) {
1825 wwin
->flags
.icon_moved
= 0;
1827 /* we reversed the order, so we use next */
1834 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1836 WScreen
*scr
= wwin
->screen_ptr
;
1839 wwin
->flags
.selected
= 1;
1840 if (wwin
->frame
->selected_border_pixel
)
1841 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1843 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1845 if (!HAS_BORDER(wwin
)) {
1846 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
1849 if (!scr
->selected_windows
)
1850 scr
->selected_windows
= WMCreateArray(4);
1851 WMAddToArray(scr
->selected_windows
, wwin
);
1853 wwin
->flags
.selected
= 0;
1854 if (wwin
->frame
->border_pixel
)
1855 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1857 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1859 if (!HAS_BORDER(wwin
)) {
1860 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1863 if (scr
->selected_windows
) {
1864 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1869 void wMakeWindowVisible(WWindow
*wwin
)
1871 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1872 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1874 if (wwin
->flags
.shaded
)
1875 wUnshadeWindow(wwin
);
1877 if (wwin
->flags
.hidden
) {
1880 app
= wApplicationOf(wwin
->main_window
);
1882 /* trick to get focus to this window */
1883 app
->last_focused
= wwin
;
1884 wUnhideApplication(app
, False
, False
);
1887 if (wwin
->flags
.miniaturized
) {
1888 wDeiconifyWindow(wwin
);
1890 if (!WFLAGP(wwin
, no_focusable
))
1891 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1892 wRaiseFrame(wwin
->frame
->core
);
1897 * Do the animation while shading (called with what = SHADE)
1898 * or unshading (what = UNSHADE).
1901 static void shade_animate(WWindow
*wwin
, Bool what
)
1904 time_t time0
= time(NULL
);
1906 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1911 if (!wwin
->screen_ptr
->flags
.startup
) {
1912 /* do the shading animation */
1913 h
= wwin
->frame
->core
->height
;
1914 s
= h
/ SHADE_STEPS
;
1917 w
= wwin
->frame
->core
->width
;
1918 y
= wwin
->frame
->top_width
;
1919 while (h
> wwin
->frame
->top_width
+ 1) {
1920 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1921 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1924 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1927 if (SHADE_DELAY
> 0) {
1928 wusleep(SHADE_DELAY
* 1000L);
1935 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1940 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1941 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1942 s
= abs(y
) / SHADE_STEPS
;
1945 w
= wwin
->frame
->core
->width
;
1946 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1948 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1949 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1950 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1952 if (SHADE_DELAY
> 0) {
1953 wusleep(SHADE_DELAY
* 2000L / 3);
1960 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1964 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);