@@ -58,6 +58,7 @@ pub struct ResizeSurfaceGrab {
58
58
window : CosmicMapped ,
59
59
edges : ResizeEdge ,
60
60
output : Output ,
61
+ initial_window_location : Point < i32 , Local > ,
61
62
initial_window_size : Size < i32 , Logical > ,
62
63
last_window_size : Size < i32 , Logical > ,
63
64
release : ReleaseMode ,
@@ -91,6 +92,25 @@ impl ResizeSurfaceGrab {
91
92
}
92
93
93
94
new_window_width = ( self . initial_window_size . w as f64 + dx) as i32 ;
95
+
96
+ // If the resizing vertical edge is close to our output's edge in the same direction, snap to it.
97
+ let output_geom = self . output . geometry ( ) . to_local ( & self . output ) ;
98
+ if self . edges . intersects ( ResizeEdge :: LEFT ) {
99
+ if ( self . initial_window_location . x - dx as i32 - output_geom. loc . x ) . abs ( ) < 10 {
100
+ new_window_width = self . initial_window_size . w - output_geom. loc . x
101
+ + self . initial_window_location . x ;
102
+ }
103
+ } else {
104
+ if ( self . initial_window_location . x + self . initial_window_size . w + dx as i32
105
+ - output_geom. loc . x
106
+ - output_geom. size . w )
107
+ . abs ( )
108
+ < 10
109
+ {
110
+ new_window_width =
111
+ output_geom. loc . x - self . initial_window_location . x + output_geom. size . w ;
112
+ }
113
+ }
94
114
}
95
115
96
116
if self . edges . intersects ( top_bottom) {
@@ -99,6 +119,25 @@ impl ResizeSurfaceGrab {
99
119
}
100
120
101
121
new_window_height = ( self . initial_window_size . h as f64 + dy) as i32 ;
122
+
123
+ // If the resizing horizontal edge is close to our output's edge in the same direction, snap to it.
124
+ let output_geom = self . output . geometry ( ) . to_local ( & self . output ) ;
125
+ if self . edges . intersects ( ResizeEdge :: TOP ) {
126
+ if ( self . initial_window_location . y - dy as i32 - output_geom. loc . y ) . abs ( ) < 10 {
127
+ new_window_height = self . initial_window_size . h - output_geom. loc . y
128
+ + self . initial_window_location . y ;
129
+ }
130
+ } else {
131
+ if ( self . initial_window_location . y + self . initial_window_size . h + dy as i32
132
+ - output_geom. loc . y
133
+ - output_geom. size . h )
134
+ . abs ( )
135
+ < 10
136
+ {
137
+ new_window_height =
138
+ output_geom. loc . y - self . initial_window_location . y + output_geom. size . h ;
139
+ }
140
+ }
102
141
}
103
142
104
143
let ( min_size, max_size) = ( self . window . min_size ( ) , self . window . max_size ( ) ) ;
@@ -414,6 +453,7 @@ impl ResizeSurfaceGrab {
414
453
window : mapped,
415
454
edges,
416
455
output,
456
+ initial_window_location,
417
457
initial_window_size,
418
458
last_window_size : initial_window_size,
419
459
release,
0 commit comments