Skip to content

Commit

Permalink
Override window scroll factor and add window rule for touchpad
Browse files Browse the repository at this point in the history
  • Loading branch information
myQwil committed Dec 6, 2024
1 parent 326f574 commit 7cb381a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2304,8 +2304,8 @@ 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", "scrollfactor", "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, ' ');
Expand Down
3 changes: 2 additions & 1 deletion src/config/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ class CConfigManager {
{"rounding", [](PHLWINDOW pWindow) { return &pWindow->m_sWindowData.rounding; }}, {"bordersize", [](PHLWINDOW pWindow) { return &pWindow->m_sWindowData.borderSize; }}};

std::unordered_map<std::string, std::function<CWindowOverridableVar<float>*(PHLWINDOW)>> mfWindowProperties = {
{"scrollfactor", [](PHLWINDOW pWindow) { return &pWindow->m_sWindowData.scrollFactor; }}};
{"scrollmouse", [](PHLWINDOW pWindow) { return &pWindow->m_sWindowData.scrollMouse; }},
{"scrolltouchpad", [](PHLWINDOW pWindow) { return &pWindow->m_sWindowData.scrollTouchpad; }}};

bool m_bWantsMonitorReload = false;
bool m_bForceReload = false;
Expand Down
10 changes: 8 additions & 2 deletions src/desktop/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,8 +1182,14 @@ int CWindow::getRealBorderSize() {
return m_sWindowData.borderSize.valueOr(*PBORDERSIZE);
}

float CWindow::getScrollFactor() {
return m_sWindowData.scrollFactor.valueOr(1.f);
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.scrollMouse.valueOr(*PTOUCHPADSCROLLFACTOR);
}

bool CWindow::canBeTorn() {
Expand Down
6 changes: 4 additions & 2 deletions src/desktop/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ struct SWindowData {
CWindowOverridableVar<int> rounding;
CWindowOverridableVar<int> borderSize;

CWindowOverridableVar<float> scrollFactor;
CWindowOverridableVar<float> scrollMouse;
CWindowOverridableVar<float> scrollTouchpad;

CWindowOverridableVar<std::string> animationStyle;
CWindowOverridableVar<Vector2D> maxSize;
Expand Down Expand Up @@ -446,7 +447,8 @@ class CWindow {
bool isFullscreen();
bool isEffectiveInternalFSMode(const eFullscreenMode);
int getRealBorderSize();
float getScrollFactor();
float getScrollMouse();
float getScrollTouchpad();
void updateWindowData();
void updateWindowData(const struct SWorkspaceRule&);
void onBorderAngleAnimEnd(void* ptr);
Expand Down
5 changes: 3 additions & 2 deletions src/managers/input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -776,7 +777,7 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e) {
const auto PWINDOW = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING);

if (PWINDOW) {
factor *= PWINDOW->getScrollFactor();
factor = (ISTOUCHPADSCROLL) ? PWINDOW->getScrollTouchpad() : PWINDOW->getScrollMouse();
if (PWINDOW->checkInputOnDecos(INPUT_TYPE_AXIS, MOUSECOORDS, e))
return;

Expand Down

0 comments on commit 7cb381a

Please sign in to comment.