mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-09 23:25:57 +01:00
add sensitivity per device & reload mice on config
This commit is contained in:
parent
1ba600ca23
commit
d52446135b
3 changed files with 63 additions and 37 deletions
|
@ -108,6 +108,7 @@ void CConfigManager::setDefaultVars() {
|
||||||
configValues["animations:workspaces_speed"].floatValue = 0.f;
|
configValues["animations:workspaces_speed"].floatValue = 0.f;
|
||||||
configValues["animations:workspaces"].intValue = 1;
|
configValues["animations:workspaces"].intValue = 1;
|
||||||
|
|
||||||
|
configValues["input:sensitivity"].floatValue = 0.f;
|
||||||
configValues["input:kb_layout"].strValue = "us";
|
configValues["input:kb_layout"].strValue = "us";
|
||||||
configValues["input:kb_variant"].strValue = STRVAL_EMPTY;
|
configValues["input:kb_variant"].strValue = STRVAL_EMPTY;
|
||||||
configValues["input:kb_options"].strValue = STRVAL_EMPTY;
|
configValues["input:kb_options"].strValue = STRVAL_EMPTY;
|
||||||
|
@ -140,6 +141,7 @@ void CConfigManager::setDefaultVars() {
|
||||||
void CConfigManager::setDeviceDefaultVars(const std::string& dev) {
|
void CConfigManager::setDeviceDefaultVars(const std::string& dev) {
|
||||||
auto& cfgValues = deviceConfigs[dev];
|
auto& cfgValues = deviceConfigs[dev];
|
||||||
|
|
||||||
|
cfgValues["sensitivity"].floatValue = 0.f;
|
||||||
cfgValues["kb_layout"].strValue = "us";
|
cfgValues["kb_layout"].strValue = "us";
|
||||||
cfgValues["kb_variant"].strValue = STRVAL_EMPTY;
|
cfgValues["kb_variant"].strValue = STRVAL_EMPTY;
|
||||||
cfgValues["kb_options"].strValue = STRVAL_EMPTY;
|
cfgValues["kb_options"].strValue = STRVAL_EMPTY;
|
||||||
|
@ -902,8 +904,10 @@ void CConfigManager::loadConfigLoadVars() {
|
||||||
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);
|
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);
|
||||||
|
|
||||||
// Update the keyboard layout to the cfg'd one if this is not the first launch
|
// Update the keyboard layout to the cfg'd one if this is not the first launch
|
||||||
if (!isFirstLaunch)
|
if (!isFirstLaunch) {
|
||||||
g_pInputManager->setKeyboardLayout();
|
g_pInputManager->setKeyboardLayout();
|
||||||
|
g_pInputManager->setMouseConfigs();
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate the internal vars
|
// Calculate the internal vars
|
||||||
configValues["general:main_mod_internal"].intValue = g_pKeybindManager->stringToModMask(configValues["general:main_mod"].strValue);
|
configValues["general:main_mod_internal"].intValue = g_pKeybindManager->stringToModMask(configValues["general:main_mod"].strValue);
|
||||||
|
|
|
@ -522,47 +522,14 @@ void CInputManager::newMouse(wlr_input_device* mouse, bool virt) {
|
||||||
Debug::log(ERR, "Mouse had no name???"); // logic error
|
Debug::log(ERR, "Mouse had no name???"); // logic error
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto HASCONFIG = g_pConfigManager->deviceConfigExists(PMOUSE->name);
|
|
||||||
|
|
||||||
if (wlr_input_device_is_libinput(mouse)) {
|
if (wlr_input_device_is_libinput(mouse)) {
|
||||||
const auto LIBINPUTDEV = (libinput_device*)wlr_libinput_get_device_handle(mouse);
|
const auto LIBINPUTDEV = (libinput_device*)wlr_libinput_get_device_handle(mouse);
|
||||||
|
|
||||||
if ((HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "clickfinger_behavior") : g_pConfigManager->getInt("input:touchpad:clickfinger_behavior")) == 0) // toggle software buttons or clickfinger
|
Debug::log(LOG, "New mouse has libinput sens %.2f (%.2f) with accel profile %i (%i)", libinput_device_config_accel_get_speed(LIBINPUTDEV), libinput_device_config_accel_get_default_speed(LIBINPUTDEV), libinput_device_config_accel_get_profile(LIBINPUTDEV), libinput_device_config_accel_get_default_profile(LIBINPUTDEV));
|
||||||
libinput_device_config_click_set_method(LIBINPUTDEV, LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
|
|
||||||
else
|
|
||||||
libinput_device_config_click_set_method(LIBINPUTDEV, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
|
|
||||||
|
|
||||||
if (libinput_device_config_middle_emulation_is_available(LIBINPUTDEV)) { // middleclick on r+l mouse button pressed
|
|
||||||
if ((HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "middle_button_emulation") : g_pConfigManager->getInt("input:touchpad:middle_button_emulation")) == 1)
|
|
||||||
libinput_device_config_middle_emulation_set_enabled(LIBINPUTDEV, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED);
|
|
||||||
else
|
|
||||||
libinput_device_config_middle_emulation_set_enabled(LIBINPUTDEV, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "drag_lock") : g_pConfigManager->getInt("input:touchpad:drag_lock")) == 0)
|
|
||||||
libinput_device_config_tap_set_drag_lock_enabled(LIBINPUTDEV, LIBINPUT_CONFIG_DRAG_LOCK_DISABLED);
|
|
||||||
else
|
|
||||||
libinput_device_config_tap_set_drag_lock_enabled(LIBINPUTDEV, LIBINPUT_CONFIG_DRAG_LOCK_ENABLED);
|
|
||||||
|
|
||||||
if (libinput_device_config_tap_get_finger_count(LIBINPUTDEV)) // this is for tapping (like on a laptop)
|
|
||||||
if ((HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "tap-to-click") : g_pConfigManager->getInt("input:touchpad:tap-to-click")) == 1)
|
|
||||||
libinput_device_config_tap_set_enabled(LIBINPUTDEV, LIBINPUT_CONFIG_TAP_ENABLED);
|
|
||||||
|
|
||||||
if (libinput_device_config_scroll_has_natural_scroll(LIBINPUTDEV)) {
|
|
||||||
double w = 0, h = 0;
|
|
||||||
|
|
||||||
if (libinput_device_has_capability(LIBINPUTDEV, LIBINPUT_DEVICE_CAP_POINTER) && libinput_device_get_size(LIBINPUTDEV, &w, &h) == 0) // pointer with size is a touchpad
|
|
||||||
libinput_device_config_scroll_set_natural_scroll_enabled(LIBINPUTDEV, (HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "natural_scroll") : g_pConfigManager->getInt("input:touchpad:natural_scroll")));
|
|
||||||
else
|
|
||||||
libinput_device_config_scroll_set_natural_scroll_enabled(LIBINPUTDEV, (HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "natural_scroll") : g_pConfigManager->getInt("input:natural_scroll")));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (libinput_device_config_dwt_is_available(LIBINPUTDEV)) {
|
|
||||||
const auto DWT = static_cast<enum libinput_config_dwt_state>((HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "disable_while_typing") : g_pConfigManager->getInt("input:touchpad:disable_while_typing")) != 0);
|
|
||||||
libinput_device_config_dwt_set_enabled(LIBINPUTDEV, DWT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setMouseConfigs();
|
||||||
|
|
||||||
PMOUSE->hyprListener_destroyMouse.initCallback(&mouse->events.destroy, &Events::listener_destroyMouse, PMOUSE, "Mouse");
|
PMOUSE->hyprListener_destroyMouse.initCallback(&mouse->events.destroy, &Events::listener_destroyMouse, PMOUSE, "Mouse");
|
||||||
|
|
||||||
wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, mouse);
|
wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, mouse);
|
||||||
|
@ -574,6 +541,60 @@ void CInputManager::newMouse(wlr_input_device* mouse, bool virt) {
|
||||||
Debug::log(LOG, "New mouse created, pointer WLR: %x", mouse);
|
Debug::log(LOG, "New mouse created, pointer WLR: %x", mouse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CInputManager::setMouseConfigs() {
|
||||||
|
for (auto& m : m_lMice) {
|
||||||
|
const auto PMOUSE = &m;
|
||||||
|
|
||||||
|
const auto HASCONFIG = g_pConfigManager->deviceConfigExists(PMOUSE->name);
|
||||||
|
|
||||||
|
if (wlr_input_device_is_libinput(m.mouse)) {
|
||||||
|
const auto LIBINPUTDEV = (libinput_device*)wlr_libinput_get_device_handle(m.mouse);
|
||||||
|
|
||||||
|
if ((HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "clickfinger_behavior") : g_pConfigManager->getInt("input:touchpad:clickfinger_behavior")) == 0) // toggle software buttons or clickfinger
|
||||||
|
libinput_device_config_click_set_method(LIBINPUTDEV, LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
|
||||||
|
else
|
||||||
|
libinput_device_config_click_set_method(LIBINPUTDEV, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
|
||||||
|
|
||||||
|
if (libinput_device_config_middle_emulation_is_available(LIBINPUTDEV)) { // middleclick on r+l mouse button pressed
|
||||||
|
if ((HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "middle_button_emulation") : g_pConfigManager->getInt("input:touchpad:middle_button_emulation")) == 1)
|
||||||
|
libinput_device_config_middle_emulation_set_enabled(LIBINPUTDEV, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED);
|
||||||
|
else
|
||||||
|
libinput_device_config_middle_emulation_set_enabled(LIBINPUTDEV, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "drag_lock") : g_pConfigManager->getInt("input:touchpad:drag_lock")) == 0)
|
||||||
|
libinput_device_config_tap_set_drag_lock_enabled(LIBINPUTDEV, LIBINPUT_CONFIG_DRAG_LOCK_DISABLED);
|
||||||
|
else
|
||||||
|
libinput_device_config_tap_set_drag_lock_enabled(LIBINPUTDEV, LIBINPUT_CONFIG_DRAG_LOCK_ENABLED);
|
||||||
|
|
||||||
|
if (libinput_device_config_tap_get_finger_count(LIBINPUTDEV)) // this is for tapping (like on a laptop)
|
||||||
|
if ((HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "tap-to-click") : g_pConfigManager->getInt("input:touchpad:tap-to-click")) == 1)
|
||||||
|
libinput_device_config_tap_set_enabled(LIBINPUTDEV, LIBINPUT_CONFIG_TAP_ENABLED);
|
||||||
|
|
||||||
|
if (libinput_device_config_scroll_has_natural_scroll(LIBINPUTDEV)) {
|
||||||
|
double w = 0, h = 0;
|
||||||
|
|
||||||
|
if (libinput_device_has_capability(LIBINPUTDEV, LIBINPUT_DEVICE_CAP_POINTER) && libinput_device_get_size(LIBINPUTDEV, &w, &h) == 0) // pointer with size is a touchpad
|
||||||
|
libinput_device_config_scroll_set_natural_scroll_enabled(LIBINPUTDEV, (HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "natural_scroll") : g_pConfigManager->getInt("input:touchpad:natural_scroll")));
|
||||||
|
else
|
||||||
|
libinput_device_config_scroll_set_natural_scroll_enabled(LIBINPUTDEV, (HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "natural_scroll") : g_pConfigManager->getInt("input:natural_scroll")));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (libinput_device_config_dwt_is_available(LIBINPUTDEV)) {
|
||||||
|
const auto DWT = static_cast<enum libinput_config_dwt_state>((HASCONFIG ? g_pConfigManager->getDeviceInt(PMOUSE->name, "disable_while_typing") : g_pConfigManager->getInt("input:touchpad:disable_while_typing")) != 0);
|
||||||
|
libinput_device_config_dwt_set_enabled(LIBINPUTDEV, DWT);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto LIBINPUTSENS = std::clamp((HASCONFIG ? g_pConfigManager->getDeviceFloat(PMOUSE->name, "sensitivity") : g_pConfigManager->getFloat("input:sensitivity")), -1.f, 1.f);
|
||||||
|
|
||||||
|
libinput_device_config_accel_set_profile(LIBINPUTDEV, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE);
|
||||||
|
libinput_device_config_accel_set_speed(LIBINPUTDEV, LIBINPUTSENS);
|
||||||
|
|
||||||
|
Debug::log(LOG, "Applied config to mouse %s, sens %.2f", m.name.c_str(), LIBINPUTSENS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CInputManager::destroyKeyboard(SKeyboard* pKeyboard) {
|
void CInputManager::destroyKeyboard(SKeyboard* pKeyboard) {
|
||||||
pKeyboard->hyprListener_keyboardDestroy.removeCallback();
|
pKeyboard->hyprListener_keyboardDestroy.removeCallback();
|
||||||
pKeyboard->hyprListener_keyboardMod.removeCallback();
|
pKeyboard->hyprListener_keyboardMod.removeCallback();
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
void refocus();
|
void refocus();
|
||||||
|
|
||||||
void setKeyboardLayout();
|
void setKeyboardLayout();
|
||||||
|
void setMouseConfigs();
|
||||||
|
|
||||||
void updateDragIcon();
|
void updateDragIcon();
|
||||||
void updateCapabilities(wlr_input_device*);
|
void updateCapabilities(wlr_input_device*);
|
||||||
|
|
Loading…
Reference in a new issue