summaryrefslogtreecommitdiff
path: root/hyprtester/plugin/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'hyprtester/plugin/src/main.cpp')
-rw-r--r--hyprtester/plugin/src/main.cpp57
1 files changed, 55 insertions, 2 deletions
diff --git a/hyprtester/plugin/src/main.cpp b/hyprtester/plugin/src/main.cpp
index 03035918..2b1d443a 100644
--- a/hyprtester/plugin/src/main.cpp
+++ b/hyprtester/plugin/src/main.cpp
@@ -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();
}