feat: add dispatch toggle_trackpad_enable

This commit is contained in:
DreamMaoMao 2025-09-03 11:59:50 +08:00
parent 76aafa0bd0
commit 4768ef2c29
4 changed files with 44 additions and 6 deletions

View file

@ -712,6 +712,8 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value,
func = centerwin; func = centerwin;
} else if (strcmp(func_name, "focuslast") == 0) { } else if (strcmp(func_name, "focuslast") == 0) {
func = focuslast; func = focuslast;
} else if (strcmp(func_name, "toggle_trackpad_enable") == 0) {
func = toggle_trackpad_enable;
} else if (strcmp(func_name, "setlayout") == 0) { } else if (strcmp(func_name, "setlayout") == 0) {
func = setlayout; func = setlayout;
(*arg).v = strdup(arg_value); (*arg).v = strdup(arg_value);

View file

@ -60,4 +60,5 @@ void toggle_named_scratchpad(const Arg *arg);
void toggle_render_border(const Arg *arg); void toggle_render_border(const Arg *arg);
void create_virtual_output(const Arg *arg); void create_virtual_output(const Arg *arg);
void destroy_all_virtual_output(const Arg *arg); void destroy_all_virtual_output(const Arg *arg);
void focuslast(const Arg *arg); void focuslast(const Arg *arg);
void toggle_trackpad_enable(const Arg *arg);

View file

@ -124,6 +124,10 @@ void focuslast(const Arg *arg) {
} }
} }
void toggle_trackpad_enable(const Arg *arg) {
disable_trackpad = !disable_trackpad;
}
void focusmon(const Arg *arg) { void focusmon(const Arg *arg) {
Client *c; Client *c;
Monitor *m = NULL; Monitor *m = NULL;

View file

@ -670,6 +670,7 @@ static const char *get_layout_abbr(const char *full_name);
void apply_named_scratchpad(Client *target_client); void apply_named_scratchpad(Client *target_client);
Client *get_client_by_id_or_title(const char *arg_id, const char *arg_title); Client *get_client_by_id_or_title(const char *arg_id, const char *arg_title);
bool switch_scratchpad_client_state(Client *c); bool switch_scratchpad_client_state(Client *c);
bool check_trackpad_disabled(struct wlr_pointer *pointer);
#include "data/static_keymap.h" #include "data/static_keymap.h"
#include "dispatch/bind_declare.h" #include "dispatch/bind_declare.h"
@ -1560,6 +1561,10 @@ axisnotify(struct wl_listener *listener, void *data) {
handlecursoractivity(); handlecursoractivity();
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
if (check_trackpad_disabled(event->pointer)) {
return;
}
hard_keyboard = &kb_group->wlr_group->keyboard; hard_keyboard = &kb_group->wlr_group->keyboard;
hard_mods = hard_keyboard ? wlr_keyboard_get_modifiers(hard_keyboard) : 0; hard_mods = hard_keyboard ? wlr_keyboard_get_modifiers(hard_keyboard) : 0;
@ -1752,6 +1757,24 @@ void place_drag_tile_client(Client *c) {
setfloating(c, 0); setfloating(c, 0);
} }
bool check_trackpad_disabled(struct wlr_pointer *pointer) {
struct libinput_device *device;
if (!disable_trackpad)
return false;
if (wlr_input_device_is_libinput(&pointer->base) &&
(device = wlr_libinput_get_device_handle(&pointer->base))) {
// 如果是触摸板且被禁用,忽略事件
if (libinput_device_config_tap_get_finger_count(device) > 0) {
return true; // 不处理事件
}
}
return false;
}
void // 鼠标按键事件 void // 鼠标按键事件
buttonpress(struct wl_listener *listener, void *data) { buttonpress(struct wl_listener *listener, void *data) {
struct wlr_pointer_button_event *event = data; struct wlr_pointer_button_event *event = data;
@ -1769,6 +1792,10 @@ buttonpress(struct wl_listener *listener, void *data) {
handlecursoractivity(); handlecursoractivity();
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
if (check_trackpad_disabled(event->pointer)) {
return;
}
switch (event->state) { switch (event->state) {
case WL_POINTER_BUTTON_STATE_PRESSED: case WL_POINTER_BUTTON_STATE_PRESSED:
cursor_mode = CurPressed; cursor_mode = CurPressed;
@ -2652,11 +2679,6 @@ void createpointer(struct wlr_pointer *pointer) {
if (wlr_input_device_is_libinput(&pointer->base) && if (wlr_input_device_is_libinput(&pointer->base) &&
(device = wlr_libinput_get_device_handle(&pointer->base))) { (device = wlr_libinput_get_device_handle(&pointer->base))) {
if (libinput_device_config_tap_get_finger_count(device) &&
disable_trackpad) {
return;
}
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);
@ -3530,6 +3552,10 @@ void motionabsolute(struct wl_listener *listener, void *data) {
struct wlr_pointer_motion_absolute_event *event = data; struct wlr_pointer_motion_absolute_event *event = data;
double lx, ly, dx, dy; double lx, ly, dx, dy;
if (check_trackpad_disabled(event->pointer)) {
return;
}
if (!event->time_msec) /* this is 0 with virtual pointers */ if (!event->time_msec) /* this is 0 with virtual pointers */
wlr_cursor_warp_absolute(cursor, &event->pointer->base, event->x, wlr_cursor_warp_absolute(cursor, &event->pointer->base, event->x,
event->y); event->y);
@ -3669,6 +3695,11 @@ void motionrelative(struct wl_listener *listener, void *data) {
* special configuration applied for the specific input device which * special configuration applied for the specific input device which
* generated the event. You can pass NULL for the device if you want to move * generated the event. You can pass NULL for the device if you want to move
* the cursor around without any input. */ * the cursor around without any input. */
if (check_trackpad_disabled(event->pointer)) {
return;
}
motionnotify(event->time_msec, &event->pointer->base, event->delta_x, motionnotify(event->time_msec, &event->pointer->base, event->delta_x,
event->delta_y, event->unaccel_dx, event->unaccel_dy); event->delta_y, event->unaccel_dx, event->unaccel_dy);
toggle_hotarea(cursor->x, cursor->y); toggle_hotarea(cursor->x, cursor->y);