diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-12-10 08:48:44 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-12-10 08:48:44 -0500 |
commit | e69b052a6d88b1c24d5e48ad086480ee04c07c81 (patch) | |
tree | 0c76b0023ef379df124c04ee8dfe9583d49202b0 /sway/input/cursor.c | |
parent | working xcursor (diff) | |
download | sway-e69b052a6d88b1c24d5e48ad086480ee04c07c81.tar.gz sway-e69b052a6d88b1c24d5e48ad086480ee04c07c81.tar.zst sway-e69b052a6d88b1c24d5e48ad086480ee04c07c81.zip |
working pointer motion
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r-- | sway/input/cursor.c | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 4f0344be..059f907d 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -2,16 +2,44 @@ | |||
2 | #include <wlr/types/wlr_cursor.h> | 2 | #include <wlr/types/wlr_cursor.h> |
3 | #include <wlr/types/wlr_xcursor_manager.h> | 3 | #include <wlr/types/wlr_xcursor_manager.h> |
4 | #include "sway/input/cursor.h" | 4 | #include "sway/input/cursor.h" |
5 | #include "sway/view.h" | ||
6 | #include "list.h" | ||
5 | #include "log.h" | 7 | #include "log.h" |
6 | 8 | ||
9 | static void cursor_update_position(struct sway_cursor *cursor) { | ||
10 | double x = cursor->cursor->x; | ||
11 | double y = cursor->cursor->y; | ||
12 | |||
13 | wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, | ||
14 | "left_ptr", cursor->cursor); | ||
15 | |||
16 | cursor->x = x; | ||
17 | cursor->y = y; | ||
18 | } | ||
19 | |||
20 | static void cursor_send_pointer_motion(struct sway_cursor *cursor, | ||
21 | uint32_t time) { | ||
22 | struct wlr_seat *seat = cursor->seat->seat; | ||
23 | struct wlr_surface *surface = NULL; | ||
24 | double sx, sy; | ||
25 | swayc_t *swayc = | ||
26 | swayc_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); | ||
27 | if (swayc) { | ||
28 | wlr_seat_pointer_enter(seat, surface, sx, sy); | ||
29 | wlr_seat_pointer_notify_motion(seat, time, sx, sy); | ||
30 | } else { | ||
31 | wlr_seat_pointer_clear_focus(seat); | ||
32 | } | ||
33 | } | ||
34 | |||
7 | static void handle_cursor_motion(struct wl_listener *listener, void *data) { | 35 | static void handle_cursor_motion(struct wl_listener *listener, void *data) { |
8 | struct sway_cursor *cursor = | 36 | struct sway_cursor *cursor = |
9 | wl_container_of(listener, cursor, motion); | 37 | wl_container_of(listener, cursor, motion); |
10 | struct wlr_event_pointer_motion *event = data; | 38 | struct wlr_event_pointer_motion *event = data; |
11 | sway_log(L_DEBUG, "TODO: handle cursor motion event: dx=%f, dy=%f", event->delta_x, event->delta_y); | 39 | wlr_cursor_move(cursor->cursor, event->device, |
12 | wlr_cursor_move(cursor->cursor, event->device, event->delta_x, event->delta_y); | 40 | event->delta_x, event->delta_y); |
13 | sway_log(L_DEBUG, "TODO: new x=%f, y=%f", cursor->cursor->x, cursor->cursor->y); | 41 | cursor_update_position(cursor); |
14 | wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, "left_ptr", cursor->cursor); | 42 | cursor_send_pointer_motion(cursor, event->time_msec); |
15 | } | 43 | } |
16 | 44 | ||
17 | static void handle_cursor_motion_absolute(struct wl_listener *listener, | 45 | static void handle_cursor_motion_absolute(struct wl_listener *listener, |
@@ -19,7 +47,10 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener, | |||
19 | struct sway_cursor *cursor = | 47 | struct sway_cursor *cursor = |
20 | wl_container_of(listener, cursor, motion_absolute); | 48 | wl_container_of(listener, cursor, motion_absolute); |
21 | struct wlr_event_pointer_motion_absolute *event = data; | 49 | struct wlr_event_pointer_motion_absolute *event = data; |
22 | sway_log(L_DEBUG, "TODO: handle event: %p", event); | 50 | wlr_cursor_warp_absolute(cursor->cursor, event->device, |
51 | event->x_mm / event->width_mm, event->y_mm / event->height_mm); | ||
52 | cursor_update_position(cursor); | ||
53 | cursor_send_pointer_motion(cursor, event->time_msec); | ||
23 | } | 54 | } |
24 | 55 | ||
25 | static void handle_cursor_button(struct wl_listener *listener, void *data) { | 56 | static void handle_cursor_button(struct wl_listener *listener, void *data) { |
@@ -91,6 +122,7 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { | |||
91 | return NULL; | 122 | return NULL; |
92 | } | 123 | } |
93 | 124 | ||
125 | cursor->seat = seat; | ||
94 | wlr_cursor_attach_output_layout(wlr_cursor, root_container.output_layout); | 126 | wlr_cursor_attach_output_layout(wlr_cursor, root_container.output_layout); |
95 | 127 | ||
96 | // input events | 128 | // input events |