aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-09-22 10:43:48 -0400
committerGitHub <noreply@github.com>2017-09-22 10:43:48 -0400
commit087894ae99a680d9228d03bae66becc6112682a1 (patch)
tree3f3a6ff372ccdd720dabee9b100b9964ab69f0aa
parentb6cf9b14a420fb02d23c85fa22965a697747ad80 (diff)
parente38248f34c3eed879486347f0c0c5db3ceca4a68 (diff)
Merge pull request #152 from acrisci/feature/wlr-seat-axis-events
wlr-seat cursor axis events
-rw-r--r--examples/compositor.c9
-rw-r--r--include/wlr/types/wlr_seat.h3
-rw-r--r--types/wlr_seat.c34
3 files changed, 36 insertions, 10 deletions
diff --git a/examples/compositor.c b/examples/compositor.c
index c67b8481..56974486 100644
--- a/examples/compositor.c
+++ b/examples/compositor.c
@@ -468,10 +468,11 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener,
}
static void handle_cursor_axis(struct wl_listener *listener, void *data) {
- //struct sample_state *sample =
- //wl_container_of(listener, sample, cursor_axis);
- //struct wlr_event_pointer_axis *event = data;
- wlr_log(L_DEBUG, "TODO: handle cursor axis");
+ struct sample_state *sample =
+ wl_container_of(listener, sample, cursor_axis);
+ struct wlr_event_pointer_axis *event = data;
+ wlr_seat_pointer_send_axis(sample->wl_seat, event->time_sec,
+ event->orientation, event->delta);
}
static void handle_cursor_button(struct wl_listener *listener, void *data) {
diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h
index 4b433ccb..f992b2f2 100644
--- a/include/wlr/types/wlr_seat.h
+++ b/include/wlr/types/wlr_seat.h
@@ -109,4 +109,7 @@ void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time,
void wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time,
uint32_t button, uint32_t state);
+void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time,
+ enum wlr_axis_orientation orientation, double value);
+
#endif
diff --git a/types/wlr_seat.c b/types/wlr_seat.c
index 9a254b35..54b55ba9 100644
--- a/types/wlr_seat.c
+++ b/types/wlr_seat.c
@@ -260,6 +260,11 @@ static void handle_pointer_focus_resource_destroyed(
wlr_seat_pointer_clear_focus(state->wlr_seat);
}
+static bool wlr_seat_pointer_has_focus_resource(struct wlr_seat *wlr_seat) {
+ return wlr_seat->pointer_state.focused_handle &&
+ wlr_seat->pointer_state.focused_handle->pointer;
+}
+
void wlr_seat_pointer_enter(struct wlr_seat *wlr_seat,
struct wlr_surface *surface, double sx, double sy) {
assert(wlr_seat);
@@ -282,7 +287,7 @@ void wlr_seat_pointer_enter(struct wlr_seat *wlr_seat,
wlr_seat->pointer_state.focused_surface;
// leave the previously entered surface
- if (focused_handle && focused_surface) {
+ if (focused_handle && focused_handle->pointer && focused_surface) {
uint32_t serial = wl_display_next_serial(wlr_seat->display);
wl_pointer_send_leave(focused_handle->pointer, serial,
focused_surface->resource);
@@ -290,7 +295,7 @@ void wlr_seat_pointer_enter(struct wlr_seat *wlr_seat,
}
// enter the current surface
- if (handle) {
+ if (handle && handle->pointer) {
uint32_t serial = wl_display_next_serial(wlr_seat->display);
wl_pointer_send_enter(handle->pointer, serial, surface->resource,
wl_fixed_from_double(sx), wl_fixed_from_double(sy));
@@ -327,8 +332,7 @@ void wlr_seat_pointer_clear_focus(struct wlr_seat *wlr_seat) {
void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time,
double sx, double sy) {
- if (!wlr_seat->pointer_state.focused_handle) {
- // nobody to send the event to
+ if (!wlr_seat_pointer_has_focus_resource(wlr_seat)) {
return;
}
@@ -339,8 +343,7 @@ void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time,
void wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time,
uint32_t button, uint32_t state) {
- if (!wlr_seat->pointer_state.focused_handle) {
- // nobody to send the event to
+ if (!wlr_seat_pointer_has_focus_resource(wlr_seat)) {
return;
}
@@ -349,3 +352,22 @@ void wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time,
serial, time, button, state);
wl_pointer_send_frame(wlr_seat->pointer_state.focused_handle->pointer);
}
+
+void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time,
+ enum wlr_axis_orientation orientation, double value) {
+ if (!wlr_seat_pointer_has_focus_resource(wlr_seat)) {
+ return;
+ }
+
+ struct wl_resource *pointer =
+ wlr_seat->pointer_state.focused_handle->pointer;
+
+ if (value) {
+ wl_pointer_send_axis(pointer, time, orientation,
+ wl_fixed_from_double(value));
+ } else {
+ wl_pointer_send_axis_stop(pointer, time, orientation);
+ }
+
+ wl_pointer_send_frame(pointer);
+}