@@ -14,15 +14,19 @@ impl WaylandState {
1414 let top_size = top_size ( snapshot) ;
1515 let side_start_y = Self :: SIDE_BASE_MARGIN_TOP + self . data . toolbar_side_offset ;
1616 let top_bottom_y = Self :: INLINE_TOP_Y + self . data . toolbar_top_offset_y + top_size. 1 as f64 ;
17- let side_overlaps_top = side_visible && side_start_y < top_bottom_y;
1817 let base = Self :: INLINE_SIDE_X + self . data . toolbar_side_offset_x ;
1918 // When dragging the side toolbar, don't push the top bar; keep its base stable so it
2019 // doesn't shift while moving the side bar.
21- if side_overlaps_top && self . active_move_drag_kind ( ) != Some ( MoveDragKind :: Side ) {
22- base + side_size. 0 as f64 + Self :: INLINE_TOP_PUSH
23- } else {
24- base
25- }
20+ let allow_push = self . active_move_drag_kind ( ) != Some ( MoveDragKind :: Side ) ;
21+ geometry:: compute_inline_top_base_x (
22+ base,
23+ side_visible,
24+ side_size. 0 as f64 ,
25+ side_start_y,
26+ top_bottom_y,
27+ Self :: INLINE_TOP_PUSH ,
28+ allow_push,
29+ )
2630 }
2731
2832 pub ( super ) fn inline_top_base_y ( & self ) -> f64 {
@@ -66,39 +70,36 @@ impl WaylandState {
6670 let top_base_x = self . inline_top_base_x ( snapshot) ;
6771 let top_base_y = self . inline_top_base_y ( ) ;
6872
69- let mut max_top_x = ( width - top_w as f64 - top_base_x - Self :: TOP_MARGIN_RIGHT ) . max ( 0.0 ) ;
70- let mut max_top_y = ( height - top_h as f64 - top_base_y - Self :: TOP_MARGIN_BOTTOM ) . max ( 0.0 ) ;
71- let mut max_side_y =
72- ( height - side_h as f64 - Self :: SIDE_BASE_MARGIN_TOP - Self :: SIDE_MARGIN_BOTTOM )
73- . max ( 0.0 ) ;
74- let mut max_side_x =
75- ( width - side_w as f64 - Self :: SIDE_BASE_MARGIN_LEFT - Self :: SIDE_MARGIN_RIGHT )
76- . max ( 0.0 ) ;
77-
78- // Ensure max bounds remain non-negative.
79- max_top_x = max_top_x. max ( 0.0 ) ;
80- max_top_y = max_top_y. max ( 0.0 ) ;
81- max_side_x = max_side_x. max ( 0.0 ) ;
82- max_side_y = max_side_y. max ( 0.0 ) ;
83-
84- // Allow negative offsets so toolbars can reach screen edges by cancelling base margins
85- let min_top_x = -top_base_x;
86- let min_top_y = -top_base_y;
87- let min_side_x = -Self :: SIDE_BASE_MARGIN_LEFT ;
88- let min_side_y = -Self :: SIDE_BASE_MARGIN_TOP ;
89-
9073 let before_top = ( self . data . toolbar_top_offset , self . data . toolbar_top_offset_y ) ;
9174 let before_side = (
9275 self . data . toolbar_side_offset_x ,
9376 self . data . toolbar_side_offset ,
9477 ) ;
95- self . data . toolbar_top_offset = self . data . toolbar_top_offset . clamp ( min_top_x, max_top_x) ;
96- self . data . toolbar_top_offset_y = self . data . toolbar_top_offset_y . clamp ( min_top_y, max_top_y) ;
97- self . data . toolbar_side_offset = self . data . toolbar_side_offset . clamp ( min_side_y, max_side_y) ;
98- self . data . toolbar_side_offset_x = self
99- . data
100- . toolbar_side_offset_x
101- . clamp ( min_side_x, max_side_x) ;
78+ let input = geometry:: ToolbarClampInput {
79+ width,
80+ height,
81+ top_size : ( top_w, top_h) ,
82+ side_size : ( side_w, side_h) ,
83+ top_base_x,
84+ top_base_y,
85+ top_margin_right : Self :: TOP_MARGIN_RIGHT ,
86+ top_margin_bottom : Self :: TOP_MARGIN_BOTTOM ,
87+ side_base_margin_left : Self :: SIDE_BASE_MARGIN_LEFT ,
88+ side_base_margin_top : Self :: SIDE_BASE_MARGIN_TOP ,
89+ side_margin_right : Self :: SIDE_MARGIN_RIGHT ,
90+ side_margin_bottom : Self :: SIDE_MARGIN_BOTTOM ,
91+ } ;
92+ let offsets = geometry:: ToolbarOffsets {
93+ top_x : self . data . toolbar_top_offset ,
94+ top_y : self . data . toolbar_top_offset_y ,
95+ side_x : self . data . toolbar_side_offset_x ,
96+ side_y : self . data . toolbar_side_offset ,
97+ } ;
98+ let ( clamped, bounds) = geometry:: clamp_toolbar_offsets ( offsets, input) ;
99+ self . data . toolbar_top_offset = clamped. top_x ;
100+ self . data . toolbar_top_offset_y = clamped. top_y ;
101+ self . data . toolbar_side_offset_x = clamped. side_x ;
102+ self . data . toolbar_side_offset = clamped. side_y ;
102103 drag_log ( format ! (
103104 "clamp offsets: before=({:.3}, {:.3})/({:.3}, {:.3}), after=({:.3}, {:.3})/({:.3}, {:.3}), max=({:.3}, {:.3})/({:.3}, {:.3}), size=({}, {}), top_base_x={:.3}, top_base_y={:.3}" ,
104105 before_top. 0 ,
@@ -109,10 +110,10 @@ impl WaylandState {
109110 self . data. toolbar_top_offset_y,
110111 self . data. toolbar_side_offset_x,
111112 self . data. toolbar_side_offset,
112- max_top_x,
113- max_top_y,
114- max_side_x,
115- max_side_y,
113+ bounds . max_top_x,
114+ bounds . max_top_y,
115+ bounds . max_side_x,
116+ bounds . max_side_y,
116117 width,
117118 height,
118119 top_base_x,
@@ -156,13 +157,19 @@ impl WaylandState {
156157 let _ = self . clamp_toolbar_offsets ( snapshot) ;
157158 if self . layer_shell . is_some ( ) {
158159 let top_base_x = self . inline_top_base_x ( snapshot) ;
159- let top_margin_left = ( top_base_x + self . data . toolbar_top_offset ) . round ( ) as i32 ;
160- let top_margin_top =
161- ( Self :: TOP_BASE_MARGIN_TOP + self . data . toolbar_top_offset_y ) . round ( ) as i32 ;
162- let side_margin_top =
163- ( Self :: SIDE_BASE_MARGIN_TOP + self . data . toolbar_side_offset ) . round ( ) as i32 ;
164- let side_margin_left =
165- ( Self :: SIDE_BASE_MARGIN_LEFT + self . data . toolbar_side_offset_x ) . round ( ) as i32 ;
160+ let ( top_margin_left, top_margin_top, side_margin_top, side_margin_left) =
161+ geometry:: compute_layer_margins (
162+ top_base_x,
163+ Self :: TOP_BASE_MARGIN_TOP ,
164+ Self :: SIDE_BASE_MARGIN_LEFT ,
165+ Self :: SIDE_BASE_MARGIN_TOP ,
166+ geometry:: ToolbarOffsets {
167+ top_x : self . data . toolbar_top_offset ,
168+ top_y : self . data . toolbar_top_offset_y ,
169+ side_x : self . data . toolbar_side_offset_x ,
170+ side_y : self . data . toolbar_side_offset ,
171+ } ,
172+ ) ;
166173 drag_log ( format ! (
167174 "apply_toolbar_offsets: top_margin_left={}, top_margin_top={}, side_margin_top={}, side_margin_left={}, offsets=({}, {})/({}, {}), scale={}, top_base_x={}" ,
168175 top_margin_left,
0 commit comments