mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-23 10:29:49 +01:00
Handle tablet motion in example compositor
This commit is contained in:
parent
446adda1a3
commit
d558745633
3 changed files with 39 additions and 2 deletions
|
@ -7,6 +7,8 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <wayland-server.h>
|
||||
// TODO: BSD et al
|
||||
#include <linux/input-event-codes.h>
|
||||
#include <wlr/backend.h>
|
||||
#include <wlr/backend/session.h>
|
||||
#include <wlr/render.h>
|
||||
|
@ -59,6 +61,10 @@ struct sample_state {
|
|||
struct wl_listener cursor_button;
|
||||
struct wl_listener cursor_axis;
|
||||
|
||||
struct wl_listener tool_axis;
|
||||
struct wl_listener tool_tip;
|
||||
struct wl_listener tool_button;
|
||||
|
||||
struct wl_listener new_xdg_surface_v6;
|
||||
|
||||
struct wlr_xdg_surface_v6 *focused_surface;
|
||||
|
@ -431,6 +437,31 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
|||
event->button, event->state);
|
||||
}
|
||||
|
||||
static void handle_tool_axis(struct wl_listener *listener, void *data) {
|
||||
struct sample_state *sample =
|
||||
wl_container_of(listener, sample, tool_axis);
|
||||
struct wlr_event_tablet_tool_axis *event = data;
|
||||
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) &&
|
||||
(event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
|
||||
wlr_cursor_warp_absolute(sample->cursor, event->device,
|
||||
event->x_mm / event->width_mm, event->y_mm / event->height_mm);
|
||||
update_pointer_position(sample, event->time_sec);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_tool_tip(struct wl_listener *listener, void *data) {
|
||||
struct sample_state *sample =
|
||||
wl_container_of(listener, sample, tool_tip);
|
||||
struct wlr_event_tablet_tool_tip *event = data;
|
||||
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
example_xdg_surface_at(sample, sample->cursor->x, sample->cursor->y);
|
||||
example_set_focused_surface(sample, surface);
|
||||
|
||||
wlr_seat_pointer_send_button(sample->wl_seat, event->time_sec,
|
||||
BTN_MOUSE, event->state);
|
||||
}
|
||||
|
||||
static void handle_input_add(struct compositor_state *state,
|
||||
struct wlr_input_device *device) {
|
||||
struct sample_state *sample = state->data;
|
||||
|
@ -528,6 +559,12 @@ int main(int argc, char *argv[]) {
|
|||
wl_signal_add(&state.cursor->events.axis, &state.cursor_axis);
|
||||
state.cursor_axis.notify = handle_cursor_axis;
|
||||
|
||||
wl_signal_add(&state.cursor->events.tablet_tool_axis, &state.tool_axis);
|
||||
state.tool_axis.notify = handle_tool_axis;
|
||||
|
||||
wl_signal_add(&state.cursor->events.tablet_tool_tip, &state.tool_tip);
|
||||
state.tool_tip.notify = handle_tool_tip;
|
||||
|
||||
compositor_init(&compositor);
|
||||
|
||||
state.renderer = wlr_gles2_renderer_create(compositor.backend);
|
||||
|
|
|
@ -107,6 +107,6 @@ void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time,
|
|||
* button event are surface-local.
|
||||
*/
|
||||
void wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time,
|
||||
uint32_t button, enum wlr_button_state state);
|
||||
uint32_t button, uint32_t state);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -338,7 +338,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, enum wlr_button_state state) {
|
||||
uint32_t button, uint32_t state) {
|
||||
if (!wlr_seat->pointer_state.focused_handle) {
|
||||
// nobody to send the event to
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue