input: add per-device scroll-factor (#11241)

This commit is contained in:
Vaxry 2025-09-02 13:16:43 +02:00 committed by GitHub
parent 78e86d879f
commit 127aab8159
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 593 additions and 22 deletions

View file

@ -9,6 +9,7 @@
#include <src/layout/IHyprLayout.hpp>
#include <src/managers/LayoutManager.hpp>
#include <src/managers/input/InputManager.hpp>
#include <src/managers/PointerManager.hpp>
#include <src/managers/input/trackpad/TrackpadGestures.hpp>
#include <src/Compositor.hpp>
#undef private
@ -88,9 +89,38 @@ class CTestKeyboard : public IKeyboard {
}
private:
bool m_isVirtual;
bool m_isVirtual = false;
};
class CTestMouse : public IPointer {
public:
static SP<CTestMouse> create(bool isVirtual) {
auto maus = SP<CTestMouse>(new CTestMouse());
maus->m_self = maus;
maus->m_isVirtual = isVirtual;
maus->m_deviceName = "test-mouse";
maus->m_hlName = "test-mouse";
return maus;
}
virtual bool isVirtual() {
return m_isVirtual;
}
virtual SP<Aquamarine::IPointer> aq() {
return nullptr;
}
void destroy() {
m_events.destroy.emit();
}
private:
bool m_isVirtual = false;
};
SP<CTestMouse> g_mouse;
static SDispatchResult pressAlt(std::string in) {
g_pInputManager->m_lastMods = in == "1" ? HL_MODIFIER_ALT : 0;
@ -173,6 +203,23 @@ static SDispatchResult vkb(std::string in) {
return {};
}
static SDispatchResult scroll(std::string in) {
int by;
try {
by = std::stoi(in);
} catch (...) { return SDispatchResult{.success = false, .error = "invalid input"}; }
Debug::log(LOG, "tester: scrolling by {}", by);
g_mouse->m_pointerEvents.axis.emit(IPointer::SAxisEvent{
.delta = by,
.deltaDiscrete = 120,
.mouse = true,
});
return {};
}
APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
PHANDLE = handle;
@ -181,10 +228,16 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:vkb", ::vkb);
HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:alt", ::pressAlt);
HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:gesture", ::simulateGesture);
HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:scroll", ::scroll);
// init mouse
g_mouse = CTestMouse::create(false);
g_pInputManager->newMouse(g_mouse);
return {"hyprtestplugin", "hyprtestplugin", "Vaxry", "1.0"};
}
APICALL EXPORT void PLUGIN_EXIT() {
;
g_mouse->destroy();
g_mouse.reset();
}