input: add per-device scroll-factor (#11241)
This commit is contained in:
parent
78e86d879f
commit
127aab8159
16 changed files with 593 additions and 22 deletions
|
|
@ -810,6 +810,7 @@ CConfigManager::CConfigManager() {
|
|||
m_config->addSpecialConfigValue("device", "scroll_button", Hyprlang::INT{0});
|
||||
m_config->addSpecialConfigValue("device", "scroll_button_lock", Hyprlang::INT{0});
|
||||
m_config->addSpecialConfigValue("device", "scroll_points", {STRVAL_EMPTY});
|
||||
m_config->addSpecialConfigValue("device", "scroll_factor", Hyprlang::FLOAT{-1});
|
||||
m_config->addSpecialConfigValue("device", "transform", Hyprlang::INT{-1});
|
||||
m_config->addSpecialConfigValue("device", "output", {STRVAL_EMPTY});
|
||||
m_config->addSpecialConfigValue("device", "enabled", Hyprlang::INT{1}); // only for mice, touchpads, and touchdevices
|
||||
|
|
@ -1335,13 +1336,18 @@ Hyprlang::CConfigValue* CConfigManager::getConfigValueSafeDevice(const std::stri
|
|||
|
||||
const auto VAL = m_config->getSpecialConfigValuePtr("device", val.c_str(), dev.c_str());
|
||||
|
||||
if ((!VAL || !VAL->m_bSetByUser) && !fallback.empty()) {
|
||||
if ((!VAL || !VAL->m_bSetByUser) && !fallback.empty())
|
||||
return m_config->getConfigValuePtr(fallback.c_str());
|
||||
}
|
||||
|
||||
return VAL;
|
||||
}
|
||||
|
||||
bool CConfigManager::deviceConfigExplicitlySet(const std::string& dev, const std::string& val) {
|
||||
const auto VAL = m_config->getSpecialConfigValuePtr("device", val.c_str(), dev.c_str());
|
||||
|
||||
return VAL && VAL->m_bSetByUser;
|
||||
}
|
||||
|
||||
int CConfigManager::getDeviceInt(const std::string& dev, const std::string& v, const std::string& fallback) {
|
||||
return std::any_cast<Hyprlang::INT>(getConfigValueSafeDevice(dev, v, fallback)->getValue());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -210,6 +210,7 @@ class CConfigManager {
|
|||
float getDeviceFloat(const std::string&, const std::string&, const std::string& fallback = "");
|
||||
Vector2D getDeviceVec(const std::string&, const std::string&, const std::string& fallback = "");
|
||||
std::string getDeviceString(const std::string&, const std::string&, const std::string& fallback = "");
|
||||
bool deviceConfigExplicitlySet(const std::string&, const std::string&);
|
||||
bool deviceConfigExists(const std::string&);
|
||||
Hyprlang::CConfigValue* getConfigValueSafeDevice(const std::string& dev, const std::string& val, const std::string& fallback);
|
||||
bool shouldBlurLS(const std::string&);
|
||||
|
|
|
|||
|
|
@ -722,10 +722,11 @@ static std::string devicesRequest(eHyprCtlOutputFormat format, std::string reque
|
|||
R"#( {{
|
||||
"address": "0x{:x}",
|
||||
"name": "{}",
|
||||
"defaultSpeed": {:.5f}
|
||||
"defaultSpeed": {:.5f},
|
||||
"scrollFactor": {:.2f}
|
||||
}},)#",
|
||||
rc<uintptr_t>(m.get()), escapeJSONStrings(m->m_hlName),
|
||||
m->aq() && m->aq()->getLibinputHandle() ? libinput_device_config_accel_get_default_speed(m->aq()->getLibinputHandle()) : 0.f);
|
||||
m->aq() && m->aq()->getLibinputHandle() ? libinput_device_config_accel_get_default_speed(m->aq()->getLibinputHandle()) : 0.f, m->m_scrollFactor.value_or(-1));
|
||||
}
|
||||
|
||||
trimTrailingComma(result);
|
||||
|
|
@ -826,8 +827,9 @@ static std::string devicesRequest(eHyprCtlOutputFormat format, std::string reque
|
|||
result += "mice:\n";
|
||||
|
||||
for (auto const& m : g_pInputManager->m_pointers) {
|
||||
result += std::format("\tMouse at {:x}:\n\t\t{}\n\t\t\tdefault speed: {:.5f}\n", rc<uintptr_t>(m.get()), m->m_hlName,
|
||||
(m->aq() && m->aq()->getLibinputHandle() ? libinput_device_config_accel_get_default_speed(m->aq()->getLibinputHandle()) : 0.f));
|
||||
result += std::format("\tMouse at {:x}:\n\t\t{}\n\t\t\tdefault speed: {:.5f}\n\t\t\tscroll factor: {:.2f}\n", rc<uintptr_t>(m.get()), m->m_hlName,
|
||||
(m->aq() && m->aq()->getLibinputHandle() ? libinput_device_config_accel_get_default_speed(m->aq()->getLibinputHandle()) : 0.f),
|
||||
m->m_scrollFactor.value_or(-1));
|
||||
}
|
||||
|
||||
result += "\n\nKeyboards:\n";
|
||||
|
|
|
|||
|
|
@ -1249,6 +1249,14 @@ float CWindow::getScrollTouchpad() {
|
|||
return m_windowData.scrollTouchpad.valueOr(*PTOUCHPADSCROLLFACTOR);
|
||||
}
|
||||
|
||||
bool CWindow::isScrollMouseOverridden() {
|
||||
return m_windowData.scrollMouse.hasValue();
|
||||
}
|
||||
|
||||
bool CWindow::isScrollTouchpadOverridden() {
|
||||
return m_windowData.scrollTouchpad.hasValue();
|
||||
}
|
||||
|
||||
bool CWindow::canBeTorn() {
|
||||
static auto PTEARING = CConfigValue<Hyprlang::INT>("general:allow_tearing");
|
||||
return m_windowData.tearing.valueOr(m_tearingHint) && *PTEARING;
|
||||
|
|
|
|||
|
|
@ -363,6 +363,8 @@ class CWindow {
|
|||
int getRealBorderSize();
|
||||
float getScrollMouse();
|
||||
float getScrollTouchpad();
|
||||
bool isScrollMouseOverridden();
|
||||
bool isScrollTouchpadOverridden();
|
||||
void updateWindowData();
|
||||
void updateWindowData(const struct SWorkspaceRule&);
|
||||
void onBorderAngleAnimEnd(WP<Hyprutils::Animation::CBaseAnimatedVariable> pav);
|
||||
|
|
|
|||
|
|
@ -108,11 +108,12 @@ class IPointer : public IHID {
|
|||
CSignalT<SHoldEndEvent> holdEnd;
|
||||
} m_pointerEvents;
|
||||
|
||||
bool m_connected = false; // means connected to the cursor
|
||||
std::string m_boundOutput = "";
|
||||
bool m_flipX = false; // decide to invert horizontal movement
|
||||
bool m_flipY = false; // decide to invert vertical movement
|
||||
bool m_isTouchpad = false;
|
||||
bool m_connected = false; // means connected to the cursor
|
||||
std::string m_boundOutput = "";
|
||||
bool m_flipX = false; // decide to invert horizontal movement
|
||||
bool m_flipY = false; // decide to invert vertical movement
|
||||
bool m_isTouchpad = false;
|
||||
std::optional<float> m_scrollFactor = {};
|
||||
|
||||
WP<IPointer> m_self;
|
||||
WP<IPointer> m_self;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -919,8 +919,8 @@ void CPointerManager::attachPointer(SP<IPointer> pointer) {
|
|||
PROTO::idle->onActivity();
|
||||
});
|
||||
|
||||
listener->axis = pointer->m_pointerEvents.axis.listen([](const IPointer::SAxisEvent& event) {
|
||||
g_pInputManager->onMouseWheel(event);
|
||||
listener->axis = pointer->m_pointerEvents.axis.listen([weak = WP<IPointer>(pointer)](const IPointer::SAxisEvent& event) {
|
||||
g_pInputManager->onMouseWheel(event, weak.lock());
|
||||
PROTO::idle->onActivity();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -835,7 +835,7 @@ void CInputManager::processMouseDownKill(const IPointer::SButtonEvent& e) {
|
|||
m_clickBehavior = CLICKMODE_DEFAULT;
|
||||
}
|
||||
|
||||
void CInputManager::onMouseWheel(IPointer::SAxisEvent e) {
|
||||
void CInputManager::onMouseWheel(IPointer::SAxisEvent e, SP<IPointer> pointer) {
|
||||
static auto POFFWINDOWAXIS = CConfigValue<Hyprlang::INT>("input:off_window_axis_events");
|
||||
static auto PINPUTSCROLLFACTOR = CConfigValue<Hyprlang::FLOAT>("input:scroll_factor");
|
||||
static auto PTOUCHPADSCROLLFACTOR = CConfigValue<Hyprlang::FLOAT>("input:touchpad:scroll_factor");
|
||||
|
|
@ -845,7 +845,10 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e) {
|
|||
const bool ISTOUCHPADSCROLL = *PTOUCHPADSCROLLFACTOR <= 0.f || e.source == WL_POINTER_AXIS_SOURCE_FINGER;
|
||||
auto factor = ISTOUCHPADSCROLL ? *PTOUCHPADSCROLLFACTOR : *PINPUTSCROLLFACTOR;
|
||||
|
||||
const auto EMAP = std::unordered_map<std::string, std::any>{{"event", e}};
|
||||
if (pointer && pointer->m_scrollFactor.has_value())
|
||||
factor = *pointer->m_scrollFactor;
|
||||
|
||||
const auto EMAP = std::unordered_map<std::string, std::any>{{"event", e}};
|
||||
EMIT_HOOK_EVENT_CANCELLABLE("mouseAxis", EMAP);
|
||||
|
||||
if (e.mouse)
|
||||
|
|
@ -888,7 +891,11 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e) {
|
|||
if (*PFOLLOWMOUSE == 1 && PCURRWINDOW && PWINDOW != PCURRWINDOW)
|
||||
simulateMouseMovement();
|
||||
}
|
||||
factor = ISTOUCHPADSCROLL ? PWINDOW->getScrollTouchpad() : PWINDOW->getScrollMouse();
|
||||
|
||||
if (!ISTOUCHPADSCROLL && PWINDOW->isScrollMouseOverridden())
|
||||
factor = PWINDOW->getScrollMouse();
|
||||
else if (ISTOUCHPADSCROLL && PWINDOW->isScrollTouchpadOverridden())
|
||||
factor = PWINDOW->getScrollTouchpad();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1117,6 +1124,14 @@ void CInputManager::newVirtualMouse(SP<CVirtualPointerV1Resource> mouse) {
|
|||
Debug::log(LOG, "New virtual mouse created");
|
||||
}
|
||||
|
||||
void CInputManager::newMouse(SP<IPointer> mouse) {
|
||||
m_pointers.emplace_back(mouse);
|
||||
|
||||
setupMouse(mouse);
|
||||
|
||||
Debug::log(LOG, "New mouse created, pointer Hypr: {:x}", rc<uintptr_t>(mouse.get()));
|
||||
}
|
||||
|
||||
void CInputManager::newMouse(SP<Aquamarine::IPointer> mouse) {
|
||||
const auto PMOUSE = m_pointers.emplace_back(CMouse::create(mouse));
|
||||
|
||||
|
|
@ -1172,6 +1187,11 @@ void CInputManager::setPointerConfigs() {
|
|||
}
|
||||
}
|
||||
|
||||
if (g_pConfigManager->deviceConfigExplicitlySet(devname, "scroll_factor"))
|
||||
m->m_scrollFactor = std::clamp(g_pConfigManager->getDeviceFloat(devname, "scroll_factor", "input:scroll_factor"), 0.F, 100.F);
|
||||
else
|
||||
m->m_scrollFactor = std::nullopt;
|
||||
|
||||
if (m->aq() && m->aq()->getLibinputHandle()) {
|
||||
const auto LIBINPUTDEV = m->aq()->getLibinputHandle();
|
||||
|
||||
|
|
|
|||
|
|
@ -90,13 +90,14 @@ class CInputManager {
|
|||
void onMouseMoved(IPointer::SMotionEvent);
|
||||
void onMouseWarp(IPointer::SMotionAbsoluteEvent);
|
||||
void onMouseButton(IPointer::SButtonEvent);
|
||||
void onMouseWheel(IPointer::SAxisEvent);
|
||||
void onMouseWheel(IPointer::SAxisEvent, SP<IPointer> pointer = nullptr);
|
||||
void onKeyboardKey(const IKeyboard::SKeyEvent&, SP<IKeyboard>);
|
||||
void onKeyboardMod(SP<IKeyboard>);
|
||||
|
||||
void newKeyboard(SP<IKeyboard>);
|
||||
void newKeyboard(SP<Aquamarine::IKeyboard>);
|
||||
void newVirtualKeyboard(SP<CVirtualKeyboardV1Resource>);
|
||||
void newMouse(SP<IPointer>);
|
||||
void newMouse(SP<Aquamarine::IPointer>);
|
||||
void newVirtualMouse(SP<CVirtualPointerV1Resource>);
|
||||
void newTouchDevice(SP<Aquamarine::ITouch>);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue