From 0dbfe56c892f400a015c37d1f3574c8f9c985030 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 13 Jun 2017 10:13:11 -0400 Subject: Simplify examples --- example/shared.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 example/shared.h (limited to 'example/shared.h') diff --git a/example/shared.h b/example/shared.h new file mode 100644 index 00000000..bafbee16 --- /dev/null +++ b/example/shared.h @@ -0,0 +1,61 @@ +#ifndef _EXAMPLE_SHARED_H +#define _EXAMPLE_SHARED_H +#define _POSIX_C_SOURCE 199309L +#include +#include +#include +#include +#include +#include +#include + +struct output_state { + struct compositor_state *compositor; + struct wlr_output *output; + struct wl_listener frame; + struct timespec last_frame; + struct wl_list link; + void *data; +}; + +struct keyboard_state { + struct compositor_state *compositor; + struct wlr_input_device *device; + struct wl_listener key; + struct wl_list link; + struct xkb_keymap *keymap; + struct xkb_state *xkb_state; + void *data; +}; + +struct compositor_state { + void (*output_add_cb)(struct output_state *s); + void (*keyboard_add_cb)(struct keyboard_state *s); + void (*output_frame_cb)(struct output_state *s, struct timespec *ts); + void (*output_remove_cb)(struct output_state *s); + void (*keyboard_remove_cb)(struct keyboard_state *s); + void (*keyboard_key_cb)(struct keyboard_state *s, xkb_keysym_t sym, + enum wlr_key_state key_state); + + struct wl_display *display; + struct wl_event_loop *event_loop; + struct wlr_backend *backend; + struct wlr_session *session; + + struct wl_list keyboards; + struct wl_listener input_add; + struct wl_listener input_remove; + + struct timespec last_frame; + struct wl_listener output_add; + struct wl_listener output_remove; + struct wl_list outputs; + + bool exit; + void *data; +}; + +void compositor_init(struct compositor_state *state); +void compositor_run(struct compositor_state *state); + +#endif -- cgit v1.2.3 From 2f9fd72fdcf9249ed16bcc029a86e734ae1487a1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 13 Jun 2017 12:21:36 -0400 Subject: Add pointer example --- example/CMakeLists.txt | 13 ++++++++ example/pointer.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++ example/shared.c | 82 +++++++++++++++++++++++++++++++++++++++++++------- example/shared.h | 13 ++++++++ 4 files changed, 174 insertions(+), 11 deletions(-) create mode 100644 example/pointer.c (limited to 'example/shared.h') diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index f659e5bb..ef11a822 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -27,3 +27,16 @@ target_link_libraries(rotation wlr-render ${XKBCOMMON_LIBRARIES} ) + +add_executable(pointer + pointer.c + shared.c + cat.c +) + +target_link_libraries(pointer + wlr-backend + wlr-session + wlr-render + ${XKBCOMMON_LIBRARIES} +) diff --git a/example/pointer.c b/example/pointer.c new file mode 100644 index 00000000..969fb721 --- /dev/null +++ b/example/pointer.c @@ -0,0 +1,77 @@ +#define _POSIX_C_SOURCE 199309L +#define _XOPEN_SOURCE 500 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "shared.h" +#include "cat.h" + +struct sample_state { + struct wlr_renderer *renderer; + struct wlr_surface *cat_texture; + int cur_x, cur_y; +}; + +static void handle_output_frame(struct output_state *output, struct timespec *ts) { + struct compositor_state *state = output->compositor; + struct sample_state *sample = state->data; + struct wlr_output *wlr_output = output->output; + + wlr_renderer_begin(sample->renderer, wlr_output); + + float matrix[16]; + wlr_surface_get_matrix(sample->cat_texture, &matrix, + &wlr_output->transform_matrix, sample->cur_x, sample->cur_y); + wlr_render_with_matrix(sample->renderer, + sample->cat_texture, &matrix); + + wlr_renderer_end(sample->renderer); +} + +static void handle_keyboard_key(struct keyboard_state *kbstate, + xkb_keysym_t sym, enum wlr_key_state key_state) { + if (sym == XKB_KEY_Escape) { + kbstate->compositor->exit = true; + } +} + +static void handle_pointer_motion(struct pointer_state *pstate, + double d_x, double d_y) { + struct sample_state *state = pstate->compositor->data; + state->cur_x += d_x; + state->cur_y += d_y; +} + +int main(int argc, char *argv[]) { + struct sample_state state = { 0 }; + struct compositor_state compositor; + + compositor_init(&compositor); + compositor.output_frame_cb = handle_output_frame; + compositor.pointer_motion_cb = handle_pointer_motion; + compositor.keyboard_key_cb = handle_keyboard_key; + + state.renderer = wlr_gles3_renderer_init(); + state.cat_texture = wlr_render_surface_init(state.renderer); + wlr_surface_attach_pixels(state.cat_texture, GL_RGB, + cat_tex.width, cat_tex.height, cat_tex.pixel_data); + + compositor.data = &state; + compositor_run(&compositor); + + wlr_surface_destroy(state.cat_texture); + wlr_renderer_destroy(state.renderer); +} diff --git a/example/shared.c b/example/shared.c index 58266214..4657b7fe 100644 --- a/example/shared.c +++ b/example/shared.c @@ -35,12 +35,7 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); } -static void input_add_notify(struct wl_listener *listener, void *data) { - struct wlr_input_device *device = data; - struct compositor_state *state = wl_container_of(listener, state, input_add); - if (device->type != WLR_INPUT_DEVICE_KEYBOARD) { - return; - } +static void keyboard_add(struct wlr_input_device *device, struct compositor_state *state) { struct keyboard_state *kbstate = calloc(sizeof(struct keyboard_state), 1); kbstate->device = device; kbstate->compositor = state; @@ -75,26 +70,90 @@ static void input_add_notify(struct wl_listener *listener, void *data) { } } -static void input_remove_notify(struct wl_listener *listener, void *data) { +static void pointer_motion_notify(struct wl_listener *listener, void *data) { + struct wlr_pointer_motion *event = data; + struct pointer_state *pstate = wl_container_of(listener, pstate, motion); + if (pstate->compositor->pointer_motion_cb) { + pstate->compositor->pointer_motion_cb(pstate, event->delta_x, event->delta_y); + } +} + +static void pointer_add(struct wlr_input_device *device, struct compositor_state *state) { + struct pointer_state *pstate = calloc(sizeof(struct pointer_state), 1); + pstate->device = device; + pstate->compositor = state; + wl_list_init(&pstate->motion.link); + wl_list_init(&pstate->motion_absolute.link); + wl_list_init(&pstate->button.link); + wl_list_init(&pstate->axis.link); + pstate->motion.notify = pointer_motion_notify; + wl_signal_add(&device->pointer->events.motion, &pstate->motion); + wl_list_insert(&state->pointers, &pstate->link); +} + +static void input_add_notify(struct wl_listener *listener, void *data) { struct wlr_input_device *device = data; struct compositor_state *state = wl_container_of(listener, state, input_add); - if (device->type != WLR_INPUT_DEVICE_KEYBOARD) { - return; + switch (device->type) { + case WLR_INPUT_DEVICE_KEYBOARD: + keyboard_add(device, state); + break; + case WLR_INPUT_DEVICE_POINTER: + pointer_add(device, state); + break; + default: + break; } +} + +static void keyboard_remove(struct wlr_input_device *device, struct compositor_state *state) { struct keyboard_state *kbstate = NULL, *_kbstate; wl_list_for_each(_kbstate, &state->keyboards, link) { if (_kbstate->device == device) { - kbstate = kbstate; + kbstate = _kbstate; break; } } if (!kbstate) { - return; // We are unfamiliar with this keyboard + return; } wl_list_remove(&kbstate->link); wl_list_remove(&kbstate->key.link); } +static void pointer_remove(struct wlr_input_device *device, struct compositor_state *state) { + struct pointer_state *pstate = NULL, *_pstate; + wl_list_for_each(_pstate, &state->pointers, link) { + if (_pstate->device == device) { + pstate = _pstate; + break; + } + } + if (!pstate) { + return; + } + wl_list_remove(&pstate->link); + //wl_list_remove(&pstate->motion.link); + wl_list_remove(&pstate->motion_absolute.link); + //wl_list_remove(&pstate->button.link); + //wl_list_remove(&pstate->axis.link); +} + +static void input_remove_notify(struct wl_listener *listener, void *data) { + struct wlr_input_device *device = data; + struct compositor_state *state = wl_container_of(listener, state, input_add); + switch (device->type) { + case WLR_INPUT_DEVICE_KEYBOARD: + keyboard_remove(device, state); + break; + case WLR_INPUT_DEVICE_POINTER: + pointer_remove(device, state); + break; + default: + break; + } +} + static void output_frame_notify(struct wl_listener *listener, void *data) { struct output_state *output = wl_container_of(listener, output, frame); struct compositor_state *compositor = output->compositor; @@ -162,6 +221,7 @@ void compositor_init(struct compositor_state *state) { } wl_list_init(&state->keyboards); + wl_list_init(&state->pointers); wl_list_init(&state->input_add.link); state->input_add.notify = input_add_notify; wl_list_init(&state->input_remove.link); diff --git a/example/shared.h b/example/shared.h index bafbee16..2c093414 100644 --- a/example/shared.h +++ b/example/shared.h @@ -28,6 +28,17 @@ struct keyboard_state { void *data; }; +struct pointer_state { + struct compositor_state *compositor; + struct wlr_input_device *device; + struct wl_listener motion; + struct wl_listener motion_absolute; + struct wl_listener button; + struct wl_listener axis; + struct wl_list link; + void *data; +}; + struct compositor_state { void (*output_add_cb)(struct output_state *s); void (*keyboard_add_cb)(struct keyboard_state *s); @@ -36,6 +47,7 @@ struct compositor_state { void (*keyboard_remove_cb)(struct keyboard_state *s); void (*keyboard_key_cb)(struct keyboard_state *s, xkb_keysym_t sym, enum wlr_key_state key_state); + void (*pointer_motion_cb)(struct pointer_state *s, double d_x, double d_y); struct wl_display *display; struct wl_event_loop *event_loop; @@ -43,6 +55,7 @@ struct compositor_state { struct wlr_session *session; struct wl_list keyboards; + struct wl_list pointers; struct wl_listener input_add; struct wl_listener input_remove; -- cgit v1.2.3 From 8f284ec0b23953ccc274291eeb612d782d391b07 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 13 Jun 2017 12:31:24 -0400 Subject: Demonstrate pointer button event in example --- example/pointer.c | 26 ++++++++++++++++++++++++-- example/shared.c | 14 +++++++++++++- example/shared.h | 5 ++++- 3 files changed, 41 insertions(+), 4 deletions(-) (limited to 'example/shared.h') diff --git a/example/pointer.c b/example/pointer.c index 969fb721..42ac85fd 100644 --- a/example/pointer.c +++ b/example/pointer.c @@ -23,6 +23,7 @@ struct sample_state { struct wlr_renderer *renderer; struct wlr_surface *cat_texture; int cur_x, cur_y; + float clear_color[4]; }; static void handle_output_frame(struct output_state *output, struct timespec *ts) { @@ -31,6 +32,9 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts struct wlr_output *wlr_output = output->output; wlr_renderer_begin(sample->renderer, wlr_output); + glClearColor(sample->clear_color[0], sample->clear_color[1], + sample->clear_color[2], sample->clear_color[3]); + glClear(GL_COLOR_BUFFER_BIT); float matrix[16]; wlr_surface_get_matrix(sample->cat_texture, &matrix, @@ -55,14 +59,32 @@ static void handle_pointer_motion(struct pointer_state *pstate, state->cur_y += d_y; } +static void handle_pointer_button(struct pointer_state *pstate, + uint32_t button, enum wlr_button_state state) { + struct sample_state *sample = pstate->compositor->data; + float (*color)[4]; + if (state == WLR_BUTTON_RELEASED) { + float _default[4] = { 0.25f, 0.25f, 0.25f, 1 }; + color = &_default; + } else { + float red[4] = { 0.25f, 0.25f, 0.25f, 1 }; + red[button % 3] = 1; + color = &red; + } + memcpy(&sample->clear_color, color, sizeof(*color)); +} + int main(int argc, char *argv[]) { - struct sample_state state = { 0 }; + struct sample_state state = { + .clear_color = { 0.25f, 0.25f, 0.25f, 1 } + }; struct compositor_state compositor; compositor_init(&compositor); compositor.output_frame_cb = handle_output_frame; - compositor.pointer_motion_cb = handle_pointer_motion; compositor.keyboard_key_cb = handle_keyboard_key; + compositor.pointer_motion_cb = handle_pointer_motion; + compositor.pointer_button_cb = handle_pointer_button; state.renderer = wlr_gles3_renderer_init(); state.cat_texture = wlr_render_surface_init(state.renderer); diff --git a/example/shared.c b/example/shared.c index 4657b7fe..6a676343 100644 --- a/example/shared.c +++ b/example/shared.c @@ -74,7 +74,17 @@ static void pointer_motion_notify(struct wl_listener *listener, void *data) { struct wlr_pointer_motion *event = data; struct pointer_state *pstate = wl_container_of(listener, pstate, motion); if (pstate->compositor->pointer_motion_cb) { - pstate->compositor->pointer_motion_cb(pstate, event->delta_x, event->delta_y); + pstate->compositor->pointer_motion_cb(pstate, + event->delta_x, event->delta_y); + } +} + +static void pointer_button_notify(struct wl_listener *listener, void *data) { + struct wlr_pointer_button *event = data; + struct pointer_state *pstate = wl_container_of(listener, pstate, button); + if (pstate->compositor->pointer_button_cb) { + pstate->compositor->pointer_button_cb(pstate, + event->button, event->state); } } @@ -87,7 +97,9 @@ static void pointer_add(struct wlr_input_device *device, struct compositor_state wl_list_init(&pstate->button.link); wl_list_init(&pstate->axis.link); pstate->motion.notify = pointer_motion_notify; + pstate->button.notify = pointer_button_notify; wl_signal_add(&device->pointer->events.motion, &pstate->motion); + wl_signal_add(&device->pointer->events.button, &pstate->button); wl_list_insert(&state->pointers, &pstate->link); } diff --git a/example/shared.h b/example/shared.h index 2c093414..ca558f1c 100644 --- a/example/shared.h +++ b/example/shared.h @@ -47,7 +47,10 @@ struct compositor_state { void (*keyboard_remove_cb)(struct keyboard_state *s); void (*keyboard_key_cb)(struct keyboard_state *s, xkb_keysym_t sym, enum wlr_key_state key_state); - void (*pointer_motion_cb)(struct pointer_state *s, double d_x, double d_y); + void (*pointer_motion_cb)(struct pointer_state *s, + double d_x, double d_y); + void (*pointer_button_cb)(struct pointer_state *s, + uint32_t button, enum wlr_button_state state); struct wl_display *display; struct wl_event_loop *event_loop; -- cgit v1.2.3 From 7dfc2c28f1870a38357d6adbb48040151f3166b1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 13 Jun 2017 12:38:57 -0400 Subject: Add axis events to pointer example --- example/pointer.c | 24 ++++++++++++++++++++++-- example/shared.c | 11 +++++++++++ example/shared.h | 4 ++++ 3 files changed, 37 insertions(+), 2 deletions(-) (limited to 'example/shared.h') diff --git a/example/pointer.c b/example/pointer.c index 42ac85fd..a427f0f2 100644 --- a/example/pointer.c +++ b/example/pointer.c @@ -23,6 +23,7 @@ struct sample_state { struct wlr_renderer *renderer; struct wlr_surface *cat_texture; int cur_x, cur_y; + float default_color[4]; float clear_color[4]; }; @@ -64,8 +65,7 @@ static void handle_pointer_button(struct pointer_state *pstate, struct sample_state *sample = pstate->compositor->data; float (*color)[4]; if (state == WLR_BUTTON_RELEASED) { - float _default[4] = { 0.25f, 0.25f, 0.25f, 1 }; - color = &_default; + color = &sample->default_color; } else { float red[4] = { 0.25f, 0.25f, 0.25f, 1 }; red[button % 3] = 1; @@ -74,8 +74,27 @@ static void handle_pointer_button(struct pointer_state *pstate, memcpy(&sample->clear_color, color, sizeof(*color)); } +static void handle_pointer_axis(struct pointer_state *pstate, + enum wlr_axis_source source, + enum wlr_axis_orientation orientation, + double delta) { + struct sample_state *sample = pstate->compositor->data; + for (size_t i = 0; i < 3; ++i) { + sample->default_color[i] += delta > 0 ? -0.05f : 0.05f; + if (sample->default_color[i] > 1.0f) { + sample->default_color[i] = 1.0f; + } + if (sample->default_color[i] < 0.0f) { + sample->default_color[i] = 0.0f; + } + } + memcpy(&sample->clear_color, &sample->default_color, + sizeof(sample->clear_color)); +} + int main(int argc, char *argv[]) { struct sample_state state = { + .default_color = { 0.25f, 0.25f, 0.25f, 1 }, .clear_color = { 0.25f, 0.25f, 0.25f, 1 } }; struct compositor_state compositor; @@ -85,6 +104,7 @@ int main(int argc, char *argv[]) { compositor.keyboard_key_cb = handle_keyboard_key; compositor.pointer_motion_cb = handle_pointer_motion; compositor.pointer_button_cb = handle_pointer_button; + compositor.pointer_axis_cb = handle_pointer_axis; state.renderer = wlr_gles3_renderer_init(); state.cat_texture = wlr_render_surface_init(state.renderer); diff --git a/example/shared.c b/example/shared.c index 6a676343..6de16074 100644 --- a/example/shared.c +++ b/example/shared.c @@ -88,6 +88,15 @@ static void pointer_button_notify(struct wl_listener *listener, void *data) { } } +static void pointer_axis_notify(struct wl_listener *listener, void *data) { + struct wlr_pointer_axis *event = data; + struct pointer_state *pstate = wl_container_of(listener, pstate, axis); + if (pstate->compositor->pointer_axis_cb) { + pstate->compositor->pointer_axis_cb(pstate, + event->source, event->orientation, event->delta); + } +} + static void pointer_add(struct wlr_input_device *device, struct compositor_state *state) { struct pointer_state *pstate = calloc(sizeof(struct pointer_state), 1); pstate->device = device; @@ -98,8 +107,10 @@ static void pointer_add(struct wlr_input_device *device, struct compositor_state wl_list_init(&pstate->axis.link); pstate->motion.notify = pointer_motion_notify; pstate->button.notify = pointer_button_notify; + pstate->axis.notify = pointer_axis_notify; wl_signal_add(&device->pointer->events.motion, &pstate->motion); wl_signal_add(&device->pointer->events.button, &pstate->button); + wl_signal_add(&device->pointer->events.axis, &pstate->axis); wl_list_insert(&state->pointers, &pstate->link); } diff --git a/example/shared.h b/example/shared.h index ca558f1c..7f0dade5 100644 --- a/example/shared.h +++ b/example/shared.h @@ -51,6 +51,10 @@ struct compositor_state { double d_x, double d_y); void (*pointer_button_cb)(struct pointer_state *s, uint32_t button, enum wlr_button_state state); + void (*pointer_axis_cb)(struct pointer_state *s, + enum wlr_axis_source source, + enum wlr_axis_orientation orientation, + double delta); struct wl_display *display; struct wl_event_loop *event_loop; -- cgit v1.2.3 From 3f24f8a1bee10fb3aadf8c57ca107fe5aaa7cffa Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 14 Jun 2017 14:50:09 -0400 Subject: Flesh out touch events and add demo --- backend/libinput/events.c | 15 ++++++ backend/libinput/touch.c | 78 +++++++++++++++++++++++++++++ example/CMakeLists.txt | 13 +++++ example/shared.c | 86 ++++++++++++++++++++++++++++++-- example/shared.h | 18 +++++++ example/touch.c | 122 +++++++++++++++++++++++++++++++++++++++++++++ include/backend/libinput.h | 2 - include/wlr/types.h | 29 ++++++++++- types/wlr_touch.c | 1 - 9 files changed, 356 insertions(+), 8 deletions(-) create mode 100644 example/touch.c (limited to 'example/shared.h') diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 4af8082f..f8413dae 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -139,6 +139,21 @@ void wlr_libinput_event(struct wlr_backend_state *state, case LIBINPUT_EVENT_POINTER_AXIS: handle_pointer_axis(event, device); break; + case LIBINPUT_EVENT_TOUCH_DOWN: + handle_touch_down(event, device); + break; + case LIBINPUT_EVENT_TOUCH_UP: + handle_touch_up(event, device); + break; + case LIBINPUT_EVENT_TOUCH_MOTION: + handle_touch_motion(event, device); + break; + case LIBINPUT_EVENT_TOUCH_CANCEL: + handle_touch_cancel(event, device); + break; + case LIBINPUT_EVENT_TOUCH_FRAME: + // no-op (at least for now) + break; default: wlr_log(L_DEBUG, "Unknown libinput event %d", event_type); break; diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c index 55e8609a..02c9cfef 100644 --- a/backend/libinput/touch.c +++ b/backend/libinput/touch.c @@ -13,3 +13,81 @@ struct wlr_touch *wlr_libinput_touch_create( assert(device); return wlr_touch_create(NULL, NULL); } + +void handle_touch_down(struct libinput_event *event, + struct libinput_device *device) { + struct wlr_input_device *dev = + get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, device); + if (!dev) { + wlr_log(L_DEBUG, "Got a touch event for a device with no touch?"); + return; + } + struct libinput_event_touch *tevent = + libinput_event_get_touch_event(event); + struct wlr_touch_down *wlr_event = + calloc(1, sizeof(struct wlr_touch_down)); + wlr_event->time_sec = libinput_event_touch_get_time(tevent); + wlr_event->time_usec = libinput_event_touch_get_time_usec(tevent); + wlr_event->slot = libinput_event_touch_get_slot(tevent); + wlr_event->x_mm = libinput_event_touch_get_x(tevent); + wlr_event->y_mm = libinput_event_touch_get_y(tevent); + libinput_device_get_size(device, &wlr_event->width_mm, &wlr_event->height_mm); + wl_signal_emit(&dev->touch->events.down, wlr_event); +} + +void handle_touch_up(struct libinput_event *event, + struct libinput_device *device) { + struct wlr_input_device *dev = + get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, device); + if (!dev) { + wlr_log(L_DEBUG, "Got a touch event for a device with no touch?"); + return; + } + struct libinput_event_touch *tevent = + libinput_event_get_touch_event(event); + struct wlr_touch_up *wlr_event = + calloc(1, sizeof(struct wlr_touch_up)); + wlr_event->time_sec = libinput_event_touch_get_time(tevent); + wlr_event->time_usec = libinput_event_touch_get_time_usec(tevent); + wlr_event->slot = libinput_event_touch_get_slot(tevent); + wl_signal_emit(&dev->touch->events.up, wlr_event); +} + +void handle_touch_motion(struct libinput_event *event, + struct libinput_device *device) { + struct wlr_input_device *dev = + get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, device); + if (!dev) { + wlr_log(L_DEBUG, "Got a touch event for a device with no touch?"); + return; + } + struct libinput_event_touch *tevent = + libinput_event_get_touch_event(event); + struct wlr_touch_motion *wlr_event = + calloc(1, sizeof(struct wlr_touch_motion)); + wlr_event->time_sec = libinput_event_touch_get_time(tevent); + wlr_event->time_usec = libinput_event_touch_get_time_usec(tevent); + wlr_event->slot = libinput_event_touch_get_slot(tevent); + wlr_event->x_mm = libinput_event_touch_get_x(tevent); + wlr_event->y_mm = libinput_event_touch_get_y(tevent); + libinput_device_get_size(device, &wlr_event->width_mm, &wlr_event->height_mm); + wl_signal_emit(&dev->touch->events.motion, wlr_event); +} + +void handle_touch_cancel(struct libinput_event *event, + struct libinput_device *device) { + struct wlr_input_device *dev = + get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, device); + if (!dev) { + wlr_log(L_DEBUG, "Got a touch event for a device with no touch?"); + return; + } + struct libinput_event_touch *tevent = + libinput_event_get_touch_event(event); + struct wlr_touch_cancel *wlr_event = + calloc(1, sizeof(struct wlr_touch_cancel)); + wlr_event->time_sec = libinput_event_touch_get_time(tevent); + wlr_event->time_usec = libinput_event_touch_get_time_usec(tevent); + wlr_event->slot = libinput_event_touch_get_slot(tevent); + wl_signal_emit(&dev->touch->events.cancel, wlr_event); +} diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index ef11a822..a6085392 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -40,3 +40,16 @@ target_link_libraries(pointer wlr-render ${XKBCOMMON_LIBRARIES} ) + +add_executable(touch + touch.c + shared.c + cat.c +) + +target_link_libraries(touch + wlr-backend + wlr-session + wlr-render + ${XKBCOMMON_LIBRARIES} +) diff --git a/example/shared.c b/example/shared.c index 6de16074..2592c924 100644 --- a/example/shared.c +++ b/example/shared.c @@ -114,6 +114,59 @@ static void pointer_add(struct wlr_input_device *device, struct compositor_state wl_list_insert(&state->pointers, &pstate->link); } +static void touch_down_notify(struct wl_listener *listener, void *data) { + struct wlr_touch_down *event = data; + struct touch_state *tstate = wl_container_of(listener, tstate, down); + if (tstate->compositor->touch_down_cb) { + tstate->compositor->touch_down_cb(tstate, event->slot, + event->x_mm, event->y_mm, event->width_mm, event->height_mm); + } +} + +static void touch_motion_notify(struct wl_listener *listener, void *data) { + struct wlr_touch_motion *event = data; + struct touch_state *tstate = wl_container_of(listener, tstate, motion); + if (tstate->compositor->touch_motion_cb) { + tstate->compositor->touch_motion_cb(tstate, event->slot, + event->x_mm, event->y_mm, event->width_mm, event->height_mm); + } +} + +static void touch_up_notify(struct wl_listener *listener, void *data) { + struct wlr_touch_up *event = data; + struct touch_state *tstate = wl_container_of(listener, tstate, up); + if (tstate->compositor->touch_up_cb) { + tstate->compositor->touch_up_cb(tstate, event->slot); + } +} + +static void touch_cancel_notify(struct wl_listener *listener, void *data) { + struct wlr_touch_cancel *event = data; + struct touch_state *tstate = wl_container_of(listener, tstate, cancel); + if (tstate->compositor->touch_cancel_cb) { + tstate->compositor->touch_cancel_cb(tstate, event->slot); + } +} + +static void touch_add(struct wlr_input_device *device, struct compositor_state *state) { + struct touch_state *tstate = calloc(sizeof(struct touch_state), 1); + tstate->device = device; + tstate->compositor = state; + wl_list_init(&tstate->down.link); + wl_list_init(&tstate->motion.link); + wl_list_init(&tstate->up.link); + wl_list_init(&tstate->cancel.link); + tstate->down.notify = touch_down_notify; + tstate->motion.notify = touch_motion_notify; + tstate->up.notify = touch_up_notify; + tstate->cancel.notify = touch_cancel_notify; + wl_signal_add(&device->touch->events.down, &tstate->down); + wl_signal_add(&device->touch->events.motion, &tstate->motion); + wl_signal_add(&device->touch->events.up, &tstate->up); + wl_signal_add(&device->touch->events.cancel, &tstate->cancel); + wl_list_insert(&state->touch, &tstate->link); +} + static void input_add_notify(struct wl_listener *listener, void *data) { struct wlr_input_device *device = data; struct compositor_state *state = wl_container_of(listener, state, input_add); @@ -124,6 +177,9 @@ static void input_add_notify(struct wl_listener *listener, void *data) { case WLR_INPUT_DEVICE_POINTER: pointer_add(device, state); break; + case WLR_INPUT_DEVICE_TOUCH: + touch_add(device, state); + break; default: break; } @@ -156,10 +212,28 @@ static void pointer_remove(struct wlr_input_device *device, struct compositor_st return; } wl_list_remove(&pstate->link); - //wl_list_remove(&pstate->motion.link); - wl_list_remove(&pstate->motion_absolute.link); - //wl_list_remove(&pstate->button.link); - //wl_list_remove(&pstate->axis.link); + wl_list_remove(&pstate->motion.link); + //wl_list_remove(&pstate->motion_absolute.link); + wl_list_remove(&pstate->button.link); + wl_list_remove(&pstate->axis.link); +} + +static void touch_remove(struct wlr_input_device *device, struct compositor_state *state) { + struct touch_state *tstate = NULL, *_tstate; + wl_list_for_each(_tstate, &state->touch, link) { + if (_tstate->device == device) { + tstate = _tstate; + break; + } + } + if (!tstate) { + return; + } + wl_list_remove(&tstate->link); + wl_list_remove(&tstate->down.link); + wl_list_remove(&tstate->motion.link); + wl_list_remove(&tstate->up.link); + wl_list_remove(&tstate->cancel.link); } static void input_remove_notify(struct wl_listener *listener, void *data) { @@ -172,6 +246,9 @@ static void input_remove_notify(struct wl_listener *listener, void *data) { case WLR_INPUT_DEVICE_POINTER: pointer_remove(device, state); break; + case WLR_INPUT_DEVICE_TOUCH: + touch_remove(device, state); + break; default: break; } @@ -245,6 +322,7 @@ void compositor_init(struct compositor_state *state) { wl_list_init(&state->keyboards); wl_list_init(&state->pointers); + wl_list_init(&state->touch); wl_list_init(&state->input_add.link); state->input_add.notify = input_add_notify; wl_list_init(&state->input_remove.link); diff --git a/example/shared.h b/example/shared.h index 7f0dade5..d09bcd0e 100644 --- a/example/shared.h +++ b/example/shared.h @@ -39,6 +39,17 @@ struct pointer_state { void *data; }; +struct touch_state { + struct compositor_state *compositor; + struct wlr_input_device *device; + struct wl_listener down; + struct wl_listener up; + struct wl_listener motion; + struct wl_listener cancel; + struct wl_list link; + void *data; +}; + struct compositor_state { void (*output_add_cb)(struct output_state *s); void (*keyboard_add_cb)(struct keyboard_state *s); @@ -55,6 +66,12 @@ struct compositor_state { enum wlr_axis_source source, enum wlr_axis_orientation orientation, double delta); + void (*touch_down_cb)(struct touch_state *s, int32_t slot, + double x, double y, double width, double height); + void (*touch_motion_cb)(struct touch_state *s, int32_t slot, + double x, double y, double width, double height); + void (*touch_up_cb)(struct touch_state *s, int32_t slot); + void (*touch_cancel_cb)(struct touch_state *s, int32_t slot); struct wl_display *display; struct wl_event_loop *event_loop; @@ -63,6 +80,7 @@ struct compositor_state { struct wl_list keyboards; struct wl_list pointers; + struct wl_list touch; struct wl_listener input_add; struct wl_listener input_remove; diff --git a/example/touch.c b/example/touch.c new file mode 100644 index 00000000..7f4f3800 --- /dev/null +++ b/example/touch.c @@ -0,0 +1,122 @@ +#define _POSIX_C_SOURCE 199309L +#define _XOPEN_SOURCE 500 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "shared.h" +#include "cat.h" + +struct sample_state { + struct wlr_renderer *renderer; + struct wlr_surface *cat_texture; + list_t *touch_points; +}; + +struct touch_point { + int32_t slot; + double x, y; +}; + +static void handle_output_frame(struct output_state *output, struct timespec *ts) { + struct compositor_state *state = output->compositor; + struct sample_state *sample = state->data; + struct wlr_output *wlr_output = output->output; + + int32_t width, height; + wlr_output_effective_resolution(wlr_output, &width, &height); + wlr_renderer_begin(sample->renderer, wlr_output); + + float matrix[16]; + for (size_t i = 0; i < sample->touch_points->length; ++i) { + struct touch_point *p = sample->touch_points->items[i]; + wlr_surface_get_matrix(sample->cat_texture, &matrix, + &wlr_output->transform_matrix, + (int)(p->x * width) - sample->cat_texture->width / 2, + (int)(p->y * height) - sample->cat_texture->height / 2); + wlr_render_with_matrix(sample->renderer, + sample->cat_texture, &matrix); + } + + wlr_renderer_end(sample->renderer); +} + +static void handle_keyboard_key(struct keyboard_state *kbstate, + xkb_keysym_t sym, enum wlr_key_state key_state) { + if (sym == XKB_KEY_Escape) { + kbstate->compositor->exit = true; + } +} + +static void handle_touch_down(struct touch_state *tstate, int32_t slot, + double x, double y, double width, double height) { + struct sample_state *sample = tstate->compositor->data; + struct touch_point *point = calloc(1, sizeof(struct touch_state)); + point->slot = slot; + point->x = x / width; + point->y = y / height; + list_add(sample->touch_points, point); +} + +static void handle_touch_up(struct touch_state *tstate, int32_t slot) { + struct sample_state *sample = tstate->compositor->data; + for (size_t i = 0; i < sample->touch_points->length; ++i) { + struct touch_point *point = sample->touch_points->items[i]; + if (point->slot == slot) { + list_del(sample->touch_points, i); + break; + } + } +} + +static void handle_touch_motion(struct touch_state *tstate, int32_t slot, + double x, double y, double width, double height) { + struct sample_state *sample = tstate->compositor->data; + for (size_t i = 0; i < sample->touch_points->length; ++i) { + struct touch_point *point = sample->touch_points->items[i]; + if (point->slot == slot) { + point->x = x / width; + point->y = y / height; + break; + } + } +} + +int main(int argc, char *argv[]) { + struct sample_state state = { + .touch_points = list_create() + }; + struct compositor_state compositor; + + compositor_init(&compositor); + compositor.output_frame_cb = handle_output_frame; + compositor.keyboard_key_cb = handle_keyboard_key; + compositor.touch_down_cb = handle_touch_down; + compositor.touch_up_cb = handle_touch_up; + compositor.touch_motion_cb = handle_touch_motion; + + state.renderer = wlr_gles3_renderer_init(); + state.cat_texture = wlr_render_surface_init(state.renderer); + wlr_surface_attach_pixels(state.cat_texture, GL_RGB, + cat_tex.width, cat_tex.height, cat_tex.pixel_data); + + compositor.data = &state; + compositor_run(&compositor); + + wlr_surface_destroy(state.cat_texture); + wlr_renderer_destroy(state.renderer); +} diff --git a/include/backend/libinput.h b/include/backend/libinput.h index dd24fbb0..2427ae5c 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -56,7 +56,5 @@ void handle_touch_motion(struct libinput_event *event, struct libinput_device *device); void handle_touch_cancel(struct libinput_event *event, struct libinput_device *device); -void handle_touch_frame(struct libinput_event *event, - struct libinput_device *device); #endif diff --git a/include/wlr/types.h b/include/wlr/types.h index b4d69ccb..4763013a 100644 --- a/include/wlr/types.h +++ b/include/wlr/types.h @@ -146,10 +146,37 @@ struct wlr_touch { struct wl_signal up; struct wl_signal motion; struct wl_signal cancel; - struct wl_signal frame; } events; }; +struct wlr_touch_down { + uint32_t time_sec; + uint64_t time_usec; + int32_t slot; + double x_mm, y_mm; + double width_mm, height_mm; +}; + +struct wlr_touch_up { + uint32_t time_sec; + uint64_t time_usec; + int32_t slot; +}; + +struct wlr_touch_motion { + uint32_t time_sec; + uint64_t time_usec; + int32_t slot; + double x_mm, y_mm; + double width_mm, height_mm; +}; + +struct wlr_touch_cancel { + uint32_t time_sec; + uint64_t time_usec; + int32_t slot; +}; + // TODO: tablet & tablet tool // TODO: gestures // TODO: switch diff --git a/types/wlr_touch.c b/types/wlr_touch.c index 9c8b4b94..0970f70f 100644 --- a/types/wlr_touch.c +++ b/types/wlr_touch.c @@ -13,7 +13,6 @@ struct wlr_touch *wlr_touch_create(struct wlr_touch_impl *impl, wl_signal_init(&touch->events.down); wl_signal_init(&touch->events.up); wl_signal_init(&touch->events.motion); - wl_signal_init(&touch->events.frame); wl_signal_init(&touch->events.cancel); return touch; } -- cgit v1.2.3 From def3d7c64f68d59c6daec5974afc3ca84fa4bda9 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 15 Jun 2017 16:15:12 -0400 Subject: Add tablet example --- backend/libinput/tablet_tool.c | 6 +-- example/shared.c | 68 +++++++++++++++++++++++++++++++ example/shared.h | 20 +++++++++ example/tablet.c | 92 +++++++++++++++++++++++++++++++++++++++--- 4 files changed, 175 insertions(+), 11 deletions(-) (limited to 'example/shared.h') diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 276c263c..e8a3bc7d 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -76,9 +76,6 @@ void handle_tablet_tool_proximity(struct libinput_event *event, wlr_log(L_DEBUG, "Got a tablet tool event for a device with no tablet tools?"); return; } - // Proximity events contain axis information. We update this information - // before we send the proximity event - handle_tablet_tool_axis(event, device); struct libinput_event_tablet_tool *tevent = libinput_event_get_tablet_tool_event(event); struct wlr_tablet_tool_proximity *wlr_event = @@ -91,6 +88,7 @@ void handle_tablet_tool_proximity(struct libinput_event *event, break; case LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN: wlr_event->state = WLR_TABLET_TOOL_PROXIMITY_IN; + handle_tablet_tool_axis(event, device); break; } wl_signal_emit(&dev->tablet_tool->events.proximity, wlr_event); @@ -104,8 +102,6 @@ void handle_tablet_tool_tip(struct libinput_event *event, wlr_log(L_DEBUG, "Got a tablet tool event for a device with no tablet tools?"); return; } - // Tip events contain axis information. We update this information - // before we send the proximity event handle_tablet_tool_axis(event, device); struct libinput_event_tablet_tool *tevent = libinput_event_get_tablet_tool_event(event); diff --git a/example/shared.c b/example/shared.c index 2592c924..88f2b05f 100644 --- a/example/shared.c +++ b/example/shared.c @@ -167,6 +167,50 @@ static void touch_add(struct wlr_input_device *device, struct compositor_state * wl_list_insert(&state->touch, &tstate->link); } +static void tablet_tool_axis_notify(struct wl_listener *listener, void *data) { + struct wlr_tablet_tool_axis *event = data; + struct tablet_tool_state *tstate = wl_container_of(listener, tstate, axis); + if (tstate->compositor->tool_axis_cb) { + tstate->compositor->tool_axis_cb(tstate, event); + } +} + +static void tablet_tool_proximity_notify(struct wl_listener *listener, void *data) { + struct wlr_tablet_tool_proximity *event = data; + struct tablet_tool_state *tstate = wl_container_of(listener, tstate, proximity); + if (tstate->compositor->tool_proximity_cb) { + tstate->compositor->tool_proximity_cb(tstate, event->state); + } +} + +static void tablet_tool_button_notify(struct wl_listener *listener, void *data) { + struct wlr_tablet_tool_button *event = data; + struct tablet_tool_state *tstate = wl_container_of(listener, tstate, button); + if (tstate->compositor->tool_button_cb) { + tstate->compositor->tool_button_cb(tstate, event->button, event->state); + } +} + +static void tablet_tool_add(struct wlr_input_device *device, + struct compositor_state *state) { + struct tablet_tool_state *tstate = calloc(sizeof(struct tablet_tool_state), 1); + tstate->device = device; + tstate->compositor = state; + wl_list_init(&tstate->axis.link); + wl_list_init(&tstate->proximity.link); + wl_list_init(&tstate->tip.link); + wl_list_init(&tstate->button.link); + tstate->axis.notify = tablet_tool_axis_notify; + tstate->proximity.notify = tablet_tool_proximity_notify; + //tstate->tip.notify = tablet_tool_tip_notify; + tstate->button.notify = tablet_tool_button_notify; + wl_signal_add(&device->tablet_tool->events.axis, &tstate->axis); + wl_signal_add(&device->tablet_tool->events.proximity, &tstate->proximity); + //wl_signal_add(&device->tablet_tool->events.tip, &tstate->tip); + wl_signal_add(&device->tablet_tool->events.button, &tstate->button); + wl_list_insert(&state->tablet_tools, &tstate->link); +} + static void input_add_notify(struct wl_listener *listener, void *data) { struct wlr_input_device *device = data; struct compositor_state *state = wl_container_of(listener, state, input_add); @@ -180,6 +224,8 @@ static void input_add_notify(struct wl_listener *listener, void *data) { case WLR_INPUT_DEVICE_TOUCH: touch_add(device, state); break; + case WLR_INPUT_DEVICE_TABLET_TOOL: + tablet_tool_add(device, state); default: break; } @@ -236,6 +282,24 @@ static void touch_remove(struct wlr_input_device *device, struct compositor_stat wl_list_remove(&tstate->cancel.link); } +static void tablet_tool_remove(struct wlr_input_device *device, struct compositor_state *state) { + struct tablet_tool_state *tstate = NULL, *_tstate; + wl_list_for_each(_tstate, &state->tablet_tools, link) { + if (_tstate->device == device) { + tstate = _tstate; + break; + } + } + if (!tstate) { + return; + } + wl_list_remove(&tstate->link); + wl_list_remove(&tstate->axis.link); + wl_list_remove(&tstate->proximity.link); + //wl_list_remove(&tstate->tip.link); + wl_list_remove(&tstate->button.link); +} + static void input_remove_notify(struct wl_listener *listener, void *data) { struct wlr_input_device *device = data; struct compositor_state *state = wl_container_of(listener, state, input_add); @@ -249,6 +313,9 @@ static void input_remove_notify(struct wl_listener *listener, void *data) { case WLR_INPUT_DEVICE_TOUCH: touch_remove(device, state); break; + case WLR_INPUT_DEVICE_TABLET_TOOL: + tablet_tool_remove(device, state); + break; default: break; } @@ -323,6 +390,7 @@ void compositor_init(struct compositor_state *state) { wl_list_init(&state->keyboards); wl_list_init(&state->pointers); wl_list_init(&state->touch); + wl_list_init(&state->tablet_tools); wl_list_init(&state->input_add.link); state->input_add.notify = input_add_notify; wl_list_init(&state->input_remove.link); diff --git a/example/shared.h b/example/shared.h index d09bcd0e..df456c91 100644 --- a/example/shared.h +++ b/example/shared.h @@ -50,6 +50,17 @@ struct touch_state { void *data; }; +struct tablet_tool_state { + struct compositor_state *compositor; + struct wlr_input_device *device; + struct wl_listener axis; + struct wl_listener proximity; + struct wl_listener tip; + struct wl_listener button; + struct wl_list link; + void *data; +}; + struct compositor_state { void (*output_add_cb)(struct output_state *s); void (*keyboard_add_cb)(struct keyboard_state *s); @@ -72,6 +83,14 @@ struct compositor_state { double x, double y, double width, double height); void (*touch_up_cb)(struct touch_state *s, int32_t slot); void (*touch_cancel_cb)(struct touch_state *s, int32_t slot); + void (*tool_axis_cb)(struct tablet_tool_state *s, + struct wlr_tablet_tool_axis *event); + void (*tool_proximity_cb)(struct tablet_tool_state *s, + enum wlr_tablet_tool_proximity_state proximity); + void (*tool_tip_cb)(struct tablet_tool_state *s, + enum wlr_tablet_tool_tip_state state); + void (*tool_button_cb)(struct tablet_tool_state *s, + uint32_t button, enum wlr_button_state state); struct wl_display *display; struct wl_event_loop *event_loop; @@ -81,6 +100,7 @@ struct compositor_state { struct wl_list keyboards; struct wl_list pointers; struct wl_list touch; + struct wl_list tablet_tools; struct wl_listener input_add; struct wl_listener input_remove; diff --git a/example/tablet.c b/example/tablet.c index 9a498438..f2497d59 100644 --- a/example/tablet.c +++ b/example/tablet.c @@ -21,6 +21,13 @@ struct sample_state { struct wlr_renderer *renderer; + bool proximity, tap; + double distance; + double pressure; + double x_mm, y_mm; + double width_mm, height_mm; + struct wl_list link; + float tool_color[4]; }; static void handle_output_frame(struct output_state *output, struct timespec *ts) { @@ -28,13 +35,41 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts struct sample_state *sample = state->data; struct wlr_output *wlr_output = output->output; + int32_t width, height; + wlr_output_effective_resolution(wlr_output, &width, &height); + wlr_renderer_begin(sample->renderer, wlr_output); - float matrix[16]; - float color[4] = { 0, 1.0, 0, 1.0 }; - wlr_matrix_scale(&matrix, 128, 128, 1); - wlr_matrix_mul(&wlr_output->transform_matrix, &matrix, &matrix); - wlr_render_colored_ellipse(sample->renderer, &color, &matrix); + float matrix[16], view[16]; + float pad_color[4] = { 0.75, 0.75, 0.75, 1.0 }; + float distance = 0.8f * (1 - sample->distance); + float tool_color[4] = { distance, distance, distance, 1 }; + for (size_t i = 0; i < 4; ++i) { + tool_color[i] *= sample->tool_color[i]; + } + float scale = 4; + + float pad_width = sample->width_mm * scale; + float pad_height = sample->height_mm * scale; + float left = width / 2.0f - pad_width / 2.0f; + float top = height / 2.0f - pad_height / 2.0f; + wlr_matrix_translate(&matrix, left, top, 0); + wlr_matrix_scale(&view, pad_width, pad_height, 1); + wlr_matrix_mul(&matrix, &view, &view); + wlr_matrix_mul(&wlr_output->transform_matrix, &view, &matrix); + wlr_render_colored_quad(sample->renderer, &pad_color, &matrix); + + if (sample->proximity) { + wlr_matrix_translate(&matrix, + sample->x_mm * scale - 8 * (sample->pressure + 1) + left, + sample->y_mm * scale - 8 * (sample->pressure + 1) + top, 0); + wlr_matrix_scale(&view, + 16 * (sample->pressure + 1), + 16 * (sample->pressure + 1), 1); + wlr_matrix_mul(&matrix, &view, &view); + wlr_matrix_mul(&wlr_output->transform_matrix, &view, &matrix); + wlr_render_colored_ellipse(sample->renderer, &tool_color, &matrix); + } wlr_renderer_end(sample->renderer); } @@ -46,13 +81,58 @@ static void handle_keyboard_key(struct keyboard_state *kbstate, } } +static void handle_tool_axis(struct tablet_tool_state *tstate, + struct wlr_tablet_tool_axis *event) { + struct sample_state *sample = tstate->compositor->data; + sample->width_mm = event->width_mm; + sample->height_mm = event->height_mm; + if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { + sample->x_mm = event->x_mm; + } + if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { + sample->y_mm = event->y_mm; + } + if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE)) { + sample->distance = event->distance; + } + if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE)) { + sample->pressure = event->pressure; + } +} + +static void handle_tool_proximity(struct tablet_tool_state *tstate, + enum wlr_tablet_tool_proximity_state state) { + struct sample_state *sample = tstate->compositor->data; + sample->proximity = state == WLR_TABLET_TOOL_PROXIMITY_IN; +} + +static void handle_tool_button(struct tablet_tool_state *tstate, + uint32_t button, enum wlr_button_state state) { + struct sample_state *sample = tstate->compositor->data; + if (state == WLR_BUTTON_RELEASED) { + float default_color[4] = { 1, 1, 1, 1 }; + memcpy(sample->tool_color, default_color, 4); + } else { + for (size_t i = 0; i < 3; ++i) { + if (button % 3 != i) { + sample->tool_color[button % 3] = 0; + } + } + } +} + int main(int argc, char *argv[]) { - struct sample_state state = { 0 }; + struct sample_state state = { + .tool_color = { 1, 1, 1, 1 } + }; struct compositor_state compositor; compositor_init(&compositor); compositor.output_frame_cb = handle_output_frame; compositor.keyboard_key_cb = handle_keyboard_key; + compositor.tool_axis_cb = handle_tool_axis; + compositor.tool_proximity_cb = handle_tool_proximity; + compositor.tool_button_cb = handle_tool_button; state.renderer = wlr_gles3_renderer_init(); -- cgit v1.2.3 From ecb04afcadc96cc8d39749311e4c1c412bebf4a9 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 19 Jun 2017 14:49:07 -0400 Subject: Implement tablet pads --- backend/CMakeLists.txt | 1 + backend/libinput/events.c | 14 ++++++- backend/libinput/tablet_pad.c | 95 +++++++++++++++++++++++++++++++++++++++++++ example/shared.c | 24 +++++++++++ example/shared.h | 11 +++++ example/tablet.c | 41 ++++++++++++++----- include/backend/libinput.h | 9 ++++ include/types.h | 8 ++++ include/wlr/types.h | 52 ++++++++++++++++++++++- types/CMakeLists.txt | 1 + types/wlr_tablet_pad.c | 25 ++++++++++++ 11 files changed, 268 insertions(+), 13 deletions(-) create mode 100644 backend/libinput/tablet_pad.c create mode 100644 types/wlr_tablet_pad.c (limited to 'example/shared.h') diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index 6ffa2042..9594c318 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -20,6 +20,7 @@ add_library(wlr-backend libinput/pointer.c libinput/touch.c libinput/tablet_tool.c + libinput/tablet_pad.c multi/backend.c backend.c diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 8ebec63b..2e7cc541 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -91,7 +91,10 @@ static void handle_device_added(struct wlr_backend_state *state, wl_signal_emit(&state->backend->events.input_add, wlr_device); } if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TABLET_PAD)) { - // TODO + struct wlr_input_device *wlr_device = allocate_device(state, + device, devices, WLR_INPUT_DEVICE_TABLET_PAD); + wlr_device->tablet_pad = wlr_libinput_tablet_pad_create(device); + wl_signal_emit(&state->backend->events.input_add, wlr_device); } if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_GESTURE)) { // TODO @@ -169,6 +172,15 @@ void wlr_libinput_event(struct wlr_backend_state *state, case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: handle_tablet_tool_button(event, device); break; + case LIBINPUT_EVENT_TABLET_PAD_BUTTON: + handle_tablet_pad_button(event, device); + break; + case LIBINPUT_EVENT_TABLET_PAD_RING: + handle_tablet_pad_ring(event, device); + break; + case LIBINPUT_EVENT_TABLET_PAD_STRIP: + handle_tablet_pad_strip(event, device); + break; default: wlr_log(L_DEBUG, "Unknown libinput event %d", event_type); break; diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c new file mode 100644 index 00000000..ee7c82f8 --- /dev/null +++ b/backend/libinput/tablet_pad.c @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include +#include +#include "backend/libinput.h" +#include "common/log.h" +#include "types.h" + +struct wlr_tablet_pad *wlr_libinput_tablet_pad_create( + struct libinput_device *device) { + assert(device); + return wlr_tablet_pad_create(NULL, NULL); +} + +void handle_tablet_pad_button(struct libinput_event *event, + struct libinput_device *device) { + struct wlr_input_device *dev = + get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, device); + if (!dev) { + wlr_log(L_DEBUG, "Got a tablet pad event for a device with no tablet pad?"); + return; + } + struct libinput_event_tablet_pad *pevent = + libinput_event_get_tablet_pad_event(event); + struct wlr_tablet_pad_button *wlr_event = + calloc(1, sizeof(struct wlr_tablet_pad_button)); + wlr_event->time_sec = libinput_event_tablet_pad_get_time(pevent); + wlr_event->time_usec = libinput_event_tablet_pad_get_time_usec(pevent); + wlr_event->button = libinput_event_tablet_pad_get_button_number(pevent); + switch (libinput_event_tablet_pad_get_button_state(pevent)) { + case LIBINPUT_BUTTON_STATE_PRESSED: + wlr_event->state = WLR_BUTTON_PRESSED; + break; + case LIBINPUT_BUTTON_STATE_RELEASED: + wlr_event->state = WLR_BUTTON_RELEASED; + break; + } + wl_signal_emit(&dev->tablet_pad->events.button, wlr_event); +} + +void handle_tablet_pad_ring(struct libinput_event *event, + struct libinput_device *device) { + struct wlr_input_device *dev = + get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, device); + if (!dev) { + wlr_log(L_DEBUG, "Got a tablet pad event for a device with no tablet pad?"); + return; + } + struct libinput_event_tablet_pad *pevent = + libinput_event_get_tablet_pad_event(event); + struct wlr_tablet_pad_ring *wlr_event = + calloc(1, sizeof(struct wlr_tablet_pad_ring)); + wlr_event->time_sec = libinput_event_tablet_pad_get_time(pevent); + wlr_event->time_usec = libinput_event_tablet_pad_get_time_usec(pevent); + wlr_event->ring = libinput_event_tablet_pad_get_ring_number(pevent); + wlr_event->position = libinput_event_tablet_pad_get_ring_position(pevent); + switch (libinput_event_tablet_pad_get_ring_source(pevent)) { + case LIBINPUT_TABLET_PAD_RING_SOURCE_UNKNOWN: + wlr_event->source = WLR_TABLET_PAD_RING_SOURCE_UNKNOWN; + break; + case LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER: + wlr_event->source = WLR_TABLET_PAD_RING_SOURCE_FINGER; + break; + } + wl_signal_emit(&dev->tablet_pad->events.ring, wlr_event); +} + +void handle_tablet_pad_strip(struct libinput_event *event, + struct libinput_device *device) { + struct wlr_input_device *dev = + get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, device); + if (!dev) { + wlr_log(L_DEBUG, "Got a tablet pad event for a device with no tablet pad?"); + return; + } + struct libinput_event_tablet_pad *pevent = + libinput_event_get_tablet_pad_event(event); + struct wlr_tablet_pad_strip *wlr_event = + calloc(1, sizeof(struct wlr_tablet_pad_strip)); + wlr_event->time_sec = libinput_event_tablet_pad_get_time(pevent); + wlr_event->time_usec = libinput_event_tablet_pad_get_time_usec(pevent); + wlr_event->strip = libinput_event_tablet_pad_get_strip_number(pevent); + wlr_event->position = libinput_event_tablet_pad_get_strip_position(pevent); + switch (libinput_event_tablet_pad_get_strip_source(pevent)) { + case LIBINPUT_TABLET_PAD_STRIP_SOURCE_UNKNOWN: + wlr_event->source = WLR_TABLET_PAD_STRIP_SOURCE_UNKNOWN; + break; + case LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER: + wlr_event->source = WLR_TABLET_PAD_STRIP_SOURCE_FINGER; + break; + } + wl_signal_emit(&dev->tablet_pad->events.strip, wlr_event); +} diff --git a/example/shared.c b/example/shared.c index 88f2b05f..56cb89af 100644 --- a/example/shared.c +++ b/example/shared.c @@ -211,6 +211,25 @@ static void tablet_tool_add(struct wlr_input_device *device, wl_list_insert(&state->tablet_tools, &tstate->link); } +static void tablet_pad_button_notify(struct wl_listener *listener, void *data) { + struct wlr_tablet_pad_button *event = data; + struct tablet_pad_state *pstate = wl_container_of(listener, pstate, button); + if (pstate->compositor->pad_button_cb) { + pstate->compositor->pad_button_cb(pstate, event->button, event->state); + } +} + +static void tablet_pad_add(struct wlr_input_device *device, + struct compositor_state *state) { + struct tablet_pad_state *pstate = calloc(sizeof(struct tablet_pad_state), 1); + pstate->device = device; + pstate->compositor = state; + wl_list_init(&pstate->button.link); + pstate->button.notify = tablet_pad_button_notify; + wl_signal_add(&device->tablet_pad->events.button, &pstate->button); + wl_list_insert(&state->tablet_pads, &pstate->link); +} + static void input_add_notify(struct wl_listener *listener, void *data) { struct wlr_input_device *device = data; struct compositor_state *state = wl_container_of(listener, state, input_add); @@ -226,6 +245,10 @@ static void input_add_notify(struct wl_listener *listener, void *data) { break; case WLR_INPUT_DEVICE_TABLET_TOOL: tablet_tool_add(device, state); + break; + case WLR_INPUT_DEVICE_TABLET_PAD: + tablet_pad_add(device, state); + break; default: break; } @@ -391,6 +414,7 @@ void compositor_init(struct compositor_state *state) { wl_list_init(&state->pointers); wl_list_init(&state->touch); wl_list_init(&state->tablet_tools); + wl_list_init(&state->tablet_pads); wl_list_init(&state->input_add.link); state->input_add.notify = input_add_notify; wl_list_init(&state->input_remove.link); diff --git a/example/shared.h b/example/shared.h index df456c91..173a5719 100644 --- a/example/shared.h +++ b/example/shared.h @@ -61,6 +61,14 @@ struct tablet_tool_state { void *data; }; +struct tablet_pad_state { + struct compositor_state *compositor; + struct wlr_input_device *device; + struct wl_listener button; + struct wl_list link; + void *data; +}; + struct compositor_state { void (*output_add_cb)(struct output_state *s); void (*keyboard_add_cb)(struct keyboard_state *s); @@ -91,6 +99,8 @@ struct compositor_state { enum wlr_tablet_tool_tip_state state); void (*tool_button_cb)(struct tablet_tool_state *s, uint32_t button, enum wlr_button_state state); + void (*pad_button_cb)(struct tablet_pad_state *s, + uint32_t button, enum wlr_button_state state); struct wl_display *display; struct wl_event_loop *event_loop; @@ -101,6 +111,7 @@ struct compositor_state { struct wl_list pointers; struct wl_list touch; struct wl_list tablet_tools; + struct wl_list tablet_pads; struct wl_listener input_add; struct wl_listener input_remove; diff --git a/example/tablet.c b/example/tablet.c index f2497d59..3c5b583e 100644 --- a/example/tablet.c +++ b/example/tablet.c @@ -21,13 +21,14 @@ struct sample_state { struct wlr_renderer *renderer; - bool proximity, tap; + bool proximity, tap, button; double distance; double pressure; double x_mm, y_mm; double width_mm, height_mm; struct wl_list link; float tool_color[4]; + float pad_color[4]; }; static void handle_output_frame(struct output_state *output, struct timespec *ts) { @@ -41,11 +42,10 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_begin(sample->renderer, wlr_output); float matrix[16], view[16]; - float pad_color[4] = { 0.75, 0.75, 0.75, 1.0 }; float distance = 0.8f * (1 - sample->distance); float tool_color[4] = { distance, distance, distance, 1 }; - for (size_t i = 0; i < 4; ++i) { - tool_color[i] *= sample->tool_color[i]; + for (size_t i = 0; sample->button && i < 4; ++i) { + tool_color[i] = sample->tool_color[i]; } float scale = 4; @@ -57,7 +57,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_matrix_scale(&view, pad_width, pad_height, 1); wlr_matrix_mul(&matrix, &view, &view); wlr_matrix_mul(&wlr_output->transform_matrix, &view, &matrix); - wlr_render_colored_quad(sample->renderer, &pad_color, &matrix); + wlr_render_colored_quad(sample->renderer, &sample->pad_color, &matrix); if (sample->proximity) { wlr_matrix_translate(&matrix, @@ -110,12 +110,31 @@ static void handle_tool_button(struct tablet_tool_state *tstate, uint32_t button, enum wlr_button_state state) { struct sample_state *sample = tstate->compositor->data; if (state == WLR_BUTTON_RELEASED) { - float default_color[4] = { 1, 1, 1, 1 }; - memcpy(sample->tool_color, default_color, 4); + sample->button = false; } else { + sample->button = true; for (size_t i = 0; i < 3; ++i) { - if (button % 3 != i) { - sample->tool_color[button % 3] = 0; + if (button % 3 == i) { + sample->tool_color[i] = 0; + } else { + sample->tool_color[i] = 1; + } + } + } +} + +static void handle_pad_button(struct tablet_pad_state *pstate, + uint32_t button, enum wlr_button_state state) { + struct sample_state *sample = pstate->compositor->data; + float default_color[4] = { 0.75, 0.75, 0.75, 1.0 }; + if (state == WLR_BUTTON_RELEASED) { + memcpy(sample->pad_color, default_color, sizeof(default_color)); + } else { + for (size_t i = 0; i < 3; ++i) { + if (button % 3 == i) { + sample->pad_color[i] = 0; + } else { + sample->pad_color[i] = 1; } } } @@ -123,7 +142,8 @@ static void handle_tool_button(struct tablet_tool_state *tstate, int main(int argc, char *argv[]) { struct sample_state state = { - .tool_color = { 1, 1, 1, 1 } + .tool_color = { 1, 1, 1, 1 }, + .pad_color = { 0.75, 0.75, 0.75, 1.0 } }; struct compositor_state compositor; @@ -133,6 +153,7 @@ int main(int argc, char *argv[]) { compositor.tool_axis_cb = handle_tool_axis; compositor.tool_proximity_cb = handle_tool_proximity; compositor.tool_button_cb = handle_tool_button; + compositor.pad_button_cb = handle_pad_button; state.renderer = wlr_gles3_renderer_init(); diff --git a/include/backend/libinput.h b/include/backend/libinput.h index 80f57177..89286ab8 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -68,4 +68,13 @@ void handle_tablet_tool_tip(struct libinput_event *event, void handle_tablet_tool_button(struct libinput_event *event, struct libinput_device *device); +struct wlr_tablet_pad *wlr_libinput_tablet_pad_create( + struct libinput_device *device); +void handle_tablet_pad_button(struct libinput_event *event, + struct libinput_device *device); +void handle_tablet_pad_ring(struct libinput_event *event, + struct libinput_device *device); +void handle_tablet_pad_strip(struct libinput_event *event, + struct libinput_device *device); + #endif diff --git a/include/types.h b/include/types.h index e2930a9f..2063c3f5 100644 --- a/include/types.h +++ b/include/types.h @@ -53,6 +53,14 @@ struct wlr_tablet_tool *wlr_tablet_tool_create(struct wlr_tablet_tool_impl *impl struct wlr_tablet_tool_state *state); void wlr_tablet_tool_destroy(struct wlr_tablet_tool *tool); +struct wlr_tablet_pad_impl { + void (*destroy)(struct wlr_tablet_pad_state *pad); +}; + +struct wlr_tablet_pad *wlr_tablet_pad_create(struct wlr_tablet_pad_impl *impl, + struct wlr_tablet_pad_state *state); +void wlr_tablet_pad_destroy(struct wlr_tablet_pad *pad); + struct wlr_input_device_impl { void (*destroy)(struct wlr_input_device_state *state); }; diff --git a/include/wlr/types.h b/include/wlr/types.h index 3afc361e..2ca73cc2 100644 --- a/include/wlr/types.h +++ b/include/wlr/types.h @@ -254,8 +254,55 @@ struct wlr_tablet_tool_button { enum wlr_button_state state; }; -// TODO: tablet pad -// TODO: switch +// NOTE: the wlr tablet pad implementation does not currently support tablets +// with more than one mode. I don't own any such hardware so I cannot test it +// and it is too complicated to make a meaningful implementation of blindly. +struct wlr_tablet_pad_impl; +struct wlr_tablet_pad_state; + +struct wlr_tablet_pad { + struct wlr_tablet_pad_impl *impl; + struct wlr_tablet_pad_state *state; + + struct { + struct wl_signal button; + struct wl_signal ring; + struct wl_signal strip; + } events; +}; + +struct wlr_tablet_pad_button { + uint32_t time_sec; + uint64_t time_usec; + uint32_t button; + enum wlr_button_state state; +}; + +enum wlr_tablet_pad_ring_source { + WLR_TABLET_PAD_RING_SOURCE_UNKNOWN, + WLR_TABLET_PAD_RING_SOURCE_FINGER, +}; + +struct wlr_tablet_pad_ring { + uint32_t time_sec; + uint64_t time_usec; + enum wlr_tablet_pad_ring_source source; + uint32_t ring; + double position; +}; + +enum wlr_tablet_pad_strip_source { + WLR_TABLET_PAD_STRIP_SOURCE_UNKNOWN, + WLR_TABLET_PAD_STRIP_SOURCE_FINGER, +}; + +struct wlr_tablet_pad_strip { + uint32_t time_sec; + uint64_t time_usec; + enum wlr_tablet_pad_strip_source source; + uint32_t strip; + double position; +}; enum wlr_input_device_type { WLR_INPUT_DEVICE_KEYBOARD, @@ -284,6 +331,7 @@ struct wlr_input_device { struct wlr_pointer *pointer; struct wlr_touch *touch; struct wlr_tablet_tool *tablet_tool; + struct wlr_tablet_pad *tablet_pad; }; }; diff --git a/types/CMakeLists.txt b/types/CMakeLists.txt index b10966ec..58f8a651 100644 --- a/types/CMakeLists.txt +++ b/types/CMakeLists.txt @@ -10,6 +10,7 @@ add_library(wlr-types wlr_pointer.c wlr_touch.c wlr_tablet_tool.c + wlr_tablet_pad.c ) target_link_libraries(wlr-types diff --git a/types/wlr_tablet_pad.c b/types/wlr_tablet_pad.c new file mode 100644 index 00000000..3143345f --- /dev/null +++ b/types/wlr_tablet_pad.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include +#include "types.h" + +struct wlr_tablet_pad *wlr_tablet_pad_create(struct wlr_tablet_pad_impl *impl, + struct wlr_tablet_pad_state *state) { + struct wlr_tablet_pad *pad = calloc(1, sizeof(struct wlr_tablet_pad)); + pad->impl = impl; + pad->state = state; + wl_signal_init(&pad->events.button); + wl_signal_init(&pad->events.ring); + wl_signal_init(&pad->events.strip); + return pad; +} + +void wlr_tablet_pad_destroy(struct wlr_tablet_pad *pad) { + if (!pad) return; + if (pad->impl) { + pad->impl->destroy(pad->state); + } + free(pad); +} -- cgit v1.2.3 From 632a04f1b7dea35f46a2fa478bf53869854a1b5e Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 19 Jun 2017 15:15:37 -0400 Subject: Implement keyboard LEDs --- backend/libinput/keyboard.c | 23 ++++++++++++++++++++++- example/shared.c | 19 +++++++++++++++++++ example/shared.h | 1 + include/types.h | 1 + include/wlr/types.h | 10 ++++++++++ types/wlr_keyboard.c | 6 ++++++ 6 files changed, 59 insertions(+), 1 deletion(-) (limited to 'example/shared.h') diff --git a/backend/libinput/keyboard.c b/backend/libinput/keyboard.c index 9ad41a78..f94f0103 100644 --- a/backend/libinput/keyboard.c +++ b/backend/libinput/keyboard.c @@ -8,11 +8,32 @@ #include "common/log.h" #include "types.h" +struct wlr_keyboard_state { + struct libinput_device *device; +}; + +static void wlr_libinput_keyboard_set_leds(struct wlr_keyboard_state *kbstate, uint32_t leds) { + libinput_device_led_update(kbstate->device, leds); +} + +static void wlr_libinput_keyboard_destroy(struct wlr_keyboard_state *kbstate) { + libinput_device_unref(kbstate->device); + free(kbstate); +} + +struct wlr_keyboard_impl impl = { + .destroy = wlr_libinput_keyboard_destroy, + .led_update = wlr_libinput_keyboard_set_leds +}; + struct wlr_keyboard *wlr_libinput_keyboard_create( struct libinput_device *device) { assert(device); + struct wlr_keyboard_state *kbstate = calloc(1, sizeof(struct wlr_keyboard_state)); + kbstate->device = device; + libinput_device_ref(device); libinput_device_led_update(device, 0); - return wlr_keyboard_create(NULL, NULL); + return wlr_keyboard_create(&impl, kbstate); } void handle_keyboard_key(struct libinput_event *event, diff --git a/example/shared.c b/example/shared.c index 56cb89af..be1bdee7 100644 --- a/example/shared.c +++ b/example/shared.c @@ -12,6 +12,16 @@ #include #include "shared.h" +static void keyboard_led_update(struct keyboard_state *kbstate) { + uint32_t leds = 0; + for (uint32_t i = 0; i < WLR_LED_LAST; ++i) { + if (xkb_state_led_index_is_active(kbstate->xkb_state, kbstate->leds[i])) { + leds |= (1 << i); + } + } + wlr_keyboard_led_update(kbstate->device->keyboard, leds); +} + static void keyboard_key_notify(struct wl_listener *listener, void *data) { struct wlr_keyboard_key *event = data; struct keyboard_state *kbstate = wl_container_of(listener, kbstate, key); @@ -33,6 +43,7 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { } xkb_state_update_key(kbstate->xkb_state, keycode, event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); + keyboard_led_update(kbstate); } static void keyboard_add(struct wlr_input_device *device, struct compositor_state *state) { @@ -68,6 +79,14 @@ static void keyboard_add(struct wlr_input_device *device, struct compositor_stat fprintf(stderr, "Failed to create XKB state\n"); exit(1); } + const char *led_names[3] = { + XKB_LED_NAME_NUM, + XKB_LED_NAME_CAPS, + XKB_LED_NAME_SCROLL + }; + for (uint32_t i = 0; i < 3; ++i) { + kbstate->leds[i] = xkb_map_led_get_index(kbstate->keymap, led_names[i]); + } } static void pointer_motion_notify(struct wl_listener *listener, void *data) { diff --git a/example/shared.h b/example/shared.h index 173a5719..6d533443 100644 --- a/example/shared.h +++ b/example/shared.h @@ -25,6 +25,7 @@ struct keyboard_state { struct wl_list link; struct xkb_keymap *keymap; struct xkb_state *xkb_state; + xkb_led_index_t leds[WLR_LED_LAST]; void *data; }; diff --git a/include/types.h b/include/types.h index 2063c3f5..54aa5606 100644 --- a/include/types.h +++ b/include/types.h @@ -23,6 +23,7 @@ void wlr_output_free(struct wlr_output *output); struct wlr_keyboard_impl { void (*destroy)(struct wlr_keyboard_state *state); + void (*led_update)(struct wlr_keyboard_state *state, uint32_t leds); }; struct wlr_keyboard *wlr_keyboard_create(struct wlr_keyboard_impl *impl, diff --git a/include/wlr/types.h b/include/wlr/types.h index 2ca73cc2..1d2abab5 100644 --- a/include/wlr/types.h +++ b/include/wlr/types.h @@ -53,18 +53,28 @@ void wlr_output_destroy(struct wlr_output *output); void wlr_output_effective_resolution(struct wlr_output *output, int *width, int *height); +enum WLR_KEYBOARD_LED { + WLR_LED_NUM_LOCK = 1, + WLR_LED_CAPS_LOCK = 2, + WLR_LED_SCROLL_LOCK = 4, + WLR_LED_LAST +}; + struct wlr_keyboard_state; struct wlr_keyboard_impl; struct wlr_keyboard { struct wlr_keyboard_state *state; struct wlr_keyboard_impl *impl; + uint32_t leds; struct { struct wl_signal key; } events; }; +void wlr_keyboard_led_update(struct wlr_keyboard *keyboard, uint32_t leds); + enum wlr_key_state { WLR_KEY_RELEASED, WLR_KEY_PRESSED, diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 32728c78..c2ad5c49 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -21,3 +21,9 @@ void wlr_keyboard_destroy(struct wlr_keyboard *kb) { } free(kb); } + +void wlr_keyboard_led_update(struct wlr_keyboard *kb, uint32_t leds) { + if (kb->impl) { + kb->impl->led_update(kb->state, leds); + } +} -- cgit v1.2.3