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.
This commit is contained in:
Vaxry 2024-05-03 22:34:10 +01:00
parent 1d2acbe193
commit 1237732b97
39 changed files with 1450 additions and 573 deletions

View file

@ -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);
}

View file

@ -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;
};

View file

@ -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));
}

View file

@ -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;
};