From 54cd2236c41db53220fa6b6968c0ac6d0adb9000 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 12 Jul 2017 09:08:49 -0400 Subject: [PATCH] Merge pull request #1272 from ascent12/pointer-fix Use WLC v2 pointer interface --- include/sway/input_state.h | 2 +- sway/commands/move.c | 8 ++++---- sway/container.c | 6 ++++-- sway/handlers.c | 37 ++++++++++++++++++------------------- sway/input_state.c | 33 +++++++++++++++------------------ 5 files changed, 42 insertions(+), 44 deletions(-) diff --git a/include/sway/input_state.h b/include/sway/input_state.h index 903301fb..fd5a3a25 100644 --- a/include/sway/input_state.h +++ b/include/sway/input_state.h @@ -69,7 +69,7 @@ enum modifier_state { MOD_STATE_RELEASED = 2 }; -void pointer_position_set(struct wlc_origin *new_origin, bool force_focus); +void pointer_position_set(double new_x, double new_y, bool force_focus); void center_pointer_on(swayc_t *view); // on button release unset mode depending on the button. diff --git a/sway/commands/move.c b/sway/commands/move.c index a38687c1..00b57103 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -161,11 +161,11 @@ struct cmd_results *cmd_move(int argc, char **argv) { wlc_view_get_visible_geometry(view->handle, &g); const struct wlc_size *size = wlc_output_get_resolution(output->handle); - struct wlc_point origin; - wlc_pointer_get_position(&origin); + double x_pos, y_pos; + wlc_pointer_get_position_v2(&x_pos, &y_pos); - int32_t x = origin.x - g.size.w / 2; - int32_t y = origin.y - g.size.h / 2; + int32_t x = x_pos - g.size.w / 2; + int32_t y = y_pos - g.size.h / 2; uint32_t w = size->w - g.size.w; uint32_t h = size->h - g.size.h; diff --git a/sway/container.c b/sway/container.c index 358ba767..125e1e3d 100644 --- a/sway/container.c +++ b/sway/container.c @@ -707,8 +707,10 @@ swayc_t *container_under_pointer(void) { if (lookup->children && !lookup->unmanaged) { return NULL; } - struct wlc_point origin; - wlc_pointer_get_position(&origin); + double x, y; + wlc_pointer_get_position_v2(&x, &y); + struct wlc_point origin = { .x = x, .y = y }; + while (lookup && lookup->type != C_VIEW) { int i; int len; diff --git a/sway/handlers.c b/sway/handlers.c index 052789ca..5fae2f7a 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -842,12 +842,13 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier return EVENT_PASSTHROUGH; } -static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_point *origin) { +static bool handle_pointer_motion(wlc_handle handle, uint32_t time, double x, double y) { if (desktop_shell.is_locked) { return EVENT_PASSTHROUGH; } - struct wlc_point new_origin = *origin; + double new_x = x; + double new_y = y; // Switch to adjacent output if touching output edge. // // Since this doesn't currently support moving windows between outputs we @@ -856,45 +857,43 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct !pointer_state.left.held && !pointer_state.right.held && !pointer_state.scroll.held) { swayc_t *output = swayc_active_output(), *adjacent = NULL; - struct wlc_point abs_pos = *origin; - abs_pos.x += output->x; - abs_pos.y += output->y; - if (origin->x == 0) { // Left edge + struct wlc_point abs_pos = { .x = x + output->x, .y = y + output->y }; + if (x <= 0) { // Left edge if ((adjacent = swayc_adjacent_output(output, MOVE_LEFT, &abs_pos, false))) { if (workspace_switch(swayc_active_workspace_for(adjacent))) { - new_origin.x = adjacent->width; + new_x = adjacent->width; // adjust for differently aligned outputs (well, this is // only correct when the two outputs have the same // resolution or the same dpi I guess, it should take // physical attributes into account) - new_origin.y += (output->y - adjacent->y); + new_y += (output->y - adjacent->y); } } - } else if ((double)origin->x == output->width) { // Right edge + } else if (x >= output->width) { // Right edge if ((adjacent = swayc_adjacent_output(output, MOVE_RIGHT, &abs_pos, false))) { if (workspace_switch(swayc_active_workspace_for(adjacent))) { - new_origin.x = 0; - new_origin.y += (output->y - adjacent->y); + new_x = 0; + new_y += (output->y - adjacent->y); } } - } else if (origin->y == 0) { // Top edge + } else if (y <= 0) { // Top edge if ((adjacent = swayc_adjacent_output(output, MOVE_UP, &abs_pos, false))) { if (workspace_switch(swayc_active_workspace_for(adjacent))) { - new_origin.y = adjacent->height; - new_origin.x += (output->x - adjacent->x); + new_y = adjacent->height; + new_x += (output->x - adjacent->x); } } - } else if ((double)origin->y == output->height) { // Bottom edge + } else if (y >= output->height) { // Bottom edge if ((adjacent = swayc_adjacent_output(output, MOVE_DOWN, &abs_pos, false))) { if (workspace_switch(swayc_active_workspace_for(adjacent))) { - new_origin.y = 0; - new_origin.x += (output->x - adjacent->x); + new_y = 0; + new_x += (output->x - adjacent->x); } } } } - pointer_position_set(&new_origin, false); + pointer_position_set(new_x, new_y, false); swayc_t *focused = get_focused_container(&root_container); if (focused->type == C_VIEW) { @@ -1122,7 +1121,7 @@ void register_wlc_handlers() { wlc_set_view_request_state_cb(handle_view_state_request); wlc_set_view_properties_updated_cb(handle_view_properties_updated); wlc_set_keyboard_key_cb(handle_key); - wlc_set_pointer_motion_cb(handle_pointer_motion); + wlc_set_pointer_motion_cb_v2(handle_pointer_motion); wlc_set_pointer_button_cb(handle_pointer_button); wlc_set_pointer_scroll_cb(handle_pointer_scroll); wlc_set_compositor_ready_cb(handle_wlc_ready); diff --git a/sway/input_state.c b/sway/input_state.c index 68df17de..04aafd37 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -202,13 +202,13 @@ static void reset_initial_sibling(void) { pointer_state.mode = 0; } -void pointer_position_set(struct wlc_point *new_origin, bool force_focus) { - struct wlc_point origin; - wlc_pointer_get_position(&origin); - pointer_state.delta.x = new_origin->x - origin.x; - pointer_state.delta.y = new_origin->y - origin.y; +void pointer_position_set(double new_x, double new_y, bool force_focus) { + double x, y; + wlc_pointer_get_position_v2(&x, &y); + pointer_state.delta.x = new_x - x; + pointer_state.delta.y = new_y - y; - wlc_pointer_set_position(new_origin); + wlc_pointer_set_position_v2(new_x, new_y); // Update view under pointer swayc_t *prev_view = pointer_state.view; @@ -226,10 +226,7 @@ void pointer_position_set(struct wlc_point *new_origin, bool force_focus) { } void center_pointer_on(swayc_t *view) { - struct wlc_point new_origin; - new_origin.x = view->x + view->width/2; - new_origin.y = view->y + view->height/2; - pointer_position_set(&new_origin, true); + pointer_position_set(view->x + view->width/2, view->y + view->height/2, true); } // Mode set left/right click @@ -269,10 +266,10 @@ static void pointer_mode_set_resizing(void) { int midway_x = initial.ptr->x + initial.ptr->width/2; int midway_y = initial.ptr->y + initial.ptr->height/2; - struct wlc_point origin; - wlc_pointer_get_position(&origin); - lock.left = origin.x > midway_x; - lock.top = origin.y > midway_y; + double x, y; + wlc_pointer_get_position_v2(&x, &y); + lock.left = x > midway_x; + lock.top = y > midway_y; if (initial.ptr->is_floating) { pointer_state.mode = M_RESIZING | M_FLOATING; @@ -346,10 +343,10 @@ void pointer_mode_update(void) { pointer_state.mode = 0; return; } - struct wlc_point origin; - wlc_pointer_get_position(&origin); - int dx = origin.x; - int dy = origin.y; + double x, y; + wlc_pointer_get_position_v2(&x, &y); + int dx = x; + int dy = y; switch (pointer_state.mode) { case M_FLOATING | M_DRAGGING: