mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-05-10 23:50:41 -04:00
opt: distinguish the acceleration of trackpad and mouse
This commit is contained in:
parent
23f2e3d3cc
commit
178840f35e
4 changed files with 108 additions and 71 deletions
|
|
@ -257,24 +257,33 @@ typedef struct {
|
|||
int32_t repeat_delay;
|
||||
uint32_t numlockon;
|
||||
|
||||
/* Trackpad */
|
||||
int32_t disable_trackpad;
|
||||
int32_t tap_to_click;
|
||||
int32_t tap_and_drag;
|
||||
int32_t drag_lock;
|
||||
int32_t mouse_natural_scrolling;
|
||||
int32_t trackpad_natural_scrolling;
|
||||
/* common pointer */
|
||||
int32_t disable_while_typing;
|
||||
int32_t left_handed;
|
||||
int32_t middle_button_emulation;
|
||||
uint32_t accel_profile;
|
||||
double accel_speed;
|
||||
uint32_t scroll_method;
|
||||
uint32_t scroll_button;
|
||||
uint32_t click_method;
|
||||
uint32_t send_events_mode;
|
||||
uint32_t button_map;
|
||||
|
||||
/* mouse */
|
||||
int32_t mouse_natural_scrolling;
|
||||
uint32_t mouse_accel_profile;
|
||||
double mouse_accel_speed;
|
||||
double axis_scroll_factor;
|
||||
|
||||
/* Trackpad */
|
||||
int32_t trackpad_natural_scrolling;
|
||||
uint32_t trackpad_accel_profile;
|
||||
double trackpad_accel_speed;
|
||||
double trackpad_scroll_factor;
|
||||
int32_t disable_trackpad;
|
||||
int32_t tap_to_click;
|
||||
int32_t tap_and_drag;
|
||||
int32_t drag_lock;
|
||||
uint32_t button_map;
|
||||
|
||||
/* appearance */
|
||||
int32_t smartgaps;
|
||||
uint32_t gappih;
|
||||
uint32_t gappiv;
|
||||
|
|
@ -1603,10 +1612,14 @@ bool parse_option(Config *config, char *key, char *value) {
|
|||
config->left_handed = atoi(value);
|
||||
} else if (strcmp(key, "middle_button_emulation") == 0) {
|
||||
config->middle_button_emulation = atoi(value);
|
||||
} else if (strcmp(key, "accel_profile") == 0) {
|
||||
config->accel_profile = atoi(value);
|
||||
} else if (strcmp(key, "accel_speed") == 0) {
|
||||
config->accel_speed = atof(value);
|
||||
} else if (strcmp(key, "mouse_accel_profile") == 0) {
|
||||
config->mouse_accel_profile = atoi(value);
|
||||
} else if (strcmp(key, "mouse_accel_speed") == 0) {
|
||||
config->mouse_accel_speed = atof(value);
|
||||
} else if (strcmp(key, "trackpad_accel_profile") == 0) {
|
||||
config->trackpad_accel_profile = atoi(value);
|
||||
} else if (strcmp(key, "trackpad_accel_speed") == 0) {
|
||||
config->trackpad_accel_speed = atof(value);
|
||||
} else if (strcmp(key, "scroll_method") == 0) {
|
||||
config->scroll_method = atoi(value);
|
||||
} else if (strcmp(key, "scroll_button") == 0) {
|
||||
|
|
@ -1619,6 +1632,8 @@ bool parse_option(Config *config, char *key, char *value) {
|
|||
config->button_map = atoi(value);
|
||||
} else if (strcmp(key, "axis_scroll_factor") == 0) {
|
||||
config->axis_scroll_factor = atof(value);
|
||||
} else if (strcmp(key, "trackpad_scroll_factor") == 0) {
|
||||
config->trackpad_scroll_factor = atof(value);
|
||||
} else if (strcmp(key, "gappih") == 0) {
|
||||
config->gappih = atoi(value);
|
||||
} else if (strcmp(key, "gappiv") == 0) {
|
||||
|
|
@ -3120,8 +3135,13 @@ void override_config(void) {
|
|||
config.swipe_min_threshold = CLAMP_INT(config.swipe_min_threshold, 1, 1000);
|
||||
config.mouse_natural_scrolling =
|
||||
CLAMP_INT(config.mouse_natural_scrolling, 0, 1);
|
||||
config.accel_profile = CLAMP_INT(config.accel_profile, 0, 2);
|
||||
config.accel_speed = CLAMP_FLOAT(config.accel_speed, -1.0f, 1.0f);
|
||||
config.mouse_accel_profile = CLAMP_INT(config.mouse_accel_profile, 0, 2);
|
||||
config.mouse_accel_speed =
|
||||
CLAMP_FLOAT(config.mouse_accel_speed, -1.0f, 1.0f);
|
||||
config.trackpad_accel_profile =
|
||||
CLAMP_INT(config.trackpad_accel_profile, 0, 2);
|
||||
config.trackpad_accel_speed =
|
||||
CLAMP_FLOAT(config.trackpad_accel_speed, -1.0f, 1.0f);
|
||||
config.scroll_method = CLAMP_INT(config.scroll_method, 0, 4);
|
||||
config.scroll_button = CLAMP_INT(config.scroll_button, 272, 279);
|
||||
config.click_method = CLAMP_INT(config.click_method, 0, 2);
|
||||
|
|
@ -3129,6 +3149,8 @@ void override_config(void) {
|
|||
config.button_map = CLAMP_INT(config.button_map, 0, 1);
|
||||
config.axis_scroll_factor =
|
||||
CLAMP_FLOAT(config.axis_scroll_factor, 0.1f, 10.0f);
|
||||
config.trackpad_scroll_factor =
|
||||
CLAMP_FLOAT(config.trackpad_scroll_factor, 0.1f, 10.0f);
|
||||
config.gappih = CLAMP_INT(config.gappih, 0, 1000);
|
||||
config.gappiv = CLAMP_INT(config.gappiv, 0, 1000);
|
||||
config.gappoh = CLAMP_INT(config.gappoh, 0, 1000);
|
||||
|
|
@ -3198,6 +3220,7 @@ void set_value_default() {
|
|||
config.scratchpad_cross_monitor = 0;
|
||||
config.focus_cross_tag = 0;
|
||||
config.axis_scroll_factor = 1.0;
|
||||
config.trackpad_scroll_factor = 1.0;
|
||||
config.view_current_to_back = 0;
|
||||
config.single_scratchpad = 1;
|
||||
config.xwayland_persistence = 1;
|
||||
|
|
@ -3237,8 +3260,10 @@ void set_value_default() {
|
|||
config.disable_while_typing = 1;
|
||||
config.left_handed = 0;
|
||||
config.middle_button_emulation = 0;
|
||||
config.accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
|
||||
config.accel_speed = 0.0;
|
||||
config.mouse_accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
|
||||
config.mouse_accel_speed = 0.0;
|
||||
config.trackpad_accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
|
||||
config.trackpad_accel_speed = 0.0;
|
||||
config.scroll_method = LIBINPUT_CONFIG_SCROLL_2FG;
|
||||
config.scroll_button = 274;
|
||||
config.click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
|
||||
|
|
|
|||
74
src/mango.c
74
src/mango.c
|
|
@ -1857,9 +1857,21 @@ void arrangelayers(Monitor *m) {
|
|||
arrangelayer(m, &m->layers[i], &usable_area, 0);
|
||||
}
|
||||
|
||||
bool pointer_is_trackpad(struct wlr_pointer *pointer) {
|
||||
struct libinput_device *device;
|
||||
|
||||
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 // 鼠标滚轮事件
|
||||
axisnotify(struct wl_listener *listener, void *data) {
|
||||
|
||||
/* This event is forwarded by the cursor when a pointer emits an axis event,
|
||||
* for example when you move the scroll wheel. */
|
||||
struct wlr_pointer_axis_event *event = data;
|
||||
|
|
@ -1868,6 +1880,7 @@ axisnotify(struct wl_listener *listener, void *data) {
|
|||
AxisBinding *a;
|
||||
int32_t ji;
|
||||
uint32_t adir;
|
||||
double target_scroll_factor;
|
||||
// IDLE_NOTIFY_ACTIVITY;
|
||||
handlecursoractivity();
|
||||
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
|
||||
|
|
@ -1914,12 +1927,17 @@ axisnotify(struct wl_listener *listener, void *data) {
|
|||
* implemented checking the event's orientation and the delta of the event
|
||||
*/
|
||||
/* Notify the client with pointer focus of the axis event. */
|
||||
|
||||
target_scroll_factor = pointer_is_trackpad(event->pointer)
|
||||
? config.axis_scroll_factor
|
||||
: config.trackpad_scroll_factor;
|
||||
|
||||
wlr_seat_pointer_notify_axis(
|
||||
seat, // 滚轮事件发送给客户端也就是窗口
|
||||
event->time_msec, event->orientation,
|
||||
event->delta * config.axis_scroll_factor,
|
||||
roundf(event->delta_discrete * config.axis_scroll_factor),
|
||||
event->source, event->relative_direction);
|
||||
roundf(event->delta_discrete * target_scroll_factor), event->source,
|
||||
event->relative_direction);
|
||||
}
|
||||
|
||||
int32_t ongesture(struct wlr_pointer_swipe_end_event *event) {
|
||||
|
|
@ -2073,21 +2091,11 @@ void place_drag_tile_client(Client *c) {
|
|||
}
|
||||
|
||||
bool check_trackpad_disabled(struct wlr_pointer *pointer) {
|
||||
struct libinput_device *device;
|
||||
|
||||
if (!config.disable_trackpad)
|
||||
if (!config.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;
|
||||
return pointer_is_trackpad(pointer);
|
||||
}
|
||||
|
||||
void // 鼠标按键事件
|
||||
|
|
@ -3159,6 +3167,22 @@ void destroyinputdevice(struct wl_listener *listener, void *data) {
|
|||
free(input_dev);
|
||||
}
|
||||
|
||||
void pointer_set_accel(struct libinput_device *device, bool natural_scrolling,
|
||||
uint32_t mouse_accel_profile, double mouse_accel_speed) {
|
||||
libinput_device_config_scroll_set_natural_scroll_enabled(device,
|
||||
natural_scrolling);
|
||||
if (mouse_accel_profile &&
|
||||
libinput_device_config_accel_is_available(device)) {
|
||||
libinput_device_config_accel_set_profile(device, mouse_accel_profile);
|
||||
libinput_device_config_accel_set_speed(device, mouse_accel_speed);
|
||||
} else {
|
||||
// profile cannot be directly applied to 0, need to set to 1 first
|
||||
libinput_device_config_accel_set_profile(device, 1);
|
||||
libinput_device_config_accel_set_profile(device, 0);
|
||||
libinput_device_config_accel_set_speed(device, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void configure_pointer(struct libinput_device *device) {
|
||||
if (libinput_device_config_tap_get_finger_count(device)) {
|
||||
libinput_device_config_tap_set_enabled(device, config.tap_to_click);
|
||||
|
|
@ -3167,11 +3191,12 @@ void configure_pointer(struct libinput_device *device) {
|
|||
libinput_device_config_tap_set_drag_lock_enabled(device,
|
||||
config.drag_lock);
|
||||
libinput_device_config_tap_set_button_map(device, config.button_map);
|
||||
libinput_device_config_scroll_set_natural_scroll_enabled(
|
||||
device, config.trackpad_natural_scrolling);
|
||||
pointer_set_accel(device, config.trackpad_natural_scrolling,
|
||||
config.trackpad_accel_profile,
|
||||
config.trackpad_accel_speed);
|
||||
} else {
|
||||
libinput_device_config_scroll_set_natural_scroll_enabled(
|
||||
device, config.mouse_natural_scrolling);
|
||||
pointer_set_accel(device, config.mouse_natural_scrolling,
|
||||
config.mouse_accel_profile, config.mouse_accel_speed);
|
||||
}
|
||||
|
||||
if (libinput_device_config_dwt_is_available(device))
|
||||
|
|
@ -3199,17 +3224,6 @@ void configure_pointer(struct libinput_device *device) {
|
|||
if (libinput_device_config_send_events_get_modes(device))
|
||||
libinput_device_config_send_events_set_mode(device,
|
||||
config.send_events_mode);
|
||||
|
||||
if (config.accel_profile &&
|
||||
libinput_device_config_accel_is_available(device)) {
|
||||
libinput_device_config_accel_set_profile(device, config.accel_profile);
|
||||
libinput_device_config_accel_set_speed(device, config.accel_speed);
|
||||
} else {
|
||||
// profile cannot be directly applied to 0, need to set to 1 first
|
||||
libinput_device_config_accel_set_profile(device, 1);
|
||||
libinput_device_config_accel_set_profile(device, 0);
|
||||
libinput_device_config_accel_set_speed(device, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void createpointer(struct wlr_pointer *pointer) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue