From b313a242c24637484a68c29ee679f45432d85bb7 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Tue, 7 Mar 2023 11:16:45 -0600 Subject: wayland: use correct x/y coordinates for the cursor While adding fractional scale support, the coordinates for wayland changed to always include the scaling parameter. The pointer stuff actually did too. However, the check_for_resize function used the unscaled, local surface coordinates. Likely, it was neccesary at the time since wl->geometry used to report unscaled coordinates. In light of that, we can just simply use mouse_x/y instead for this function to make it work correctly with the right/bottom edges. mouse_unscaled becomes completely unneccesary, so just drop it. Some minor style changes included just because. --- video/out/wayland_common.c | 24 +++++++++++------------- video/out/wayland_common.h | 2 -- 2 files changed, 11 insertions(+), 15 deletions(-) (limited to 'video/out') diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 664afd3d44..bb1a5e672f 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -171,8 +171,8 @@ struct vo_wayland_output { struct wl_list link; }; -static int check_for_resize(struct vo_wayland_state *wl, wl_fixed_t x_w, wl_fixed_t y_w, - int edge_pixels, enum xdg_toplevel_resize_edge *edge); +static int check_for_resize(struct vo_wayland_state *wl, int edge_pixels, + enum xdg_toplevel_resize_edge *edge); static int get_mods(struct vo_wayland_state *wl); static int lookupkey(int key); static int set_cursor_visibility(struct vo_wayland_state *wl, bool on); @@ -218,8 +218,6 @@ static void pointer_handle_motion(void *data, struct wl_pointer *pointer, wl->mouse_x = wl_fixed_to_int(sx) * wl->scaling; wl->mouse_y = wl_fixed_to_int(sy) * wl->scaling; - wl->mouse_unscaled_x = sx; - wl->mouse_unscaled_y = sy; if (!wl->toplevel_configured) mp_input_set_mouse_pos(wl->vo->input_ctx, wl->mouse_x, wl->mouse_y); @@ -269,15 +267,15 @@ static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, if (!mp_input_test_dragging(wl->vo->input_ctx, wl->mouse_x, wl->mouse_y) && (!wl->vo_opts->fullscreen) && (!wl->vo_opts->window_maximized) && - (button == MP_MBTN_LEFT) && (state == MP_KEY_STATE_DOWN)) { + (button == MP_MBTN_LEFT) && (state == MP_KEY_STATE_DOWN)) + { uint32_t edges; // Implement an edge resize zone if there are no decorations - if (!wl->vo_opts->border && - check_for_resize(wl, wl->mouse_unscaled_x, wl->mouse_unscaled_y, - wl->opts->edge_pixels_pointer, &edges)) + if (!wl->vo_opts->border && check_for_resize(wl, wl->opts->edge_pixels_pointer, &edges)) { xdg_toplevel_resize(wl->xdg_toplevel, wl->seat, serial, edges); - else + } else { window_move(wl, serial); + } // Explictly send an UP event after the client finishes a move/resize mp_input_put_key(wl->vo->input_ctx, button | MP_KEY_STATE_UP); } @@ -324,7 +322,7 @@ static void touch_handle_down(void *data, struct wl_touch *wl_touch, enum xdg_toplevel_resize_edge edge; if (!mp_input_test_dragging(wl->vo->input_ctx, wl->mouse_x, wl->mouse_y)) { - if (check_for_resize(wl, x_w, y_w, wl->opts->edge_pixels_touch, &edge)) { + if (check_for_resize(wl, wl->opts->edge_pixels_touch, &edge)) { xdg_toplevel_resize(wl->xdg_toplevel, wl->seat, serial, edge); } else { xdg_toplevel_move(wl->xdg_toplevel, wl->seat, serial); @@ -1374,13 +1372,13 @@ end: } } -static int check_for_resize(struct vo_wayland_state *wl, wl_fixed_t x_w, wl_fixed_t y_w, - int edge_pixels, enum xdg_toplevel_resize_edge *edge) +static int check_for_resize(struct vo_wayland_state *wl, int edge_pixels, + enum xdg_toplevel_resize_edge *edge) { if (wl->vo_opts->fullscreen || wl->vo_opts->window_maximized) return 0; - int pos[2] = { wl_fixed_to_double(x_w), wl_fixed_to_double(y_w) }; + int pos[2] = { wl->mouse_x, wl->mouse_y }; int left_edge = pos[0] < edge_pixels; int top_edge = pos[1] < edge_pixels; int right_edge = pos[0] > (mp_rect_w(wl->geometry) - edge_pixels); diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h index c9921cc60b..d22e91d5e5 100644 --- a/video/out/wayland_common.h +++ b/video/out/wayland_common.h @@ -75,8 +75,6 @@ struct vo_wayland_state { bool state_change; bool toplevel_configured; int display_fd; - int mouse_unscaled_x; - int mouse_unscaled_y; int mouse_x; int mouse_y; int pending_vo_events; -- cgit v1.2.3