summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-05-03 22:34:10 +0100
committerVaxry <vaxry@vaxry.net>2024-05-03 22:40:27 +0100
commit1237732b97fcf21a19aed16f2ef966118a3ca2aa (patch)
tree15a3a29377af7f0ce3dd428229587e476ce92db3 /src/helpers
parent1d2acbe19355c8640d54a4b6cba225c6f4370c85 (diff)
input: Introduce basic hyprland HID classes
Implements an intermediary HID class for mice, keyboards and touch devices, removing the old structs from WLClasses.hpp Yes, virtual ones are duplicated a bit, but will likely be de-duped once wlr_input_device is not used anymore.
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/Monitor.cpp9
-rw-r--r--src/helpers/WLClasses.cpp77
-rw-r--r--src/helpers/WLClasses.hpp100
-rw-r--r--src/helpers/signal/Listener.cpp8
-rw-r--r--src/helpers/signal/Listener.hpp16
-rw-r--r--src/helpers/signal/Signal.cpp8
-rw-r--r--src/helpers/signal/Signal.hpp7
7 files changed, 49 insertions, 176 deletions
diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp
index ffa8b7d8..1369244d 100644
--- a/src/helpers/Monitor.cpp
+++ b/src/helpers/Monitor.cpp
@@ -3,6 +3,7 @@
#include "../Compositor.hpp"
#include "../config/ConfigValue.hpp"
#include "../protocols/GammaControl.hpp"
+#include "../devices/ITouch.hpp"
int ratHandler(void* data) {
g_pHyprRenderer->renderMonitor((CMonitor*)data);
@@ -145,10 +146,10 @@ void CMonitor::onConnect(bool noRule) {
if (!noRule)
g_pHyprRenderer->applyMonitorRule(this, &monitorRule, true);
- for (const auto& PTOUCHDEV : g_pInputManager->m_lTouchDevices) {
- if (matchesStaticSelector(PTOUCHDEV.boundOutput)) {
- Debug::log(LOG, "Binding touch device {} to output {}", PTOUCHDEV.name, szName);
- wlr_cursor_map_input_to_output(g_pCompositor->m_sWLRCursor, PTOUCHDEV.pWlrDevice, output);
+ for (const auto& PTOUCHDEV : g_pInputManager->m_vTouches) {
+ if (matchesStaticSelector(PTOUCHDEV->boundOutput)) {
+ Debug::log(LOG, "Binding touch device {} to output {}", PTOUCHDEV->hlName, szName);
+ wlr_cursor_map_input_to_output(g_pCompositor->m_sWLRCursor, &PTOUCHDEV->wlr()->base, output);
}
}
diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp
index 4cdde4a0..61ab1133 100644
--- a/src/helpers/WLClasses.cpp
+++ b/src/helpers/WLClasses.cpp
@@ -1,78 +1 @@
#include "WLClasses.hpp"
-
-void SKeyboard::updateXKBTranslationState(xkb_keymap* const keymap) {
- xkb_state_unref(xkbTranslationState);
-
- if (keymap) {
- Debug::log(LOG, "Updating keyboard {:x}'s translation state from a provided keymap", (uintptr_t)this);
- xkbTranslationState = xkb_state_new(keymap);
- return;
- }
-
- const auto WLRKB = wlr_keyboard_from_input_device(keyboard);
- const auto KEYMAP = WLRKB->keymap;
- const auto STATE = WLRKB->xkb_state;
- const auto LAYOUTSNUM = xkb_keymap_num_layouts(KEYMAP);
-
- const auto PCONTEXT = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
-
- for (uint32_t i = 0; i < LAYOUTSNUM; ++i) {
- if (xkb_state_layout_index_is_active(STATE, i, XKB_STATE_LAYOUT_EFFECTIVE)) {
- Debug::log(LOG, "Updating keyboard {:x}'s translation state from an active index {}", (uintptr_t)this, i);
-
- CVarList keyboardLayouts(currentRules.layout, 0, ',');
- CVarList keyboardModels(currentRules.model, 0, ',');
- CVarList keyboardVariants(currentRules.variant, 0, ',');
-
- xkb_rule_names rules = {.rules = "", .model = "", .layout = "", .variant = "", .options = ""};
-
- std::string layout, model, variant;
- layout = keyboardLayouts[i % keyboardLayouts.size()];
- model = keyboardModels[i % keyboardModels.size()];
- variant = keyboardVariants[i % keyboardVariants.size()];
-
- rules.layout = layout.c_str();
- rules.model = model.c_str();
- rules.variant = variant.c_str();
-
- auto KEYMAP = xkb_keymap_new_from_names(PCONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
-
- if (!KEYMAP) {
- Debug::log(ERR, "updateXKBTranslationState: keymap failed 1, fallback without model/variant");
- rules.model = "";
- rules.variant = "";
- KEYMAP = xkb_keymap_new_from_names(PCONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
- }
-
- if (!KEYMAP) {
- Debug::log(ERR, "updateXKBTranslationState: keymap failed 2, fallback to us");
- rules.layout = "us";
- KEYMAP = xkb_keymap_new_from_names(PCONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
- }
-
- xkbTranslationState = xkb_state_new(KEYMAP);
-
- xkb_keymap_unref(KEYMAP);
- xkb_context_unref(PCONTEXT);
-
- return;
- }
- }
-
- Debug::log(LOG, "Updating keyboard {:x}'s translation state from an unknown index", (uintptr_t)this);
-
- xkb_rule_names rules = {
- .rules = currentRules.rules.c_str(),
- .model = currentRules.model.c_str(),
- .layout = currentRules.layout.c_str(),
- .variant = currentRules.variant.c_str(),
- .options = currentRules.options.c_str(),
- };
-
- const auto NEWKEYMAP = xkb_keymap_new_from_names(PCONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
-
- xkbTranslationState = xkb_state_new(NEWKEYMAP);
-
- xkb_keymap_unref(NEWKEYMAP);
- xkb_context_unref(PCONTEXT);
-}
diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp
index c625aae0..bed2b915 100644
--- a/src/helpers/WLClasses.hpp
+++ b/src/helpers/WLClasses.hpp
@@ -11,8 +11,8 @@
#include "Region.hpp"
class CMonitor;
-class CVirtualKeyboard;
-class CVirtualPointer;
+class IPointer;
+class IKeyboard;
struct SRenderData {
CMonitor* pMonitor;
@@ -58,86 +58,12 @@ struct SExtensionFindingData {
wlr_surface** found;
};
-struct SStringRuleNames {
- std::string layout = "";
- std::string model = "";
- std::string variant = "";
- std::string options = "";
- std::string rules = "";
-};
-
-struct SKeyboard {
- wlr_input_device* keyboard;
-
- DYNLISTENER(keyboardMod);
- DYNLISTENER(keyboardKey);
- DYNLISTENER(keyboardKeymap);
- DYNLISTENER(keyboardDestroy);
-
- bool isVirtual = false;
- bool active = false;
- bool enabled = true;
-
- WP<CVirtualKeyboard> virtKeyboard;
-
- xkb_layout_index_t activeLayout = 0;
- xkb_state* xkbTranslationState = nullptr;
-
- std::string name = "";
- std::string xkbFilePath = "";
-
- SStringRuleNames currentRules;
- int repeatRate = 0;
- int repeatDelay = 0;
- int numlockOn = -1;
- bool resolveBindsBySym = false;
-
- void updateXKBTranslationState(xkb_keymap* const keymap = nullptr);
-
- struct {
- CHyprSignalListener destroyVKeyboard;
- } listeners;
-
- // For the list lookup
- bool operator==(const SKeyboard& rhs) const {
- return keyboard == rhs.keyboard;
- }
-
- ~SKeyboard() {
- if (xkbTranslationState)
- xkb_state_unref(xkbTranslationState);
- }
-};
-
-struct SMouse {
- wlr_input_device* mouse = nullptr;
-
- std::string name = "";
-
- bool virt = false;
-
- bool connected = false; // means connected to the cursor
-
- WP<CVirtualPointer> virtualPointer;
-
- struct {
- CHyprSignalListener destroyMouse;
- } listeners;
-
- DYNLISTENER(destroyMouse);
-
- bool operator==(const SMouse& b) const {
- return mouse == b.mouse;
- }
-};
-
-class CMonitor;
-
struct SSeat {
- wlr_seat* seat = nullptr;
- wl_client* exclusiveClient = nullptr;
+ wlr_seat* seat = nullptr;
+ wl_client* exclusiveClient = nullptr;
- SMouse* mouse = nullptr;
+ WP<IPointer> mouse;
+ WP<IKeyboard> keyboard;
};
struct SDrag {
@@ -238,20 +164,6 @@ struct SSwipeGesture {
CMonitor* pMonitor = nullptr;
};
-struct STouchDevice {
- wlr_input_device* pWlrDevice = nullptr;
-
- std::string name = "";
-
- std::string boundOutput = "";
-
- DYNLISTENER(destroy);
-
- bool operator==(const STouchDevice& other) const {
- return pWlrDevice == other.pWlrDevice;
- }
-};
-
struct SSwitchDevice {
wlr_input_device* pWlrDevice = nullptr;
diff --git a/src/helpers/signal/Listener.cpp b/src/helpers/signal/Listener.cpp
index ae506343..4023477f 100644
--- a/src/helpers/signal/Listener.cpp
+++ b/src/helpers/signal/Listener.cpp
@@ -11,3 +11,11 @@ void CSignalListener::emit(std::any data) {
m_fHandler(data);
}
+
+CStaticSignalListener::CStaticSignalListener(std::function<void(void*, std::any)> handler, void* owner) : m_pOwner(owner), m_fHandler(handler) {
+ ;
+}
+
+void CStaticSignalListener::emit(std::any data) {
+ m_fHandler(m_pOwner, data);
+}
diff --git a/src/helpers/signal/Listener.hpp b/src/helpers/signal/Listener.hpp
index d2edb253..7ca96e87 100644
--- a/src/helpers/signal/Listener.hpp
+++ b/src/helpers/signal/Listener.hpp
@@ -22,3 +22,19 @@ class CSignalListener {
};
typedef std::shared_ptr<CSignalListener> CHyprSignalListener;
+
+class CStaticSignalListener {
+ public:
+ CStaticSignalListener(std::function<void(void*, std::any)> handler, void* owner);
+
+ CStaticSignalListener(CStaticSignalListener&&) = delete;
+ CStaticSignalListener(CStaticSignalListener&) = delete;
+ CStaticSignalListener(const CStaticSignalListener&) = delete;
+ CStaticSignalListener(const CStaticSignalListener&&) = delete;
+
+ void emit(std::any data);
+
+ private:
+ void* m_pOwner = nullptr;
+ std::function<void(void*, std::any)> m_fHandler;
+}; \ No newline at end of file
diff --git a/src/helpers/signal/Signal.cpp b/src/helpers/signal/Signal.cpp
index 204aaf00..d105eb78 100644
--- a/src/helpers/signal/Signal.cpp
+++ b/src/helpers/signal/Signal.cpp
@@ -11,6 +11,10 @@ void CSignal::emit(std::any data) {
dirty = true;
}
+ for (auto& l : m_vStaticListeners) {
+ l->emit(data);
+ }
+
if (dirty)
std::erase_if(m_vListeners, [](const auto& other) { return other.expired(); });
}
@@ -20,3 +24,7 @@ CHyprSignalListener CSignal::registerListener(std::function<void(std::any)> hand
m_vListeners.emplace_back(std::weak_ptr<CSignalListener>(listener));
return listener;
}
+
+void CSignal::registerStaticListener(std::function<void(void*, std::any)> handler, void* owner) {
+ m_vStaticListeners.emplace_back(std::make_unique<CStaticSignalListener>(handler, owner));
+} \ No newline at end of file
diff --git a/src/helpers/signal/Signal.hpp b/src/helpers/signal/Signal.hpp
index f12d0dc4..8938a70c 100644
--- a/src/helpers/signal/Signal.hpp
+++ b/src/helpers/signal/Signal.hpp
@@ -14,6 +14,11 @@ class CSignal {
//
[[nodiscard("Listener is unregistered when the ptr is lost")]] CHyprSignalListener registerListener(std::function<void(std::any)> handler);
+ // this is for static listeners. They die with this signal.
+ // TODO: can we somehow rid of the void* data and make it a custom this?
+ void registerStaticListener(std::function<void(void*, std::any)> handler, void* owner);
+
private:
- std::vector<std::weak_ptr<CSignalListener>> m_vListeners;
+ std::vector<std::weak_ptr<CSignalListener>> m_vListeners;
+ std::vector<std::unique_ptr<CStaticSignalListener>> m_vStaticListeners;
};