Skip to content

Commit 11bc754

Browse files
committed
improve window positioning when dragging floating windows
1 parent 559c7aa commit 11bc754

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/gridwm/mod.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,16 +1314,27 @@ impl GridWM {
13141314
self.get_toplevel(event.subwindow)
13151315
};
13161316

1317-
self.floating_windows.insert(win);
1317+
let attr = self.get_window_attributes(win);
13181318

1319-
self.layout();
1319+
let mut new_x = attr.x;
1320+
let mut new_y = attr.y;
13201321

1321-
let attr = self.get_window_attributes(win);
1322+
if self.floating_windows.insert(win) {
1323+
let new_width = (self.screen_width as f32 * 0.5) as u32;
1324+
let new_height = (self.screen_height as f32 * 0.5) as u32;
1325+
1326+
new_x = event.x_root - (new_width / 2) as i32;
1327+
new_y = event.y_root - (new_height / 2) as i32;
1328+
1329+
self.move_resize_window(win, new_x, new_y, new_width, new_height);
1330+
}
1331+
1332+
self.layout();
13221333

13231334
self.drag_state = Some(DragState {
13241335
window: win,
1325-
start_win_x: attr.x,
1326-
start_win_y: attr.y,
1336+
start_win_x: new_x,
1337+
start_win_y: new_y,
13271338
start_mouse_x: event.x_root,
13281339
start_mouse_y: event.y_root,
13291340
});

0 commit comments

Comments
 (0)