Allow mouse movements to trigger SnapToEdge

This commit is contained in:
Consolatis 2022-01-08 11:25:18 +01:00 committed by Johan Malm
parent 4e3a03586a
commit 87f4a60e38
5 changed files with 53 additions and 2 deletions

View file

@ -76,7 +76,36 @@ void
interactive_end(struct view *view)
{
if (view->server->grabbed_view == view) {
bool should_snap = view->server->input_mode == LAB_INPUT_STATE_MOVE
&& rc.snap_edge_range;
view->server->input_mode = LAB_INPUT_STATE_PASSTHROUGH;
view->server->grabbed_view = NULL;
if (should_snap) {
int snap_range = rc.snap_edge_range;
struct wlr_box *area = &view->output->usable_area;
/* Translate into output local coordinates */
double cursor_x = view->server->seat.cursor->x;
double cursor_y = view->server->seat.cursor->y;
wlr_output_layout_output_coords(view->server->output_layout,
view->output->wlr_output, &cursor_x, &cursor_y);
if (cursor_x <= area->x + snap_range) {
view_snap_to_edge(view, "left");
} else if (cursor_x >= area->x + area->width - snap_range) {
view_snap_to_edge(view, "right");
} else if (cursor_y <= area->y + snap_range) {
if (rc.snap_top_maximize) {
view_maximize(view, true);
/* When unmaximizing later on restore original position */
view->unmaximized_geometry.x = view->server->grab_box.x;
view->unmaximized_geometry.y = view->server->grab_box.y;
} else {
view_snap_to_edge(view, "up");
}
} else if (cursor_y >= area->y + area->height - snap_range) {
view_snap_to_edge(view, "down");
}
}
}
}