2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 /* ---------------------------- included header files ---------------------- */
23 #include "libs/fvwmlib.h"
24 #include "libs/FScreen.h"
25 #include "libs/Grab.h"
26 #include "libs/Parse.h"
27 #include "libs/XResource.h"
30 #include "execcontext.h"
35 #include "placement.h"
39 #include "move_resize.h"
44 #include "add_window.h"
46 /* ---------------------------- local definitions -------------------------- */
48 #define MAX_NUM_PLACEMENT_ALGOS 31
49 #define CP_GET_NEXT_STEP 5
51 /* ---------------------------- local macros ------------------------------- */
54 #define MIN(A,B) ((A)<(B)? (A):(B))
57 #define MAX(A,B) ((A)>(B)? (A):(B))
60 #define NORMAL_PLACEMENT_PENALTY(p) (p->normal)
61 #define ONTOP_PLACEMENT_PENALTY(p) (p->ontop)
62 #define ICON_PLACEMENT_PENALTY(p) (p->icon)
63 #define STICKY_PLACEMENT_PENALTY(p) (p->sticky)
64 #define BELOW_PLACEMENT_PENALTY(p) (p->below)
65 #define EWMH_STRUT_PLACEMENT_PENALTY(p) (p->strut)
67 #define PERCENTAGE_99_PENALTY(p) (p->p99)
68 #define PERCENTAGE_95_PENALTY(p) (p->p95)
69 #define PERCENTAGE_85_PENALTY(p) (p->p85)
70 #define PERCENTAGE_75_PENALTY(p) (p->p75)
72 /* ---------------------------- imports ------------------------------------ */
74 /* ---------------------------- included code files ------------------------ */
76 /* ---------------------------- local types -------------------------------- */
87 PR_POS_USPOS_OVERRIDE_SOS
92 PR_SCREEN_CURRENT
= 0,
94 PR_SCREEN_X_RESOURCE_FVWMSCREEN
,
95 PR_SCREEN_IGNORE_CAPTURE
102 PR_PAGE_X_RESOURCE_PAGE
,
103 PR_PAGE_IGNORE_CAPTURE
,
104 PR_PAGE_IGNORE_INVALID
,
112 PR_DESK_X_RESOURCE_DESK
,
113 PR_DESK_X_RESOURCE_PAGE
,
116 PR_DESK_WINDOW_GROUP_LEADER
,
117 PR_DESK_WINDOW_GROUP_MEMBER
,
119 PR_DESK_XPROP_XA_WM_DESKTOP
126 preason_pos_t reason
;
130 char *pl_position_string
;
131 unsigned do_not_manual_icon_placement
: 1;
132 unsigned do_adjust_off_screen
: 1;
133 unsigned do_adjust_off_page
: 1;
134 unsigned is_pl_position_string_invalid
: 1;
135 unsigned has_tile_failed
: 1;
136 unsigned has_manual_failed
: 1;
137 unsigned has_placement_failed
: 1;
141 preason_screen_t reason
;
144 unsigned was_modified_by_ewmh_workingarea
: 1;
148 preason_page_t reason
;
151 unsigned do_switch_page
: 1;
152 unsigned do_honor_starts_on_page
: 1;
153 unsigned do_ignore_starts_on_page
: 1;
157 preason_desk_t reason
;
158 preason_desk_t sod_reason
;
160 unsigned do_switch_desk
: 1;
174 unsigned do_forbid_manual_placement
: 1;
175 unsigned do_honor_starts_on_page
: 1;
176 unsigned do_honor_starts_on_screen
: 1;
177 unsigned do_not_use_wm_placement
: 1;
180 typedef float pl_penalty_t
;
193 /* If this funtion pointer is not NULL, use this function to return
194 * the desired position in a single call */
195 pl_penalty_t (*get_pos_simple
)(
196 position
*ret_p
, struct pl_ret_t
*ret
,
197 const struct pl_arg_t
*arg
);
198 /* otherwise use these three in a loop */
199 pl_loop_rc_t (*get_first_pos
)(
200 position
*ret_p
, struct pl_ret_t
*ret
,
201 const struct pl_arg_t
*arg
);
202 pl_loop_rc_t (*get_next_pos
)(
203 position
*ret_p
, struct pl_ret_t
*ret
,
204 const struct pl_arg_t
*arg
, position hint_p
);
205 pl_penalty_t (*get_pos_penalty
)(
206 position
*ret_hint_p
, struct pl_ret_t
*ret
,
207 const struct pl_arg_t
*arg
);
210 typedef struct pl_scratch_t
212 const pl_penalty_struct
*pp
;
213 const pl_percent_penalty_struct
*ppp
;
216 typedef struct pl_arg_t
218 const pl_algo_t
*algo
;
219 const exec_context_t
*exc
;
220 const window_style
*style
;
222 FvwmWindow
*place_fw
;
223 pl_scratch_t
*scratch
;
232 unsigned use_percent
: 1;
233 unsigned use_ewmh_dynamic_working_areapercent
: 1;
234 unsigned do_honor_starts_on_page
: 1;
238 typedef struct pl_ret_t
241 pl_penalty_t best_penalty
;
244 unsigned do_resize_too
: 1;
248 /* ---------------------------- forward declarations ----------------------- */
250 static pl_loop_rc_t
__pl_minoverlap_get_first_pos(
251 position
*ret_p
, struct pl_ret_t
*ret
, const struct pl_arg_t
*arg
);
252 static pl_loop_rc_t
__pl_minoverlap_get_next_pos(
253 position
*ret_p
, struct pl_ret_t
*ret
, const struct pl_arg_t
*arg
,
255 static pl_penalty_t
__pl_minoverlap_get_pos_penalty(
256 position
*ret_hint_p
, struct pl_ret_t
*ret
, const pl_arg_t
*arg
);
258 static pl_penalty_t
__pl_smart_get_pos_penalty(
259 position
*ret_hint_p
, struct pl_ret_t
*ret
, const pl_arg_t
*arg
);
261 static pl_penalty_t
__pl_position_get_pos_simple(
262 position
*ret_p
, struct pl_ret_t
*ret
, const struct pl_arg_t
*arg
);
264 static pl_penalty_t
__pl_cascade_get_pos_simple(
265 position
*ret_p
, struct pl_ret_t
*ret
, const struct pl_arg_t
*arg
);
267 static pl_penalty_t
__pl_manual_get_pos_simple(
268 position
*ret_p
, struct pl_ret_t
*ret
, const struct pl_arg_t
*arg
);
270 /* ---------------------------- local variables ---------------------------- */
272 const pl_algo_t minoverlap_placement_algo
=
275 __pl_minoverlap_get_first_pos
,
276 __pl_minoverlap_get_next_pos
,
277 __pl_minoverlap_get_pos_penalty
280 const pl_algo_t smart_placement_algo
=
283 __pl_minoverlap_get_first_pos
,
284 __pl_minoverlap_get_next_pos
,
285 __pl_smart_get_pos_penalty
288 const pl_algo_t position_placement_algo
=
290 __pl_position_get_pos_simple
293 const pl_algo_t cascade_placement_algo
=
295 __pl_cascade_get_pos_simple
298 const pl_algo_t manual_placement_algo
=
300 __pl_manual_get_pos_simple
303 /* ---------------------------- exported variables (globals) --------------- */
305 const pl_penalty_struct default_pl_penalty
=
308 PLACEMENT_AVOID_ONTOP
,
309 PLACEMENT_AVOID_ICON
,
310 PLACEMENT_AVOID_STICKY
,
311 PLACEMENT_AVOID_BELOW
,
312 PLACEMENT_AVOID_EWMH_STRUT
315 const pl_percent_penalty_struct default_pl_percent_penalty
=
317 PLACEMENT_AVOID_COVER_99
,
318 PLACEMENT_AVOID_COVER_95
,
319 PLACEMENT_AVOID_COVER_85
,
320 PLACEMENT_AVOID_COVER_75
323 /* ---------------------------- local functions (PositionPlacement) -------- */
325 static pl_penalty_t
__pl_position_get_pos_simple(
326 position
*ret_p
, struct pl_ret_t
*ret
, const struct pl_arg_t
*arg
)
334 is_under_mouse
= False
;
335 spos
= SGET_PLACEMENT_POSITION_STRING(*arg
->style
);
336 if (spos
== NULL
|| *spos
== 0)
338 spos
= DEFAULT_PLACEMENT_POSITION_STRING
;
341 else if (StrEquals(spos
, "Center"))
343 spos
= DEFAULT_PLACEMENT_POS_CENTER_STRING
;
346 else if (StrEquals(spos
, "UnderMouse"))
348 spos
= DEFAULT_PLACEMENT_POS_MOUSE_STRING
;
350 is_under_mouse
= True
;
356 arg
->reason
->pos
.pl_position_string
= spos
;
357 for (n
= -1; i
< 2 && n
< 2; i
++)
362 n
= GetMoveArguments(
363 &spos
, arg
->place_g
.width
, arg
->place_g
.height
,
364 &ret_p
->x
, &ret_p
->y
, NULL
, &fPointer
, False
);
365 spos
= DEFAULT_PLACEMENT_POSITION_STRING
;
368 arg
->reason
->pos
.is_pl_position_string_invalid
= 1;
378 /* TA: 20090218: Try and keep the window on-screen if we
381 if (ret_p
->x
+ arg
->place_fw
->g
.frame
.width
> arg
->screen_g
.x
382 + arg
->screen_g
.width
)
384 ret_p
->x
= (arg
->screen_g
.x
+ arg
->screen_g
.width
) -
385 arg
->place_fw
->g
.frame
.width
;
387 if (ret_p
->y
+ arg
->place_fw
->g
.frame
.height
> arg
->screen_g
.y
388 + arg
->screen_g
.height
)
390 ret_p
->y
= (arg
->screen_g
.y
+ arg
->screen_g
.height
) -
391 arg
->place_fw
->g
.frame
.height
;
394 /* Don't let the upper left corner be offscreen. */
395 if (ret_p
->x
< arg
->screen_g
.x
)
397 ret_p
->x
= arg
->screen_g
.x
;
399 if (ret_p
->y
< arg
->screen_g
.y
)
401 ret_p
->y
= arg
->screen_g
.y
;
403 if (arg
->flags
.do_honor_starts_on_page
)
405 ret_p
->x
-= arg
->pdelta_p
.x
;
406 ret_p
->y
-= arg
->pdelta_p
.y
;
412 /* ---------------------------- local functions (CascadePlacement)---------- */
414 static pl_penalty_t
__pl_cascade_get_pos_simple(
415 position
*ret_p
, struct pl_ret_t
*ret
, const struct pl_arg_t
*arg
)
421 t
= (Scr
.cascade_window
!= NULL
) ? Scr
.cascade_window
: arg
->place_fw
;
422 w
= t
->title_thickness
;
425 w
= t
->boundary_width
;
429 w
= PLACEMENT_FALLBACK_CASCADE_STEP
;
432 if (Scr
.cascade_window
!= NULL
)
437 switch (GET_TITLE_DIR(t
))
451 Scr
.cascade_window
= arg
->place_fw
;
452 if (Scr
.cascade_x
> arg
->screen_g
.width
/ 2)
454 Scr
.cascade_x
= arg
->place_fw
->title_thickness
;
456 if (Scr
.cascade_y
> arg
->screen_g
.height
/ 2)
458 Scr
.cascade_y
= 2 * arg
->place_fw
->title_thickness
;
460 ret_p
->x
= Scr
.cascade_x
+ arg
->page_p1
.x
;
461 ret_p
->y
= Scr
.cascade_y
+ arg
->page_p1
.y
;
462 /* try to keep the window on the screen */
463 get_window_borders(arg
->place_fw
, &b
);
464 if (ret_p
->x
+ arg
->place_g
.width
>= arg
->page_p2
.x
)
466 ret_p
->x
= arg
->page_p2
.x
- arg
->place_g
.width
-
468 Scr
.cascade_x
= arg
->place_fw
->title_thickness
;
469 switch (GET_TITLE_DIR(t
))
473 Scr
.cascade_x
+= arg
->place_fw
->title_thickness
;
478 if (ret_p
->y
+ arg
->place_g
.height
>= arg
->page_p2
.y
)
480 ret_p
->y
= arg
->page_p2
.y
- arg
->place_g
.height
-
482 Scr
.cascade_y
= arg
->place_fw
->title_thickness
;
483 switch (GET_TITLE_DIR(t
))
487 Scr
.cascade_y
+= arg
->place_fw
->title_thickness
;
493 /* the left and top sides are more important in huge windows */
494 if (ret_p
->x
< arg
->page_p1
.x
)
496 ret_p
->x
= arg
->page_p1
.x
;
498 if (ret_p
->y
< arg
->page_p1
.y
)
500 ret_p
->y
= arg
->page_p1
.y
;
506 /* ---------------------------- local functions (ManualPlacement)----------- */
508 static pl_penalty_t
__pl_manual_get_pos_simple(
509 position
*ret_p
, struct pl_ret_t
*ret
, const struct pl_arg_t
*arg
)
513 if (GrabEm(CRS_POSITION
, GRAB_NORMAL
))
520 /* Grabbed the pointer - continue */
524 dpy
, FW_W(arg
->place_fw
), &JunkRoot
, &JunkX
,
525 &JunkY
, (unsigned int*)&DragWidth
,
526 (unsigned int*)&DragHeight
,
527 (unsigned int*)&JunkBW
,
528 (unsigned int*)&JunkDepth
) == 0)
530 MyXUngrabServer(dpy
);
531 UngrabEm(GRAB_NORMAL
);
535 SET_PLACED_BY_FVWM(arg
->place_fw
, 0);
536 MyXGrabKeyboard(dpy
);
537 DragWidth
= arg
->place_g
.width
;
538 DragHeight
= arg
->place_g
.height
;
540 if (Scr
.SizeWindow
!= None
)
542 XMapRaised(dpy
, Scr
.SizeWindow
);
545 NULL
, FSCREEN_GLOBAL
, &mx
, &my
, NULL
, NULL
);
547 arg
->exc
, mx
, my
, DragWidth
, DragHeight
, &ret_p
->x
,
548 &ret_p
->y
, False
, CRS_POSITION
))
550 ret
->flags
.do_resize_too
= 1;
552 if (Scr
.SizeWindow
!= None
)
554 XUnmapWindow(dpy
, Scr
.SizeWindow
);
556 MyXUngrabKeyboard(dpy
);
557 MyXUngrabServer(dpy
);
558 UngrabEm(GRAB_NORMAL
);
562 /* couldn't grab the pointer - better do something */
566 arg
->reason
->pos
.has_manual_failed
= 1;
568 if (arg
->flags
.do_honor_starts_on_page
)
570 ret_p
->x
-= arg
->pdelta_p
.x
;
571 ret_p
->y
-= arg
->pdelta_p
.y
;
577 /* ---------------------------- local functions (MinoverlapPlacement) ------ */
579 /* MinoverlapPlacement by Anthony Martin <amartin@engr.csulb.edu>
580 * This algorithm places a new window such that there is a minimum amount of
581 * interference with other windows. If it can place a window without any
582 * interference, fine. Otherwise, it places it so that the area of of
583 * interference between the new window and the other windows is minimized */
585 static int __pl_minoverlap_get_next_x(const pl_arg_t
*arg
)
587 FvwmWindow
*other_fw
;
601 if (arg
->flags
.use_percent
== 1)
607 start
= CP_GET_NEXT_STEP
;
610 /* Test window at far right of screen */
611 xnew
= arg
->page_p2
.x
;
612 xtest
= arg
->page_p2
.x
- arg
->place_g
.width
;
617 /* test the borders of the working area */
618 xtest
= arg
->page_p1
.x
+ Scr
.Desktops
->ewmh_working_area
.x
;
621 xnew
= MIN(xnew
, xtest
);
623 xtest
= arg
->page_p1
.x
+
624 (Scr
.Desktops
->ewmh_working_area
.x
+
625 Scr
.Desktops
->ewmh_working_area
.width
) -
629 xnew
= MIN(xnew
, xtest
);
631 /* Test the values of the right edges of every window */
633 other_fw
= Scr
.FvwmRoot
.next
; other_fw
!= NULL
;
634 other_fw
= other_fw
->next
)
637 other_fw
== arg
->place_fw
||
638 (other_fw
->Desk
!= arg
->place_fw
->Desk
&&
639 !IS_STICKY_ACROSS_DESKS(other_fw
)) ||
640 IS_EWMH_DESKTOP(FW_W(other_fw
)))
644 if (IS_STICKY_ACROSS_PAGES(other_fw
))
646 stickyx
= arg
->pdelta_p
.x
;
647 stickyy
= arg
->pdelta_p
.y
;
654 if (IS_ICONIFIED(other_fw
))
656 rc
= get_visible_icon_geometry(other_fw
, &g
);
657 if (rc
== True
&& y
< g
.y
+ g
.height
- stickyy
&&
658 g
.y
- stickyy
< arg
->place_g
.height
+ y
)
660 win_left
= arg
->page_p1
.x
+ g
.x
- stickyx
-
662 for (i
= start
; i
<= CP_GET_NEXT_STEP
; i
++)
664 xtest
= win_left
+ g
.width
*
665 (CP_GET_NEXT_STEP
- i
) /
669 xnew
= MIN(xnew
, xtest
);
672 win_left
= arg
->page_p1
.x
+ g
.x
- stickyx
;
673 for (i
= start
; i
<= CP_GET_NEXT_STEP
; i
++)
675 xtest
= (win_left
) + g
.width
* i
/
679 xnew
= MIN(xnew
, xtest
);
685 y
< other_fw
->g
.frame
.height
+ other_fw
->g
.frame
.y
-
687 other_fw
->g
.frame
.y
- stickyy
<
688 arg
->place_g
.height
+ y
&&
689 arg
->page_p1
.x
< other_fw
->g
.frame
.width
+
690 other_fw
->g
.frame
.x
- stickyx
&&
691 other_fw
->g
.frame
.x
- stickyx
< arg
->page_p2
.x
)
694 other_fw
->g
.frame
.x
- stickyx
-
696 for (i
= start
; i
<= CP_GET_NEXT_STEP
; i
++)
698 xtest
= win_left
+ other_fw
->g
.frame
.width
*
699 (CP_GET_NEXT_STEP
- i
) /
703 xnew
= MIN(xnew
, xtest
);
706 win_left
= other_fw
->g
.frame
.x
- stickyx
;
707 for (i
= start
; i
<= CP_GET_NEXT_STEP
; i
++)
709 xtest
= win_left
+ other_fw
->g
.frame
.width
*
710 i
/ CP_GET_NEXT_STEP
;
713 xnew
= MIN(xnew
, xtest
);
722 static int __pl_minoverlap_get_next_y(const pl_arg_t
*arg
)
724 FvwmWindow
*other_fw
;
735 if (arg
->flags
.use_percent
== 1)
741 start
= CP_GET_NEXT_STEP
;
744 /* Test window at far bottom of screen */
745 ynew
= arg
->page_p2
.y
;
746 ytest
= arg
->page_p2
.y
- arg
->place_g
.height
;
751 /* test the borders of the working area */
752 ytest
= arg
->page_p1
.y
+ Scr
.Desktops
->ewmh_working_area
.y
;
755 ynew
= MIN(ynew
, ytest
);
757 ytest
= arg
->screen_g
.y
+
758 (Scr
.Desktops
->ewmh_working_area
.y
+
759 Scr
.Desktops
->ewmh_working_area
.height
) -
763 ynew
= MIN(ynew
, ytest
);
765 /* Test the values of the bottom edge of every window */
767 other_fw
= Scr
.FvwmRoot
.next
; other_fw
!= NULL
;
768 other_fw
= other_fw
->next
)
771 other_fw
== arg
->place_fw
||
773 other_fw
->Desk
!= arg
->place_fw
->Desk
&&
774 !IS_STICKY_ACROSS_DESKS(other_fw
)) ||
775 IS_EWMH_DESKTOP(FW_W(other_fw
)))
780 if (IS_STICKY_ACROSS_PAGES(other_fw
))
782 stickyy
= arg
->pdelta_p
.y
;
789 if (IS_ICONIFIED(other_fw
))
791 get_visible_icon_geometry(other_fw
, &g
);
792 win_top
= g
.y
- stickyy
;
793 for (i
= start
; i
<= CP_GET_NEXT_STEP
; i
++)
796 win_top
+ g
.height
* i
/
800 ynew
= MIN(ynew
, ytest
);
803 win_top
= g
.y
- stickyy
- arg
->place_g
.height
;
804 for (i
= start
; i
<= CP_GET_NEXT_STEP
; i
++)
808 (CP_GET_NEXT_STEP
- i
) /
812 ynew
= MIN(ynew
, ytest
);
818 win_top
= other_fw
->g
.frame
.y
- stickyy
;
819 for (i
= start
; i
<= CP_GET_NEXT_STEP
; i
++)
822 win_top
+ other_fw
->g
.frame
.height
*
823 i
/ CP_GET_NEXT_STEP
;
826 ynew
= MIN(ynew
, ytest
);
829 win_top
= other_fw
->g
.frame
.y
- stickyy
-
831 for (i
= start
; i
<= CP_GET_NEXT_STEP
; i
++)
834 win_top
+ other_fw
->g
.frame
.height
*
835 (CP_GET_NEXT_STEP
- i
) /
839 ynew
= MIN(ynew
, ytest
);
848 static pl_loop_rc_t
__pl_minoverlap_get_first_pos(
849 position
*ret_p
, struct pl_ret_t
*ret
, const pl_arg_t
*arg
)
851 /* top left corner of page */
852 ret_p
->x
= arg
->page_p1
.x
;
853 ret_p
->y
= arg
->page_p1
.y
;
858 static pl_loop_rc_t
__pl_minoverlap_get_next_pos(
859 position
*ret_p
, struct pl_ret_t
*ret
, const struct pl_arg_t
*arg
,
862 ret_p
->x
= arg
->place_g
.x
;
863 ret_p
->y
= arg
->place_g
.y
;
864 if (ret_p
->x
+ arg
->place_g
.width
<= arg
->page_p2
.x
)
867 ret_p
->x
= __pl_minoverlap_get_next_x(arg
);
868 ret_p
->y
= arg
->place_g
.y
;
870 if (ret_p
->x
+ arg
->place_g
.width
> arg
->page_p2
.x
)
872 /* out of room in x direction. Try next y. Reset x.*/
873 ret_p
->x
= arg
->page_p1
.x
;
874 ret_p
->y
= __pl_minoverlap_get_next_y(arg
);
876 if (ret_p
->y
+ arg
->place_g
.height
> arg
->page_p2
.y
)
885 static pl_penalty_t
__pl_minoverlap_get_avoidance_penalty(
886 const pl_arg_t
*arg
, FvwmWindow
*other_fw
, const rectangle
*other_g
)
889 pl_penalty_t avoidance_factor
;
891 const pl_penalty_struct
*opp
;
892 const pl_percent_penalty_struct
*oppp
;
894 opp
= (arg
->scratch
->pp
!= 0 && 0) ? arg
->scratch
->pp
:
895 &other_fw
->pl_penalty
;
896 oppp
= (arg
->scratch
->ppp
!= 0 && 0) ? arg
->scratch
->ppp
:
897 &other_fw
->pl_percent_penalty
;
898 other_p2
.x
= other_g
->x
+ other_g
->width
;
899 other_p2
.y
= other_g
->y
+ other_g
->height
;
901 long x1
= MAX(arg
->place_g
.x
, other_g
->x
);
902 long x2
= MIN(arg
->place_p2
.x
, other_p2
.x
);
903 long y1
= MAX(arg
->place_g
.y
, other_g
->y
);
904 long y2
= MIN(arg
->place_p2
.y
, other_p2
.y
);
906 /* overlapping area in pixels (windows are guaranteed to
907 * overlap when this function is called) */
908 anew
= (x2
- x1
) * (y2
- y1
);
910 if (IS_ICONIFIED(other_fw
))
912 avoidance_factor
= ICON_PLACEMENT_PENALTY(opp
);
914 else if (compare_window_layers(other_fw
, arg
->place_fw
) > 0)
916 avoidance_factor
= ONTOP_PLACEMENT_PENALTY(opp
);
918 else if (compare_window_layers(other_fw
, arg
->place_fw
) < 0)
920 avoidance_factor
= BELOW_PLACEMENT_PENALTY(opp
);
923 IS_STICKY_ACROSS_PAGES(other_fw
) ||
924 IS_STICKY_ACROSS_DESKS(other_fw
))
926 avoidance_factor
= STICKY_PLACEMENT_PENALTY(opp
);
930 avoidance_factor
= NORMAL_PLACEMENT_PENALTY(opp
);
932 if (arg
->flags
.use_percent
== 1)
934 pl_penalty_t cover_factor
;
938 other_area
= other_g
->width
* other_g
->height
;
939 place_area
= arg
->place_g
.width
* arg
->place_g
.height
;
941 if (other_area
!= 0 && place_area
!= 0)
943 anew
= 100 * MAX(anew
/ other_area
, anew
/ place_area
);
946 cover_factor
= PERCENTAGE_99_PENALTY(oppp
);
950 cover_factor
= PERCENTAGE_95_PENALTY(oppp
);
954 cover_factor
= PERCENTAGE_85_PENALTY(oppp
);
958 cover_factor
= PERCENTAGE_75_PENALTY(oppp
);
961 if (avoidance_factor
>= 1)
963 avoidance_factor
+= cover_factor
;
967 arg
->flags
.use_ewmh_dynamic_working_areapercent
== 1 &&
968 DO_EWMH_IGNORE_STRUT_HINTS(other_fw
) == 0 &&
970 other_fw
->dyn_strut
.left
> 0 ||
971 other_fw
->dyn_strut
.right
> 0 ||
972 other_fw
->dyn_strut
.top
> 0 ||
973 other_fw
->dyn_strut
.bottom
> 0))
975 const pl_penalty_struct
*mypp
;
977 mypp
= (arg
->scratch
->pp
!= 0 && 0) ? arg
->scratch
->pp
:
978 &arg
->place_fw
->pl_penalty
;
979 /* if we intersect a window which reserves space */
980 avoidance_factor
+= (avoidance_factor
>= 1) ?
981 EWMH_STRUT_PLACEMENT_PENALTY(mypp
) : 0;
983 anew
*= avoidance_factor
;
988 static pl_penalty_t
__pl_minoverlap_get_pos_penalty(
989 position
*ret_hint_p
, struct pl_ret_t
*ret
, const struct pl_arg_t
*arg
)
991 FvwmWindow
*other_fw
;
992 pl_penalty_t penalty
;
997 other_fw
= Scr
.FvwmRoot
.next
; other_fw
!= NULL
;
998 other_fw
= other_fw
->next
)
1002 get_window_borders(other_fw
, &b
);
1005 arg
->place_fw
== other_fw
||
1006 IS_EWMH_DESKTOP(FW_W(other_fw
)))
1010 /* RBW - account for sticky windows... */
1012 other_fw
->Desk
!= arg
->place_fw
->Desk
&&
1013 IS_STICKY_ACROSS_DESKS(other_fw
) == 0)
1017 rc
= get_visible_window_or_icon_geometry(other_fw
, &other_g
);
1018 if (IS_STICKY_ACROSS_PAGES(other_fw
))
1020 other_g
.x
-= arg
->pdelta_p
.x
;
1021 other_g
.y
-= arg
->pdelta_p
.y
;
1024 arg
->place_g
.x
< other_g
.x
+ other_g
.width
&&
1025 arg
->place_p2
.x
> other_g
.x
&&
1026 arg
->place_g
.y
< other_g
.y
+ other_g
.height
&&
1027 arg
->place_p2
.y
> other_g
.y
)
1031 anew
= __pl_minoverlap_get_avoidance_penalty(
1032 arg
, other_fw
, &other_g
);
1035 penalty
> ret
->best_penalty
&&
1036 ret
->best_penalty
!= -1)
1038 /* TA: 20091230: Fix over-zealous penalties
1039 * by explicitly forcing the window on-screen
1040 * here. The y-axis is only affected here,
1041 * due to how the xoffset calculations happen
1042 * prior to setting the x-axis. When we get
1043 * penalties which are "over-zealous" -- and
1044 * by not taking into account the size of the
1045 * window borders, the window was being placed
1048 if (ret
->best_p
.y
+ arg
->place_g
.height
>= arg
->page_p2
.y
)
1052 arg
->place_g
.height
-
1053 b
.total_size
.height
);
1056 /* stop looking; the penalty is too high */
1061 /* now handle the working area */
1063 const pl_penalty_struct
*mypp
;
1065 mypp
= (arg
->scratch
->pp
!= 0 && 0) ? arg
->scratch
->pp
:
1066 &arg
->place_fw
->pl_penalty
;
1067 if (arg
->flags
.use_ewmh_dynamic_working_areapercent
== 1)
1069 penalty
+= EWMH_STRUT_PLACEMENT_PENALTY(mypp
) *
1070 EWMH_GetStrutIntersection(
1071 arg
->place_g
.x
, arg
->place_g
.y
,
1072 arg
->place_p2
.x
, arg
->place_p2
.y
,
1073 arg
->flags
.use_percent
);
1077 /* EWMH_USE_DYNAMIC_WORKING_AREA, count the base strut
1080 EWMH_STRUT_PLACEMENT_PENALTY(mypp
) *
1081 EWMH_GetBaseStrutIntersection(
1082 arg
->place_g
.x
, arg
->place_g
.y
,
1083 arg
->place_p2
.x
, arg
->place_p2
.y
,
1084 arg
->flags
.use_percent
);
1091 /* ---------------------------- local functions (SmartPlacement) ----------- */
1093 static pl_penalty_t
__pl_smart_get_pos_penalty(
1094 position
*ret_hint_p
, struct pl_ret_t
*ret
, const struct pl_arg_t
*arg
)
1098 arg
->scratch
->pp
= &default_pl_penalty
;
1099 arg
->scratch
->ppp
= &default_pl_percent_penalty
;
1100 p
= __pl_minoverlap_get_pos_penalty(ret_hint_p
, ret
, arg
);
1109 /* ---------------------------- local functions ---------------------------- */
1111 static int placement_loop(pl_ret_t
*ret
, pl_arg_t
*arg
)
1114 pl_penalty_t penalty
;
1115 pl_loop_rc_t loop_rc
;
1117 if (arg
->algo
->get_pos_simple
!= NULL
)
1121 penalty
= arg
->algo
->get_pos_simple(&pos
, ret
, arg
);
1122 arg
->place_g
.x
= pos
.x
;
1123 arg
->place_g
.y
= pos
.y
;
1124 ret
->best_penalty
= penalty
;
1125 ret
->best_p
.x
= pos
.x
;
1126 ret
->best_p
.y
= pos
.y
;
1127 loop_rc
= PL_LOOP_END
;
1131 loop_rc
= arg
->algo
->get_first_pos(&next_p
, ret
, arg
);
1132 arg
->place_g
.x
= next_p
.x
;
1133 arg
->place_g
.y
= next_p
.y
;
1134 ret
->best_p
.x
= next_p
.x
;
1135 ret
->best_p
.y
= next_p
.y
;
1137 while (loop_rc
!= PL_LOOP_END
)
1140 pl_scratch_t scratch
;
1142 memset(&scratch
, 0, sizeof(scratch
));
1143 arg
->scratch
= &scratch
;
1144 arg
->place_p2
.x
= arg
->place_g
.x
+ arg
->place_g
.width
;
1145 arg
->place_p2
.y
= arg
->place_g
.y
+ arg
->place_g
.height
;
1146 hint_p
.x
= arg
->place_g
.x
;
1147 hint_p
.y
= arg
->place_g
.y
;
1148 penalty
= arg
->algo
->get_pos_penalty(&hint_p
, ret
, arg
);
1149 /* I've added +0.0001 because with my machine the < test fail
1150 * with certain *equal* float numbers! */
1154 ret
->best_penalty
< 0 ||
1155 penalty
+ 0.0001 < ret
->best_penalty
))
1157 ret
->best_p
.x
= arg
->place_g
.x
;
1158 ret
->best_p
.y
= arg
->place_g
.y
;
1159 ret
->best_penalty
= penalty
;
1165 loop_rc
= arg
->algo
->get_next_pos(&next_p
, ret
, arg
, hint_p
);
1166 arg
->place_g
.x
= next_p
.x
;
1167 arg
->place_g
.y
= next_p
.y
;
1169 if (ret
->best_penalty
< 0)
1171 ret
->best_penalty
= -1;
1174 return (ret
->best_penalty
== -1) ? -1 : 0;
1177 static void __place_get_placement_flags(
1178 pl_flags_t
*ret_flags
, FvwmWindow
*fw
, window_style
*pstyle
,
1179 initial_window_options_t
*win_opts
, int mode
, pl_reason_t
*reason
)
1182 Bool override_uspos
;
1183 Bool has_ppos
= False
;
1184 Bool has_uspos
= False
;
1186 /* Windows use the position hint if these conditions are met:
1188 * The program specified a USPosition hint and it is not overridden
1189 * with the No(Transient)USPosition style.
1193 * The program specified a PPosition hint and it is not overridden
1194 * with the No(Transient)PPosition style.
1196 * Windows without a position hint are placed using wm placement.
1198 if (IS_TRANSIENT(fw
))
1200 override_ppos
= SUSE_NO_TRANSIENT_PPOSITION(&pstyle
->flags
);
1201 override_uspos
= SUSE_NO_TRANSIENT_USPOSITION(&pstyle
->flags
);
1205 override_ppos
= SUSE_NO_PPOSITION(&pstyle
->flags
);
1206 override_uspos
= SUSE_NO_USPOSITION(&pstyle
->flags
);
1208 if (fw
->hints
.flags
& PPosition
)
1213 reason
->pos
.reason
= PR_POS_USE_PPOS
;
1217 reason
->pos
.reason
= PR_POS_IGNORE_PPOS
;
1220 if (fw
->hints
.flags
& USPosition
)
1222 if (!override_uspos
)
1225 reason
->pos
.reason
= PR_POS_USE_USPOS
;
1227 else if (reason
->pos
.reason
!= PR_POS_USE_PPOS
)
1229 reason
->pos
.reason
= PR_POS_USE_USPOS
;
1232 if (mode
== PLACE_AGAIN
)
1234 ret_flags
->do_not_use_wm_placement
= 0;
1235 reason
->pos
.reason
= PR_POS_PLACE_AGAIN
;
1237 else if (has_ppos
|| has_uspos
)
1239 ret_flags
->do_not_use_wm_placement
= 1;
1241 else if (win_opts
->flags
.do_override_ppos
)
1243 ret_flags
->do_not_use_wm_placement
= 1;
1244 reason
->pos
.reason
= PR_POS_CAPTURE
;
1246 else if (!ret_flags
->do_honor_starts_on_page
&&
1247 fw
->wmhints
&& (fw
->wmhints
->flags
& StateHint
) &&
1248 fw
->wmhints
->initial_state
== IconicState
)
1250 ret_flags
->do_forbid_manual_placement
= 1;
1251 reason
->pos
.do_not_manual_icon_placement
= 1;
1257 static int __add_algo(
1258 const pl_algo_t
**algos
, int num_algos
, const pl_algo_t
*new_algo
)
1260 if (num_algos
>= MAX_NUM_PLACEMENT_ALGOS
)
1262 return MAX_NUM_PLACEMENT_ALGOS
;
1264 algos
[num_algos
] = new_algo
;
1270 static int __place_get_wm_pos(
1271 const exec_context_t
*exc
, window_style
*pstyle
, rectangle
*attr_g
,
1272 pl_flags_t flags
, rectangle screen_g
, pl_start_style_t start_style
,
1273 int mode
, initial_window_options_t
*win_opts
, pl_reason_t
*reason
,
1274 int pdeltax
, int pdeltay
)
1276 const pl_algo_t
*algos
[MAX_NUM_PLACEMENT_ALGOS
+ 1];
1278 unsigned int placement_mode
= SPLACEMENT_MODE(&pstyle
->flags
);
1283 /* BEGIN init placement agrs and ret */
1284 memset(&arg
, 0, sizeof(arg
));
1287 arg
.reason
= reason
;
1288 arg
.place_fw
= exc
->w
.fw
;
1289 arg
.place_g
= arg
.place_fw
->g
.frame
;
1290 arg
.screen_g
= screen_g
;
1291 arg
.page_p1
.x
= arg
.screen_g
.x
- pdeltax
;
1292 arg
.page_p1
.y
= arg
.screen_g
.y
- pdeltay
;
1293 arg
.page_p2
.x
= arg
.page_p1
.x
+ screen_g
.width
;
1294 arg
.page_p2
.y
= arg
.page_p1
.y
+ screen_g
.height
;
1295 arg
.pdelta_p
.x
= pdeltax
;
1296 arg
.pdelta_p
.y
= pdeltay
;
1297 arg
.flags
.use_percent
= 0;
1298 arg
.flags
.do_honor_starts_on_page
= flags
.do_honor_starts_on_page
;
1299 if (SEWMH_PLACEMENT_MODE(&pstyle
->flags
) == EWMH_USE_WORKING_AREA
)
1301 arg
.flags
.use_ewmh_dynamic_working_areapercent
= 1;
1303 memset(&ret
, 0, sizeof(ret
));
1304 ret
.best_penalty
= -1.0;
1305 /* END init placement agrs and ret */
1306 /* override if manual placement happens */
1307 SET_PLACED_BY_FVWM(arg
.place_fw
, 1);
1308 if (flags
.do_forbid_manual_placement
)
1310 switch (placement_mode
)
1313 case PLACE_MANUAL_B
:
1314 placement_mode
= PLACE_CASCADE
;
1316 case PLACE_TILEMANUAL
:
1317 placement_mode
= PLACE_TILECASCADE
;
1323 reason
->pos
.algo
= placement_mode
;
1324 /* first, try various "smart" placement */
1326 switch (placement_mode
)
1328 case PLACE_POSITION
:
1329 num_algos
= __add_algo(
1330 algos
, num_algos
, &position_placement_algo
);
1332 case PLACE_TILEMANUAL
:
1333 num_algos
= __add_algo(
1334 algos
, num_algos
, &smart_placement_algo
);
1335 num_algos
= __add_algo(
1336 algos
, num_algos
, &manual_placement_algo
);
1338 case PLACE_MINOVERLAPPERCENT
:
1339 arg
.flags
.use_percent
= 1;
1341 case PLACE_MINOVERLAP
:
1342 num_algos
= __add_algo(
1343 algos
, num_algos
, &minoverlap_placement_algo
);
1345 case PLACE_TILECASCADE
:
1346 num_algos
= __add_algo(
1347 algos
, num_algos
, &smart_placement_algo
);
1348 num_algos
= __add_algo(
1349 algos
, num_algos
, &cascade_placement_algo
);
1352 case PLACE_MANUAL_B
:
1353 num_algos
= __add_algo(
1354 algos
, num_algos
, &manual_placement_algo
);
1357 case PLACE_CASCADE_B
:
1358 num_algos
= __add_algo(
1359 algos
, num_algos
, &cascade_placement_algo
);
1365 /* try all the placement algorithms */
1366 for (i
= 0 ; ret
.best_penalty
< 0 && i
< num_algos
; i
++)
1368 arg
.algo
= algos
[i
];
1369 placement_loop(&ret
, &arg
);
1371 if (ret
.best_penalty
>= 0)
1373 /* placement succed */
1374 attr_g
->x
= ret
.best_p
.x
;
1375 attr_g
->y
= ret
.best_p
.y
;
1379 /* fall back to default position */
1382 reason
->pos
.has_placement_failed
= 1;
1385 return ret
.flags
.do_resize_too
;
1388 static int __place_get_nowm_pos(
1389 const exec_context_t
*exc
, window_style
*pstyle
, rectangle
*attr_g
,
1390 pl_flags_t flags
, rectangle screen_g
, pl_start_style_t start_style
,
1391 int mode
, initial_window_options_t
*win_opts
, pl_reason_t
*reason
,
1392 int pdeltax
, int pdeltay
)
1394 FvwmWindow
*fw
= exc
->w
.fw
;
1397 if (!win_opts
->flags
.do_override_ppos
)
1399 SET_PLACED_BY_FVWM(fw
, False
);
1401 /* the USPosition was specified, or the window is a transient, or it
1402 * starts iconic so place it automatically */
1404 SUSE_START_ON_SCREEN(&pstyle
->flags
) &&
1405 flags
.do_honor_starts_on_screen
)
1407 fscreen_scr_t mangle_screen
;
1409 /* If StartsOnScreen has been given for a window, translate its
1410 * USPosition so that it is relative to that particular screen.
1411 * If we don't do this, then a geometry would completely
1412 * cancel the effect of the StartsOnScreen style. However, some
1413 * applications try to remember their position. This would
1414 * break if these were translated to screen coordinates. There
1415 * is no reliable way to do it. Currently, if the desired
1416 * place does not intersect the target screen, we assume the
1417 * window position must be adjusted to the screen origin. So
1418 * there are two ways to get a window to pop up on a particular
1419 * Xinerama screen. 1: The intuitive way giving a geometry
1420 * hint relative to the desired screen's 0,0 along with the
1421 * appropriate StartsOnScreen style (or *wmscreen resource), or
1422 * 2: Do NOT specify a Xinerama screen (or specify it to be
1423 * 'g') and give the geometry hint in terms of the global
1425 mangle_screen
= FScreenFetchMangledScreenFromUSPosHints(
1427 if (mangle_screen
!= FSCREEN_GLOBAL
)
1429 /* whoever set this hint knew exactly what he was
1430 * doing; so ignore the StartsOnScreen style */
1431 flags
.do_honor_starts_on_screen
= 0;
1432 reason
->pos
.reason
= PR_POS_USPOS_OVERRIDE_SOS
;
1434 else if (attr_g
->x
+ attr_g
->width
< screen_g
.x
||
1435 attr_g
->x
>= screen_g
.x
+ screen_g
.width
||
1436 attr_g
->y
+ attr_g
->height
< screen_g
.y
||
1437 attr_g
->y
>= screen_g
.y
+ screen_g
.height
)
1439 /* desired coordinates do not intersect the target
1440 * screen. Let's assume the application specified
1441 * global coordinates and translate them to the screen.
1443 FScreenTranslateCoordinates(
1444 NULL
, start_style
.screen
, NULL
, FSCREEN_GLOBAL
,
1445 &attr_g
->x
, &attr_g
->y
);
1446 reason
->pos
.do_adjust_off_screen
= 1;
1449 /* If SkipMapping, and other legalities are observed, adjust for
1451 if (DO_NOT_SHOW_ON_MAP(fw
) && flags
.do_honor_starts_on_page
&&
1452 (!IS_TRANSIENT(fw
) ||
1453 SUSE_START_ON_PAGE_FOR_TRANSIENT(&pstyle
->flags
))
1455 /* dv 08-Jul-2003: Do not use this. Instead, force the window on
1456 * the requested page even if the application requested a different
1458 && (SUSE_NO_PPOSITION(&pstyle
->flags
) ||
1459 !(fw
->hints
.flags
& PPosition
))
1460 /* dv 08-Jul-2003: This condition is always true because we
1461 * already checked for flags.do_honor_starts_on_page above. */
1462 /* RBW - allow StartsOnPage to go through, even if iconic. */
1463 && ((!(fw
->wmhints
&& (fw
->wmhints
->flags
& StateHint
) &&
1464 fw
->wmhints
->initial_state
== IconicState
))
1465 || flags
.do_honor_starts_on_page
)
1474 /* We're placing a SkipMapping window - either capturing one
1475 * that's previously been mapped, or overriding USPosition - so
1476 * what we have here is its actual untouched coordinates. In
1477 * case it was a StartsOnPage window, we have to 1) convert the
1478 * existing x,y offsets relative to the requested page (i.e.,
1479 * as though there were only one page, no virtual desktop),
1480 * then 2) readjust relative to the current page. */
1483 attr_g
->x
+= Scr
.MyDisplayWidth
;
1485 attr_g
->x
%= Scr
.MyDisplayWidth
;
1486 attr_g
->x
-= pdeltax
;
1487 /* Noticed a quirk here. With some apps (e.g., xman), we find
1488 * the placement has moved 1 pixel away from where we
1489 * originally put it when we come through here. Why is this
1490 * happening? Probably attr_backup.border_width, try xclock
1491 * -borderwidth 100 */
1494 attr_g
->y
+= Scr
.MyDisplayHeight
;
1496 attr_g
->y
%= Scr
.MyDisplayHeight
;
1497 attr_g
->y
-= pdeltay
;
1498 if (attr_g
->x
!= old_x
|| attr_g
->y
!= old_y
)
1500 reason
->pos
.do_adjust_off_page
= 1;
1503 /* put it where asked, mod title bar */
1504 /* if the gravity is towards the top, move it by the title height */
1510 gravity_get_offsets(fw
->hints
.win_gravity
, &gravx
, &gravy
);
1511 final_g
.x
= attr_g
->x
+ gravx
* fw
->attr_backup
.border_width
;
1512 final_g
.y
= attr_g
->y
+ gravy
* fw
->attr_backup
.border_width
;
1513 /* Virtually all applications seem to share a common bug: they
1514 * request the top left pixel of their *border* as their origin
1515 * instead of the top left pixel of their client window, e.g.
1516 * 'xterm -g +0+0' creates an xterm that tries to map at (0 0)
1517 * although its border (width 1) would not be visible if it ran
1518 * under plain X. It should have tried to map at (1 1)
1519 * instead. This clearly violates the ICCCM, but trying to
1520 * change this is like tilting at windmills. So we have to add
1521 * the border width here. */
1522 final_g
.x
+= fw
->attr_backup
.border_width
;
1523 final_g
.y
+= fw
->attr_backup
.border_width
;
1526 if (mode
== PLACE_INITIAL
)
1528 get_window_borders(fw
, &b
);
1530 fw
->hints
.win_gravity
, &final_g
,
1531 b
.total_size
.width
, b
.total_size
.height
);
1533 attr_g
->x
= final_g
.x
;
1534 attr_g
->y
= final_g
.y
;
1540 /* Handles initial placement and sizing of a new window
1546 * 2 = OK, window must be resized too */
1547 static int __place_window(
1548 const exec_context_t
*exc
, window_style
*pstyle
, rectangle
*attr_g
,
1549 pl_start_style_t start_style
, int mode
,
1550 initial_window_options_t
*win_opts
, pl_reason_t
*reason
)
1553 int is_skipmapping_forbidden
;
1561 extern Bool Restarting
;
1562 FvwmWindow
*fw
= exc
->w
.fw
;
1564 memset(&flags
, 0, sizeof(flags
));
1566 /* Select a desk to put the window on (in list of priority):
1567 * 1. Sticky Windows stay on the current desk.
1568 * 2. Windows specified with StartsOnDesk go where specified
1569 * 3. Put it on the desk it was on before the restart.
1570 * 4. Transients go on the same desk as their parents.
1571 * 5. Window groups stay together (if the KeepWindowGroupsOnDesk style
1574 /* Let's get the StartsOnDesk/Page tests out of the way first. */
1576 SUSE_START_ON_DESK(&pstyle
->flags
) ||
1577 SUSE_START_ON_SCREEN(&pstyle
->flags
))
1579 flags
.do_honor_starts_on_page
= 1;
1580 flags
.do_honor_starts_on_screen
= 1;
1582 * Honor the flag unless...
1583 * it's a restart or recapture, and that option's disallowed...
1585 if (win_opts
->flags
.do_override_ppos
&&
1586 (Restarting
|| (Scr
.flags
.are_windows_captured
)) &&
1587 !SRECAPTURE_HONORS_STARTS_ON_PAGE(&pstyle
->flags
))
1589 flags
.do_honor_starts_on_page
= 0;
1590 flags
.do_honor_starts_on_screen
= 0;
1591 reason
->page
.reason
= PR_PAGE_IGNORE_CAPTURE
;
1592 reason
->page
.do_ignore_starts_on_page
= 1;
1593 reason
->screen
.reason
= PR_PAGE_IGNORE_CAPTURE
;
1596 * it's a cold start window capture, and that's disallowed...
1598 if (win_opts
->flags
.do_override_ppos
&&
1599 (!Restarting
&& !(Scr
.flags
.are_windows_captured
)) &&
1600 !SCAPTURE_HONORS_STARTS_ON_PAGE(&pstyle
->flags
))
1602 flags
.do_honor_starts_on_page
= 0;
1603 flags
.do_honor_starts_on_screen
= 0;
1604 reason
->page
.reason
= PR_PAGE_IGNORE_CAPTURE
;
1605 reason
->page
.do_ignore_starts_on_page
= 1;
1606 reason
->screen
.reason
= PR_PAGE_IGNORE_CAPTURE
;
1609 * it's ActivePlacement and SkipMapping, and that's disallowed.
1611 switch (SPLACEMENT_MODE(&pstyle
->flags
))
1614 case PLACE_MANUAL_B
:
1615 case PLACE_TILEMANUAL
:
1616 is_skipmapping_forbidden
=
1617 !SMANUAL_PLACEMENT_HONORS_STARTS_ON_PAGE(
1621 is_skipmapping_forbidden
= 0;
1624 if (win_opts
->flags
.do_override_ppos
||
1625 !DO_NOT_SHOW_ON_MAP(fw
))
1627 is_skipmapping_forbidden
= 0;
1629 if (is_skipmapping_forbidden
== 1)
1631 flags
.do_honor_starts_on_page
= 0;
1632 reason
->page
.reason
= PR_PAGE_IGNORE_INVALID
;
1633 reason
->page
.do_ignore_starts_on_page
= 1;
1635 WARN
, "__place_window",
1636 "invalid style combination used: StartsOnPage"
1637 "/StartsOnDesk and SkipMapping don't work with"
1638 " ManualPlacement and TileManualPlacement."
1639 " Putting window on current page, please use"
1640 " another placement style or"
1641 " ActivePlacementHonorsStartsOnPage.");
1644 /* get the screen coordinates to place window on */
1645 if (SUSE_START_ON_SCREEN(&pstyle
->flags
))
1647 if (flags
.do_honor_starts_on_screen
)
1649 /* use screen from style */
1651 NULL
, start_style
.screen
, &screen_g
.x
,
1652 &screen_g
.y
, &screen_g
.width
,
1654 reason
->screen
.screen
= start_style
.screen
;
1658 /* use global screen */
1660 NULL
, FSCREEN_GLOBAL
, &screen_g
.x
, &screen_g
.y
,
1661 &screen_g
.width
, &screen_g
.height
);
1662 reason
->screen
.screen
= FSCREEN_GLOBAL
;
1667 /* use current screen */
1669 NULL
, FSCREEN_CURRENT
, &screen_g
.x
, &screen_g
.y
,
1670 &screen_g
.width
, &screen_g
.height
);
1671 reason
->screen
.screen
= FSCREEN_CURRENT
;
1674 if (SPLACEMENT_MODE(&pstyle
->flags
) != PLACE_MINOVERLAPPERCENT
&&
1675 SPLACEMENT_MODE(&pstyle
->flags
) != PLACE_MINOVERLAP
)
1677 EWMH_GetWorkAreaIntersection(
1678 fw
, &screen_g
.x
, &screen_g
.y
, &screen_g
.width
,
1680 SEWMH_PLACEMENT_MODE(&pstyle
->flags
));
1681 reason
->screen
.was_modified_by_ewmh_workingarea
= 1;
1683 reason
->screen
.g
= screen_g
;
1684 /* Don't alter the existing desk location during Capture/Recapture. */
1685 if (!win_opts
->flags
.do_override_ppos
)
1687 fw
->Desk
= Scr
.CurrentDesk
;
1688 reason
->desk
.reason
= PR_DESK_CURRENT
;
1692 reason
->desk
.reason
= PR_DESK_CAPTURE
;
1694 if (S_IS_STICKY_ACROSS_DESKS(SFC(pstyle
->flags
)))
1696 fw
->Desk
= Scr
.CurrentDesk
;
1697 reason
->desk
.reason
= PR_DESK_STICKY
;
1699 else if (SUSE_START_ON_DESK(&pstyle
->flags
) && start_style
.desk
&&
1700 flags
.do_honor_starts_on_page
)
1702 fw
->Desk
= (start_style
.desk
> -1) ?
1703 start_style
.desk
- 1 : start_style
.desk
;
1704 reason
->desk
.reason
= reason
->desk
.sod_reason
;
1708 if ((DO_USE_WINDOW_GROUP_HINT(fw
)) &&
1709 (fw
->wmhints
) && (fw
->wmhints
->flags
& WindowGroupHint
)&&
1710 (fw
->wmhints
->window_group
!= None
) &&
1711 (fw
->wmhints
->window_group
!= Scr
.Root
))
1713 /* Try to find the group leader or another window in
1715 for (t
= Scr
.FvwmRoot
.next
; t
!= NULL
; t
= t
->next
)
1717 if (FW_W(t
) == fw
->wmhints
->window_group
)
1719 /* found the group leader, break out */
1721 reason
->desk
.reason
=
1722 PR_DESK_WINDOW_GROUP_LEADER
;
1725 else if (t
->wmhints
&&
1726 (t
->wmhints
->flags
&
1728 (t
->wmhints
->window_group
==
1729 fw
->wmhints
->window_group
))
1731 /* found a window from the same group,
1732 * but keep looking for the group
1735 reason
->desk
.reason
=
1736 PR_DESK_WINDOW_GROUP_MEMBER
;
1740 if ((IS_TRANSIENT(fw
))&&(FW_W_TRANSIENTFOR(fw
)!=None
)&&
1741 (FW_W_TRANSIENTFOR(fw
) != Scr
.Root
))
1743 /* Try to find the parent's desktop */
1744 for (t
= Scr
.FvwmRoot
.next
; t
!= NULL
; t
= t
->next
)
1746 if (FW_W(t
) == FW_W_TRANSIENTFOR(fw
))
1749 reason
->desk
.reason
=
1757 /* migo - I am not sure this block is ever needed */
1761 unsigned long nitems
, bytes_remain
;
1762 unsigned char *prop
;
1766 dpy
, FW_W(fw
), _XA_WM_DESKTOP
, 0L, 1L,
1767 True
, _XA_WM_DESKTOP
, &atype
, &aformat
,
1768 &nitems
, &bytes_remain
, &prop
) ==
1773 fw
->Desk
= *(unsigned long *)prop
;
1775 reason
->desk
.reason
=
1776 PR_DESK_XPROP_XA_WM_DESKTOP
;
1781 reason
->desk
.desk
= fw
->Desk
;
1782 /* I think it would be good to switch to the selected desk
1783 * whenever a new window pops up, except during initialization */
1784 /* RBW - 11/02/1998 -- I dont. */
1785 if (!win_opts
->flags
.do_override_ppos
&& !DO_NOT_SHOW_ON_MAP(fw
))
1787 if (Scr
.CurrentDesk
!= fw
->Desk
)
1789 reason
->desk
.do_switch_desk
= 1;
1791 goto_desk(fw
->Desk
);
1793 /* Don't move viewport if SkipMapping, or if recapturing the window,
1794 * adjust the coordinates later. Otherwise, just switch to the target
1795 * page - it's ever so much simpler. */
1796 if (S_IS_STICKY_ACROSS_PAGES(SFC(pstyle
->flags
)))
1798 reason
->page
.reason
= PR_PAGE_STICKY
;
1800 else if (SUSE_START_ON_DESK(&pstyle
->flags
))
1802 if (start_style
.page_x
!= 0 && start_style
.page_y
!= 0)
1804 px
= start_style
.page_x
- 1;
1805 py
= start_style
.page_y
- 1;
1806 reason
->page
.reason
= PR_PAGE_STYLE
;
1807 px
*= Scr
.MyDisplayWidth
;
1808 py
*= Scr
.MyDisplayHeight
;
1809 if (!win_opts
->flags
.do_override_ppos
&&
1810 !DO_NOT_SHOW_ON_MAP(fw
))
1812 MoveViewport(px
,py
,True
);
1813 reason
->page
.do_switch_page
= 1;
1815 else if (flags
.do_honor_starts_on_page
)
1817 /* Save the delta from current page */
1818 pdeltax
= Scr
.Vx
- px
;
1819 pdeltay
= Scr
.Vy
- py
;
1820 reason
->page
.do_honor_starts_on_page
= 1;
1825 /* pick a location for the window. */
1826 __place_get_placement_flags(
1827 &flags
, fw
, pstyle
, win_opts
, mode
, reason
);
1828 if (flags
.do_not_use_wm_placement
)
1830 rc
= __place_get_nowm_pos(
1831 exc
, pstyle
, attr_g
, flags
, screen_g
, start_style
,
1832 mode
, win_opts
, reason
, pdeltax
, pdeltay
);
1836 rc
= __place_get_wm_pos(
1837 exc
, pstyle
, attr_g
, flags
, screen_g
, start_style
,
1838 mode
, win_opts
, reason
, pdeltax
, pdeltay
);
1840 reason
->pos
.x
= attr_g
->x
;
1841 reason
->pos
.y
= attr_g
->y
;
1846 static void __place_handle_x_resources(
1847 FvwmWindow
*fw
, window_style
*pstyle
, pl_reason_t
*reason
)
1849 int client_argc
= 0;
1850 char **client_argv
= NULL
;
1852 /* Used to parse command line of clients for specific desk requests. */
1853 /* Todo: check for multiple desks. */
1854 XrmDatabase db
= NULL
;
1855 static XrmOptionDescRec table
[] = {
1856 /* Want to accept "-workspace N" or -xrm "fvwm*desk:N" as
1857 * options to specify the desktop. I have to include dummy
1858 * options that are meaningless since Xrm seems to allow -w to
1859 * match -workspace if there would be no ambiguity. */
1860 {"-workspacf", "*junk", XrmoptionSepArg
, (caddr_t
) NULL
},
1861 {"-workspace", "*desk", XrmoptionSepArg
, (caddr_t
) NULL
},
1862 {"-xrn", NULL
, XrmoptionResArg
, (caddr_t
) NULL
},
1863 {"-xrm", NULL
, XrmoptionResArg
, (caddr_t
) NULL
},
1865 int t1
= -1, t2
= -1, t3
= -1, spargs
= 0;
1867 /* Find out if the client requested a specific desk on the command
1869 * RBW - 11/20/1998 - allow a desk of -1 to work. */
1870 if (XGetCommand(dpy
, FW_W(fw
), &client_argv
, &client_argc
) == 0)
1874 if (client_argc
<= 0 || client_argv
== NULL
)
1878 /* Get global X resources */
1879 MergeXResources(dpy
, &db
, False
);
1880 /* command line takes precedence over all */
1881 MergeCmdLineResources(
1882 &db
, table
, 4, client_argv
[0], &client_argc
, client_argv
,
1884 /* parse the database values */
1885 if (GetResourceString(db
, "desk", client_argv
[0], &rm_value
) &&
1888 SGET_START_DESK(*pstyle
) = atoi(rm_value
.addr
);
1889 /* RBW - 11/20/1998 */
1890 if (SGET_START_DESK(*pstyle
) > -1)
1893 *pstyle
, SGET_START_DESK(*pstyle
) + 1);
1895 reason
->desk
.sod_reason
= PR_DESK_X_RESOURCE_DESK
;
1896 pstyle
->flags
.use_start_on_desk
= 1;
1898 if (GetResourceString(db
, "fvwmscreen", client_argv
[0], &rm_value
) &&
1902 *pstyle
, FScreenGetScreenArgument(rm_value
.addr
, 'c'));
1903 reason
->screen
.reason
= PR_SCREEN_X_RESOURCE_FVWMSCREEN
;
1904 reason
->screen
.screen
= SGET_START_SCREEN(*pstyle
);
1905 pstyle
->flags
.use_start_on_screen
= 1;
1907 if (GetResourceString(db
, "page", client_argv
[0], &rm_value
) &&
1911 rm_value
.addr
, "%d %d %d", &t1
, &t2
, &t3
);
1915 pstyle
->flags
.use_start_on_desk
= 1;
1916 SSET_START_DESK(*pstyle
, (t1
> -1) ? t1
+ 1 : t1
);
1917 reason
->desk
.sod_reason
= PR_DESK_X_RESOURCE_PAGE
;
1920 pstyle
->flags
.use_start_on_desk
= 1;
1921 SSET_START_PAGE_X(*pstyle
, (t1
> -1) ? t1
+ 1 : t1
);
1922 SSET_START_PAGE_Y(*pstyle
, (t2
> -1) ? t2
+ 1 : t2
);
1923 reason
->page
.reason
= PR_PAGE_X_RESOURCE_PAGE
;
1924 reason
->page
.px
= SGET_START_PAGE_X(*pstyle
);
1925 reason
->page
.py
= SGET_START_PAGE_Y(*pstyle
);
1928 pstyle
->flags
.use_start_on_desk
= 1;
1929 SSET_START_DESK(*pstyle
, (t1
> -1) ? t1
+ 1 : t1
);
1930 reason
->desk
.sod_reason
=
1931 PR_DESK_X_RESOURCE_PAGE
;
1932 SSET_START_PAGE_X(*pstyle
, (t2
> -1) ? t2
+ 1 : t2
);
1933 SSET_START_PAGE_Y(*pstyle
, (t3
> -1) ? t3
+ 1 : t3
);
1934 reason
->page
.reason
= PR_PAGE_X_RESOURCE_PAGE
;
1935 reason
->page
.px
= SGET_START_PAGE_X(*pstyle
);
1936 reason
->page
.py
= SGET_START_PAGE_Y(*pstyle
);
1942 XFreeStringList(client_argv
);
1943 XrmDestroyDatabase(db
);
1948 static void __explain_placement(FvwmWindow
*fw
, pl_reason_t
*reason
)
1950 char explanation
[2048];
1955 int is_placed_by_algo
;
1959 strcat(s
, "placed new window 0x%x '%s':\n");
1962 s
, " initial size %dx%d\n", fw
->g
.frame
.width
,
1963 fw
->g
.frame
.height
);
1965 switch (reason
->desk
.reason
)
1967 case PR_DESK_CURRENT
:
1971 r
= "specified by style";
1973 case PR_DESK_X_RESOURCE_DESK
:
1974 r
= "specified by 'desk' X resource";
1976 case PR_DESK_X_RESOURCE_PAGE
:
1977 r
= "specified by 'page' X resource";
1979 case PR_DESK_CAPTURE
:
1980 r
= "window was (re)captured";
1982 case PR_DESK_STICKY
:
1983 r
= "window is sticky";
1985 case PR_DESK_WINDOW_GROUP_LEADER
:
1986 r
= "same desk as window group leader";
1988 case PR_DESK_WINDOW_GROUP_MEMBER
:
1989 r
= "same desk as window group member";
1991 case PR_DESK_TRANSIENT
:
1992 r
= "transient window placed on same desk as parent";
1994 case PR_DESK_XPROP_XA_WM_DESKTOP
:
1995 r
= "specified by _XA_WM_DESKTOP property";
2001 sprintf(s
, " desk %d (%s)\n", reason
->desk
.desk
, r
);
2003 if (reason
->desk
.do_switch_desk
== 1)
2005 sprintf(s
, " (switched to desk)\n");
2010 switch (reason
->page
.reason
)
2012 case PR_PAGE_CURRENT
:
2017 r
= "specified by style";
2019 case PR_PAGE_X_RESOURCE_PAGE
:
2020 r
= "specified by 'page' X resource";
2022 case PR_PAGE_IGNORE_CAPTURE
:
2023 r
= "window was (re)captured";
2025 case PR_PAGE_IGNORE_INVALID
:
2026 r
= "requested page ignored because of invalid style"
2029 case PR_PAGE_STICKY
:
2031 r
= "current page (window is sticky)";
2037 if (do_show_page
== 0)
2039 sprintf(s
, " %s\n", r
);
2044 s
, " page %d %d (%s)\n", reason
->page
.px
- 1,
2045 reason
->page
.py
- 1, r
);
2048 if (reason
->page
.do_switch_page
== 1)
2050 sprintf(s
, " (switched to page)\n");
2053 if (reason
->page
.do_ignore_starts_on_page
== 1)
2055 sprintf(s
, " (possibly ignored StartsOnPage)\n");
2059 if (FScreenIsEnabled() == True
|| FScreenIsSLSEnabled() == True
)
2061 switch (reason
->screen
.reason
)
2063 case PR_SCREEN_CURRENT
:
2064 r
= "current screen";
2066 case PR_SCREEN_STYLE
:
2067 r
= "specified by style";
2069 case PR_SCREEN_X_RESOURCE_FVWMSCREEN
:
2070 r
= "specified by 'fvwmscreen' X resource";
2072 case PR_SCREEN_IGNORE_CAPTURE
:
2073 r
= "window was (re)captured";
2079 FScreenSpecToString(t
, 32, reason
->screen
.screen
);
2081 s
, " screen: %s: %d %d %dx%d (%s)\n",
2082 t
, reason
->screen
.g
.x
, reason
->screen
.g
.y
,
2083 reason
->screen
.g
.width
, reason
->screen
.g
.height
, r
);
2085 if (reason
->screen
.was_modified_by_ewmh_workingarea
== 1)
2088 s
, " (screen area modified by EWMH working"
2094 is_placed_by_algo
= 0;
2095 switch (reason
->pos
.reason
)
2098 is_placed_by_algo
= 1;
2099 r
= "normal placement";
2101 case PR_POS_IGNORE_PPOS
:
2102 is_placed_by_algo
= 1;
2103 r
= "ignored program specified position";
2105 case PR_POS_USE_PPOS
:
2106 r
= "used program specified position";
2108 case PR_POS_IGNORE_USPOS
:
2109 is_placed_by_algo
= 1;
2110 r
= "ignored user specified position";
2112 case PR_POS_USE_USPOS
:
2113 r
= "used user specified position";
2115 case PR_POS_PLACE_AGAIN
:
2116 is_placed_by_algo
= 1;
2117 r
= "by PlaceAgain command";
2119 case PR_POS_CAPTURE
:
2120 r
= "window was (re)captured";
2122 case PR_POS_USPOS_OVERRIDE_SOS
:
2123 r
= "StartsOnPage style overridden by application via USPos";
2129 sprintf(s
, " position %d %d", reason
->pos
.x
, reason
->pos
.y
);
2131 if (is_placed_by_algo
== 1)
2137 switch (reason
->pos
.algo
)
2139 case PLACE_POSITION
:
2140 a
= "Position args: ";
2141 b
= reason
->pos
.pl_position_string
;
2143 case PLACE_TILEMANUAL
:
2147 case PLACE_MANUAL_B
:
2150 case PLACE_MINOVERLAPPERCENT
:
2151 a
= "MinOverlapPercent";
2153 case PLACE_TILECASCADE
:
2157 case PLACE_CASCADE_B
:
2160 case PLACE_MINOVERLAP
:
2167 sprintf(s
, ", placed by fvwm (%s)\n", r
);
2169 sprintf(s
, " placement method: %s%s\n", a
, b
);
2171 if (reason
->pos
.do_not_manual_icon_placement
== 1)
2173 sprintf(s
, " (icon not placed manually)\n");
2176 if (reason
->pos
.is_pl_position_string_invalid
== 1)
2178 sprintf(s
, " (invalid position string)\n");
2181 if (reason
->pos
.has_tile_failed
== 1)
2183 sprintf(s
, " (tile placement failed)\n");
2186 if (reason
->pos
.has_manual_failed
== 1)
2188 sprintf(s
, " (manual placement failed)\n");
2191 if (reason
->pos
.has_placement_failed
== 1)
2193 sprintf(s
, " (placement failed default pos 0 0)\n");
2199 sprintf(s
, " (%s)\n", r
);
2202 if (reason
->pos
.do_adjust_off_screen
== 1)
2204 sprintf(s
, " (adjusted to force window on screen)\n");
2207 if (reason
->pos
.do_adjust_off_page
== 1)
2209 sprintf(s
, " (adjusted to force window on page)\n");
2213 INFO
, "__explain_placement", explanation
, (int)FW_W(fw
),
2219 /* ---------------------------- interface functions ------------------------ */
2221 Bool
setup_window_placement(
2222 FvwmWindow
*fw
, window_style
*pstyle
, rectangle
*attr_g
,
2223 initial_window_options_t
*win_opts
, placement_mode_t mode
)
2226 const exec_context_t
*exc
;
2227 exec_context_changes_t ecc
;
2229 pl_start_style_t start_style
;
2231 memset(&reason
, 0, sizeof(reason
));
2232 if (pstyle
->flags
.use_start_on_desk
)
2234 reason
.desk
.sod_reason
= PR_DESK_STYLE
;
2235 reason
.page
.px
= SGET_START_PAGE_X(*pstyle
);
2236 reason
.page
.py
= SGET_START_PAGE_Y(*pstyle
);
2238 if (pstyle
->flags
.use_start_on_screen
)
2240 reason
.screen
.reason
= PR_SCREEN_STYLE
;
2241 reason
.screen
.screen
= SGET_START_SCREEN(*pstyle
);
2243 __place_handle_x_resources(fw
, pstyle
, &reason
);
2244 if (pstyle
->flags
.do_start_iconic
)
2246 win_opts
->initial_state
= IconicState
;
2248 ecc
.type
= EXCT_NULL
;
2250 exc
= exc_create_context(&ecc
, ECC_TYPE
| ECC_FW
);
2251 start_style
.desk
= SGET_START_DESK(*pstyle
);
2252 start_style
.page_x
= SGET_START_PAGE_X(*pstyle
);
2253 start_style
.page_y
= SGET_START_PAGE_Y(*pstyle
);
2254 start_style
.screen
= SGET_START_SCREEN(*pstyle
);
2255 rc
= __place_window(
2256 exc
, pstyle
, attr_g
, start_style
, mode
, win_opts
, &reason
);
2257 exc_destroy_context(exc
);
2258 if (Scr
.bo
.do_explain_window_placement
== 1)
2260 __explain_placement(fw
, &reason
);
2263 return (rc
== 0) ? False
: True
;
2266 /* ---------------------------- builtin commands --------------------------- */
2268 void CMD_PlaceAgain(F_CMD_ARGS
)
2272 float noMovement
[1] = {1.0};
2273 float *ppctMovement
= noMovement
;
2275 XWindowAttributes attr
;
2276 Bool do_move_animated
= False
;
2277 Bool do_place_icon
= False
;
2278 FvwmWindow
* const fw
= exc
->w
.fw
;
2280 if (!XGetWindowAttributes(dpy
, FW_W(fw
), &attr
))
2284 while ((token
= PeekToken(action
, &action
)) != NULL
)
2286 if (StrEquals("Anim", token
))
2288 ppctMovement
= NULL
;
2289 do_move_animated
= True
;
2291 else if (StrEquals("icon", token
))
2293 do_place_icon
= True
;
2296 old_desk
= fw
->Desk
;
2297 if (IS_ICONIFIED(fw
) && !do_place_icon
)
2301 if (IS_ICONIFIED(fw
) && do_place_icon
)
2306 if (IS_ICON_SUPPRESSED(fw
))
2310 fw
->Desk
= Scr
.CurrentDesk
;
2311 get_icon_geometry(fw
, &old_g
);
2312 SET_ICON_MOVED(fw
, 0);
2313 AutoPlaceIcon(fw
, NULL
, False
);
2314 get_icon_geometry(fw
, &new_g
);
2316 fw
, new_g
.x
, new_g
.y
, old_g
.x
, old_g
.y
,
2317 do_move_animated
, False
);
2322 initial_window_options_t win_opts
;
2324 memset(&win_opts
, 0, sizeof(win_opts
));
2325 lookup_style(fw
, &style
);
2328 attr_g
.width
= attr
.width
;
2329 attr_g
.height
= attr
.height
;
2331 setup_window_placement(
2332 exc
->w
.fw
, &style
, &attr_g
, &win_opts
, PLACE_AGAIN
);
2333 AnimatedMoveFvwmWindow(
2334 fw
, FW_W_FRAME(fw
), -1, -1, attr_g
.x
, attr_g
.y
, False
,
2337 if (fw
->Desk
!= old_desk
)
2339 int new_desk
= fw
->Desk
;
2341 fw
->Desk
= old_desk
;
2342 do_move_window_to_desk(fw
, new_desk
);