aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMike Will <[email protected]>2024-12-06 01:16:58 -0500
committerVaxry <[email protected]>2024-12-11 17:27:49 +0000
commitdf956a0f6fbcfd7397b2d7b86883c0936c7795ec (patch)
tree269946352158faa6a455c9e87337cb83c37998eb /src
parent33f271c29a0069a95755b1d3252aeebe0fd85287 (diff)
downloadHyprland-df956a0f6fbcfd7397b2d7b86883c0936c7795ec.tar.gz
Hyprland-df956a0f6fbcfd7397b2d7b86883c0936c7795ec.zip
windowrules: add rules for mouse and touchpad scroll factors (#8655)
Diffstat (limited to 'src')
-rw-r--r--src/config/ConfigManager.cpp7
-rw-r--r--src/config/ConfigManager.hpp4
-rw-r--r--src/desktop/Window.cpp17
-rw-r--r--src/desktop/Window.hpp5
-rw-r--r--src/managers/KeybindManager.cpp7
-rw-r--r--src/managers/input/InputManager.cpp4
6 files changed, 40 insertions, 4 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp
index ce474f94..b53ed4d9 100644
--- a/src/config/ConfigManager.cpp
+++ b/src/config/ConfigManager.cpp
@@ -2309,14 +2309,15 @@ bool windowRuleValid(const std::string& RULE) {
"float", "fullscreen", "maximize", "noinitialfocus", "pin", "stayfocused", "tile", "renderunfocused",
};
static const auto rulesPrefix = std::vector<std::string>{
- "animation", "bordercolor", "bordersize", "center", "fullscreenstate", "group", "idleinhibit", "maxsize", "minsize", "monitor",
- "move", "opacity", "plugin:", "pseudo", "rounding", "size", "suppressevent", "tag", "workspace", "xray",
+ "animation", "bordercolor", "bordersize", "center", "fullscreenstate", "group", "idleinhibit", "maxsize", "minsize", "monitor", "move",
+ "opacity", "plugin:", "pseudo", "rounding", "scrollmouse", "scrolltouchpad", "size", "suppressevent", "tag", "workspace", "xray",
};
const auto VALS = CVarList(RULE, 2, ' ');
return rules.contains(RULE) || std::any_of(rulesPrefix.begin(), rulesPrefix.end(), [&RULE](auto prefix) { return RULE.starts_with(prefix); }) ||
(g_pConfigManager->mbWindowProperties.find(VALS[0]) != g_pConfigManager->mbWindowProperties.end()) ||
- (g_pConfigManager->miWindowProperties.find(VALS[0]) != g_pConfigManager->miWindowProperties.end());
+ (g_pConfigManager->miWindowProperties.find(VALS[0]) != g_pConfigManager->miWindowProperties.end()) ||
+ (g_pConfigManager->mfWindowProperties.find(VALS[0]) != g_pConfigManager->mfWindowProperties.end());
}
bool layerRuleValid(const std::string& RULE) {
diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp
index 987884b5..2de217cb 100644
--- a/src/config/ConfigManager.hpp
+++ b/src/config/ConfigManager.hpp
@@ -263,6 +263,10 @@ class CConfigManager {
{"bordersize", [](const PHLWINDOW& pWindow) { return &pWindow->m_sWindowData.borderSize; }},
};
+ std::unordered_map<std::string, std::function<CWindowOverridableVar<float>*(PHLWINDOW)>> mfWindowProperties = {
+ {"scrollmouse", [](const PHLWINDOW& pWindow) { return &pWindow->m_sWindowData.scrollMouse; }},
+ {"scrolltouchpad", [](const PHLWINDOW& pWindow) { return &pWindow->m_sWindowData.scrollTouchpad; }}};
+
bool m_bWantsMonitorReload = false;
bool m_bForceReload = false;
bool m_bNoMonitorReload = false;
diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp
index e4651e61..e2106e4a 100644
--- a/src/desktop/Window.cpp
+++ b/src/desktop/Window.cpp
@@ -718,6 +718,10 @@ void CWindow::applyDynamicRule(const SWindowRule& r) {
try {
*(search->second(m_pSelf.lock())) = CWindowOverridableVar(std::stoi(VARS[1]), priority);
} catch (std::exception& e) { Debug::log(ERR, "Rule \"{}\" failed with: {}", r.szRule, e.what()); }
+ } else if (auto search = g_pConfigManager->mfWindowProperties.find(VARS[0]); search != g_pConfigManager->mfWindowProperties.end()) {
+ try {
+ *(search->second(m_pSelf.lock())) = CWindowOverridableVar(std::stof(VARS[1]), priority);
+ } catch (std::exception& e) { Debug::log(ERR, "Rule \"{}\" failed with: {}", r.szRule, e.what()); }
} else if (r.szRule.starts_with("idleinhibit")) {
auto IDLERULE = r.szRule.substr(r.szRule.find_first_of(' ') + 1);
@@ -1178,6 +1182,16 @@ int CWindow::getRealBorderSize() {
return m_sWindowData.borderSize.valueOr(*PBORDERSIZE);
}
+float CWindow::getScrollMouse() {
+ static auto PINPUTSCROLLFACTOR = CConfigValue<Hyprlang::FLOAT>("input:scroll_factor");
+ return m_sWindowData.scrollMouse.valueOr(*PINPUTSCROLLFACTOR);
+}
+
+float CWindow::getScrollTouchpad() {
+ static auto PTOUCHPADSCROLLFACTOR = CConfigValue<Hyprlang::FLOAT>("input:touchpad:scroll_factor");
+ return m_sWindowData.scrollTouchpad.valueOr(*PTOUCHPADSCROLLFACTOR);
+}
+
bool CWindow::canBeTorn() {
static auto PTEARING = CConfigValue<Hyprlang::INT>("general:allow_tearing");
return m_sWindowData.tearing.valueOr(m_bTearingHint) && *PTEARING;
@@ -1602,6 +1616,9 @@ void CWindow::unsetWindowData(eOverridePriority priority) {
for (auto const& element : g_pConfigManager->miWindowProperties) {
element.second(m_pSelf.lock())->unset(priority);
}
+ for (auto const& element : g_pConfigManager->mfWindowProperties) {
+ element.second(m_pSelf.lock())->unset(priority);
+ }
}
bool CWindow::isX11OverrideRedirect() {
diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp
index fc7ead24..590194e1 100644
--- a/src/desktop/Window.hpp
+++ b/src/desktop/Window.hpp
@@ -184,6 +184,9 @@ struct SWindowData {
CWindowOverridableVar<int> rounding;
CWindowOverridableVar<int> borderSize;
+ CWindowOverridableVar<float> scrollMouse;
+ CWindowOverridableVar<float> scrollTouchpad;
+
CWindowOverridableVar<std::string> animationStyle;
CWindowOverridableVar<Vector2D> maxSize;
CWindowOverridableVar<Vector2D> minSize;
@@ -442,6 +445,8 @@ class CWindow {
bool isFullscreen();
bool isEffectiveInternalFSMode(const eFullscreenMode);
int getRealBorderSize();
+ float getScrollMouse();
+ float getScrollTouchpad();
void updateWindowData();
void updateWindowData(const struct SWorkspaceRule&);
void onBorderAngleAnimEnd(void* ptr);
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index 2eb04d41..67c2c5d0 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -3014,6 +3014,13 @@ SDispatchResult CKeybindManager::setProp(std::string args) {
search->second(PWINDOW)->unset(PRIORITY_SET_PROP);
else if (const auto V = configStringToInt(VAL); V)
*(search->second(PWINDOW)) = CWindowOverridableVar((int)*V, PRIORITY_SET_PROP);
+ } else if (auto search = g_pConfigManager->mfWindowProperties.find(PROP); search != g_pConfigManager->mfWindowProperties.end()) {
+ if (VAL == "unset")
+ search->second(PWINDOW)->unset(PRIORITY_SET_PROP);
+ else {
+ const auto V = std::stof(VAL);
+ *(search->second(PWINDOW)) = CWindowOverridableVar(V, PRIORITY_SET_PROP);
+ }
} else
return {.success = false, .error = "Prop not found"};
} catch (std::exception& e) { return {.success = false, .error = std::format("Error parsing prop value: {}", std::string(e.what()))}; }
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp
index 6883717c..d1eb7c4c 100644
--- a/src/managers/input/InputManager.cpp
+++ b/src/managers/input/InputManager.cpp
@@ -761,7 +761,8 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e) {
static auto PEMULATEDISCRETE = CConfigValue<Hyprlang::INT>("input:emulate_discrete_scroll");
static auto PFOLLOWMOUSE = CConfigValue<Hyprlang::INT>("input:follow_mouse");
- auto factor = (*PTOUCHPADSCROLLFACTOR <= 0.f || e.source == WL_POINTER_AXIS_SOURCE_FINGER ? *PTOUCHPADSCROLLFACTOR : *PINPUTSCROLLFACTOR);
+ 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}};
EMIT_HOOK_EVENT_CANCELLABLE("mouseAxis", EMAP);
@@ -803,6 +804,7 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e) {
if (*PFOLLOWMOUSE == 1 && PCURRWINDOW && PWINDOW != PCURRWINDOW)
simulateMouseMovement();
}
+ factor = ISTOUCHPADSCROLL ? PWINDOW->getScrollTouchpad() : PWINDOW->getScrollMouse();
}
}