diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 12892ba..a3c53e8 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -712,6 +712,8 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, func = centerwin; } else if (strcmp(func_name, "focuslast") == 0) { func = focuslast; + } else if (strcmp(func_name, "toggle_trackpad_enable") == 0) { + func = toggle_trackpad_enable; } else if (strcmp(func_name, "setlayout") == 0) { func = setlayout; (*arg).v = strdup(arg_value); diff --git a/src/dispatch/bind_declare.h b/src/dispatch/bind_declare.h index 1bc039d..764d1c7 100644 --- a/src/dispatch/bind_declare.h +++ b/src/dispatch/bind_declare.h @@ -60,4 +60,5 @@ void toggle_named_scratchpad(const Arg *arg); void toggle_render_border(const Arg *arg); void create_virtual_output(const Arg *arg); void destroy_all_virtual_output(const Arg *arg); -void focuslast(const Arg *arg); \ No newline at end of file +void focuslast(const Arg *arg); +void toggle_trackpad_enable(const Arg *arg); \ No newline at end of file diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index df2b8c6..2b0883e 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -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) { Client *c; Monitor *m = NULL; diff --git a/src/mango.c b/src/mango.c index b8a0ad6..e263e80 100644 --- a/src/mango.c +++ b/src/mango.c @@ -670,6 +670,7 @@ static const char *get_layout_abbr(const char *full_name); void apply_named_scratchpad(Client *target_client); Client *get_client_by_id_or_title(const char *arg_id, const char *arg_title); bool switch_scratchpad_client_state(Client *c); +bool check_trackpad_disabled(struct wlr_pointer *pointer); #include "data/static_keymap.h" #include "dispatch/bind_declare.h" @@ -1560,6 +1561,10 @@ axisnotify(struct wl_listener *listener, void *data) { handlecursoractivity(); wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); + if (check_trackpad_disabled(event->pointer)) { + return; + } + hard_keyboard = &kb_group->wlr_group->keyboard; 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); } +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 // 鼠标按键事件 buttonpress(struct wl_listener *listener, void *data) { struct wlr_pointer_button_event *event = data; @@ -1769,6 +1792,10 @@ buttonpress(struct wl_listener *listener, void *data) { handlecursoractivity(); wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); + if (check_trackpad_disabled(event->pointer)) { + return; + } + switch (event->state) { case WL_POINTER_BUTTON_STATE_PRESSED: cursor_mode = CurPressed; @@ -2652,11 +2679,6 @@ void createpointer(struct wlr_pointer *pointer) { 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) && - disable_trackpad) { - return; - } - if (libinput_device_config_tap_get_finger_count(device)) { libinput_device_config_tap_set_enabled(device, tap_to_click); 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; double lx, ly, dx, dy; + if (check_trackpad_disabled(event->pointer)) { + return; + } + if (!event->time_msec) /* this is 0 with virtual pointers */ wlr_cursor_warp_absolute(cursor, &event->pointer->base, event->x, event->y); @@ -3669,6 +3695,11 @@ void motionrelative(struct wl_listener *listener, void *data) { * special configuration applied for the specific input device which * generated the event. You can pass NULL for the device if you want to move * the cursor around without any input. */ + + if (check_trackpad_disabled(event->pointer)) { + return; + } + motionnotify(event->time_msec, &event->pointer->base, event->delta_x, event->delta_y, event->unaccel_dx, event->unaccel_dy); toggle_hotarea(cursor->x, cursor->y);