pointer: release pressed buttons on destroy

This commit is contained in:
Kirill Primak 2024-08-14 20:23:45 +03:00 committed by Alexander Orzechowski
parent c752270be7
commit 56d69320c7
8 changed files with 38 additions and 6 deletions

View File

@ -69,7 +69,7 @@ void handle_pointer_button(struct libinput_event *event,
wlr_event.state = WL_POINTER_BUTTON_STATE_RELEASED; wlr_event.state = WL_POINTER_BUTTON_STATE_RELEASED;
break; break;
} }
wl_signal_emit_mutable(&pointer->events.button, &wlr_event); wlr_pointer_notify_button(pointer, &wlr_event);
wl_signal_emit_mutable(&pointer->events.frame, pointer); wl_signal_emit_mutable(&pointer->events.frame, pointer);
} }

View File

@ -112,7 +112,7 @@ static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
.state = state, .state = state,
.time_msec = time, .time_msec = time,
}; };
wl_signal_emit_mutable(&pointer->wlr_pointer.events.button, &event); wlr_pointer_notify_button(&pointer->wlr_pointer, &event);
} }
static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,

View File

@ -36,7 +36,7 @@ static void send_button_event(struct wlr_x11_output *output, uint32_t key,
.button = key, .button = key,
.state = st, .state = st,
}; };
wl_signal_emit_mutable(&output->pointer.events.button, &ev); wlr_pointer_notify_button(&output->pointer, &ev);
wl_signal_emit_mutable(&output->pointer.events.frame, &output->pointer); wl_signal_emit_mutable(&output->pointer.events.frame, &output->pointer);
} }

View File

@ -19,4 +19,7 @@ void wlr_pointer_init(struct wlr_pointer *pointer,
const struct wlr_pointer_impl *impl, const char *name); const struct wlr_pointer_impl *impl, const char *name);
void wlr_pointer_finish(struct wlr_pointer *pointer); void wlr_pointer_finish(struct wlr_pointer *pointer);
void wlr_pointer_notify_button(struct wlr_pointer *pointer,
struct wlr_pointer_button_event *event);
#endif #endif

View File

@ -14,6 +14,8 @@
#include <wayland-server-protocol.h> #include <wayland-server-protocol.h>
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>
#define WLR_POINTER_BUTTONS_CAP 16
struct wlr_pointer_impl; struct wlr_pointer_impl;
struct wlr_pointer { struct wlr_pointer {
@ -23,6 +25,9 @@ struct wlr_pointer {
char *output_name; char *output_name;
uint32_t buttons[WLR_POINTER_BUTTONS_CAP];
size_t button_count;
struct { struct {
struct wl_signal motion; // struct wlr_pointer_motion_event struct wl_signal motion; // struct wlr_pointer_motion_event
struct wl_signal motion_absolute; // struct wlr_pointer_motion_absolute_event struct wl_signal motion_absolute; // struct wlr_pointer_motion_absolute_event

View File

@ -170,8 +170,6 @@ struct wlr_seat_pointer_grab {
void *data; void *data;
}; };
#define WLR_POINTER_BUTTONS_CAP 16
struct wlr_seat_pointer_button { struct wlr_seat_pointer_button {
uint32_t button; uint32_t button;
size_t n_pressed; size_t n_pressed;

View File

@ -6,6 +6,8 @@
#include <wlr/types/wlr_pointer.h> #include <wlr/types/wlr_pointer.h>
#include "interfaces/wlr_input_device.h" #include "interfaces/wlr_input_device.h"
#include "util/set.h"
#include "util/time.h"
struct wlr_pointer *wlr_pointer_from_input_device( struct wlr_pointer *wlr_pointer_from_input_device(
struct wlr_input_device *input_device) { struct wlr_input_device *input_device) {
@ -36,7 +38,31 @@ void wlr_pointer_init(struct wlr_pointer *pointer,
} }
void wlr_pointer_finish(struct wlr_pointer *pointer) { void wlr_pointer_finish(struct wlr_pointer *pointer) {
int64_t time_msec = get_current_time_msec();
while (pointer->button_count > 0) {
struct wlr_pointer_button_event event = {
.pointer = pointer,
.time_msec = time_msec,
.button = pointer->buttons[pointer->button_count - 1],
.state = WL_POINTER_BUTTON_STATE_RELEASED,
};
wlr_pointer_notify_button(pointer, &event);
}
wlr_input_device_finish(&pointer->base); wlr_input_device_finish(&pointer->base);
free(pointer->output_name); free(pointer->output_name);
} }
void wlr_pointer_notify_button(struct wlr_pointer *pointer,
struct wlr_pointer_button_event *event) {
if (event->state == WL_POINTER_BUTTON_STATE_PRESSED) {
set_add(pointer->buttons, &pointer->button_count,
WLR_POINTER_BUTTONS_CAP, event->button);
} else {
set_remove(pointer->buttons, &pointer->button_count,
WLR_POINTER_BUTTONS_CAP, event->button);
}
wl_signal_emit_mutable(&pointer->events.button, event);
}

View File

@ -73,7 +73,7 @@ static void virtual_pointer_button(struct wl_client *client,
.button = button, .button = button,
.state = state ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED, .state = state ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED,
}; };
wl_signal_emit_mutable(&pointer->pointer.events.button, &event); wlr_pointer_notify_button(&pointer->pointer, &event);
} }
static void virtual_pointer_axis(struct wl_client *client, static void virtual_pointer_axis(struct wl_client *client,