feat: hot-reload pointer setting in config

This commit is contained in:
DreamMaoMao 2025-09-03 12:48:02 +08:00
parent 8afcde6265
commit b189d7a2be
2 changed files with 88 additions and 43 deletions

View file

@ -2537,6 +2537,17 @@ void reapply_keyboard(void) {
} }
} }
void reapply_pointer(void) {
struct input_device *id;
struct libinput_device *device;
wl_list_for_each(id, &pointers, link) {
device = id->libinput_device;
if (wlr_input_device_is_libinput(id->wlr_device) && device) {
configure_pointer(device);
}
}
}
void reapply_master(void) { void reapply_master(void) {
int i; int i;
@ -2594,6 +2605,7 @@ void reload_config(const Arg *arg) {
reapply_border(); reapply_border();
reapply_keyboard(); reapply_keyboard();
reapply_pointer();
reapply_master(); reapply_master();
reapply_tagrule(); reapply_tagrule();

View file

@ -190,6 +190,13 @@ typedef struct {
const Arg arg; const Arg arg;
} Axis; } Axis;
struct input_device {
struct wl_list link;
struct wlr_input_device *wlr_device;
struct libinput_device *libinput_device;
struct wl_listener destroy_listener; // 用于监听设备销毁事件
};
struct dwl_animation { struct dwl_animation {
bool should_animate; bool should_animate;
bool running; bool running;
@ -506,6 +513,8 @@ static void createlocksurface(struct wl_listener *listener, void *data);
static void createmon(struct wl_listener *listener, void *data); static void createmon(struct wl_listener *listener, void *data);
static void createnotify(struct wl_listener *listener, void *data); static void createnotify(struct wl_listener *listener, void *data);
static void createpointer(struct wlr_pointer *pointer); static void createpointer(struct wlr_pointer *pointer);
static void configure_pointer(struct libinput_device *device);
static void destroypointer(struct wl_listener *listener, void *data);
static void createpointerconstraint(struct wl_listener *listener, void *data); static void createpointerconstraint(struct wl_listener *listener, void *data);
static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint); static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint);
static void commitpopup(struct wl_listener *listener, void *data); static void commitpopup(struct wl_listener *listener, void *data);
@ -732,6 +741,7 @@ static struct wlr_pointer_constraint_v1 *active_constraint;
static struct wlr_seat *seat; static struct wlr_seat *seat;
static KeyboardGroup *kb_group; static KeyboardGroup *kb_group;
static struct wl_list keyboards; static struct wl_list keyboards;
static struct wl_list pointers;
static unsigned int cursor_mode; static unsigned int cursor_mode;
static Client *grabc; static Client *grabc;
static int grabcx, grabcy; /* client-relative */ static int grabcx, grabcy; /* client-relative */
@ -2619,11 +2629,19 @@ createnotify(struct wl_listener *listener, void *data) {
LISTEN(&toplevel->events.set_title, &c->set_title, updatetitle); LISTEN(&toplevel->events.set_title, &c->set_title, updatetitle);
} }
void createpointer(struct wlr_pointer *pointer) { void destroypointer(struct wl_listener *listener, void *data) {
struct libinput_device *device; struct input_device *input_dev =
if (wlr_input_device_is_libinput(&pointer->base) && wl_container_of(listener, input_dev, destroy_listener);
(device = wlr_libinput_get_device_handle(&pointer->base))) {
// 从设备列表中移除
wl_list_remove(&input_dev->link);
// 移除监听器
wl_list_remove(&input_dev->destroy_listener.link);
// 释放内存
free(input_dev);
}
void configure_pointer(struct libinput_device *device) {
if (libinput_device_config_tap_get_finger_count(device)) { if (libinput_device_config_tap_get_finger_count(device)) {
libinput_device_config_tap_set_enabled(device, tap_to_click); libinput_device_config_tap_set_enabled(device, tap_to_click);
libinput_device_config_tap_set_drag_enabled(device, tap_and_drag); libinput_device_config_tap_set_drag_enabled(device, tap_and_drag);
@ -2637,8 +2655,7 @@ void createpointer(struct wlr_pointer *pointer) {
} }
if (libinput_device_config_dwt_is_available(device)) if (libinput_device_config_dwt_is_available(device))
libinput_device_config_dwt_set_enabled(device, libinput_device_config_dwt_set_enabled(device, disable_while_typing);
disable_while_typing);
if (libinput_device_config_left_handed_is_available(device)) if (libinput_device_config_left_handed_is_available(device))
libinput_device_config_left_handed_set(device, left_handed); libinput_device_config_left_handed_set(device, left_handed);
@ -2659,15 +2676,30 @@ void createpointer(struct wlr_pointer *pointer) {
libinput_device_config_click_set_method(device, click_method); libinput_device_config_click_set_method(device, click_method);
if (libinput_device_config_send_events_get_modes(device)) if (libinput_device_config_send_events_get_modes(device))
libinput_device_config_send_events_set_mode(device, libinput_device_config_send_events_set_mode(device, send_events_mode);
send_events_mode);
if (libinput_device_config_accel_is_available(device)) { if (libinput_device_config_accel_is_available(device)) {
libinput_device_config_accel_set_profile(device, accel_profile); libinput_device_config_accel_set_profile(device, accel_profile);
libinput_device_config_accel_set_speed(device, accel_speed); libinput_device_config_accel_set_speed(device, accel_speed);
} }
}
void createpointer(struct wlr_pointer *pointer) {
struct libinput_device *device;
if (wlr_input_device_is_libinput(&pointer->base) &&
(device = wlr_libinput_get_device_handle(&pointer->base))) {
configure_pointer(device);
} }
struct input_device *input_dev = calloc(1, sizeof(struct input_device));
input_dev->wlr_device = &pointer->base;
input_dev->libinput_device = device;
input_dev->destroy_listener.notify = destroypointer;
wl_signal_add(&pointer->base.events.destroy, &input_dev->destroy_listener);
wl_list_insert(&pointers, &input_dev->link);
wlr_cursor_attach_input_device(cursor, &pointer->base); wlr_cursor_attach_input_device(cursor, &pointer->base);
} }
@ -4594,6 +4626,7 @@ void setup(void) {
* let us know when new input devices are available on the backend. * let us know when new input devices are available on the backend.
*/ */
wl_list_init(&keyboards); wl_list_init(&keyboards);
wl_list_init(&pointers);
wl_signal_add(&backend->events.new_input, &new_input_device); wl_signal_add(&backend->events.new_input, &new_input_device);
virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy); virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy);
wl_signal_add(&virtual_keyboard_mgr->events.new_virtual_keyboard, wl_signal_add(&virtual_keyboard_mgr->events.new_virtual_keyboard,