diff options
author | riChar <[email protected]> | 2023-01-08 23:35:24 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2023-01-08 16:35:24 +0100 |
commit | e5dcbf73d881178c7f9c6306d287ed610d6efea1 (patch) | |
tree | d157de8ddd40b44a6b42dddd7013a403731fb5ac | |
parent | 50e106f2e60785126331eaf2a9c43595a2a768d4 (diff) | |
download | Hyprland-e5dcbf73d881178c7f9c6306d287ed610d6efea1.tar.gz Hyprland-e5dcbf73d881178c7f9c6306d287ed610d6efea1.zip |
Add "on" and "off" for the bind of switch (#1342)
-rw-r--r-- | src/managers/KeybindManager.cpp | 8 | ||||
-rw-r--r-- | src/managers/KeybindManager.hpp | 2 | ||||
-rw-r--r-- | src/managers/input/InputManager.cpp | 13 |
3 files changed, 23 insertions, 0 deletions
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index f5b3e34b..cb2faf11 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -287,6 +287,14 @@ void CKeybindManager::onSwitchEvent(const std::string& switchName) { handleKeybinds(0, "switch:" + switchName, 0, 0, true, 0); } +void CKeybindManager::onSwitchOnEvent(const std::string& switchName) { + handleKeybinds(0, "switch:on:" + switchName, 0, 0, true, 0); +} + +void CKeybindManager::onSwitchOffEvent(const std::string& switchName) { + handleKeybinds(0, "switch:off:" + switchName, 0, 0, true, 0); +} + int repeatKeyHandler(void* data) { SKeybind** ppActiveKeybind = (SKeybind**)data; diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 3923d571..b29b48b0 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -40,6 +40,8 @@ class CKeybindManager { bool onAxisEvent(wlr_pointer_axis_event*); bool onMouseEvent(wlr_pointer_button_event*); void onSwitchEvent(const std::string&); + void onSwitchOnEvent(const std::string&); + void onSwitchOffEvent(const std::string&); void addKeybind(SKeybind); void removeKeybind(uint32_t, const std::string&); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index c67bcba3..a5ff20f7 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1,5 +1,6 @@ #include "InputManager.hpp" #include "../../Compositor.hpp" +#include "wlr/types/wlr_switch.h" void CInputManager::onMouseMoved(wlr_pointer_motion_event* e) { static auto* const PSENS = &g_pConfigManager->getConfigValuePtr("general:sensitivity")->floatValue; @@ -1215,6 +1216,18 @@ void CInputManager::newSwitch(wlr_input_device* pDevice) { Debug::log(LOG, "Switch %s fired, triggering binds.", NAME.c_str()); g_pKeybindManager->onSwitchEvent(NAME); + + const auto event_data = (wlr_switch_toggle_event*)data; + switch (event_data->switch_state) { + case WLR_SWITCH_STATE_ON: + Debug::log(LOG, "Switch %s turn on, triggering binds.", NAME.c_str()); + g_pKeybindManager->onSwitchOnEvent(NAME); + break; + case WLR_SWITCH_STATE_OFF: + Debug::log(LOG, "Switch %s turn off, triggering binds.", NAME.c_str()); + g_pKeybindManager->onSwitchOffEvent(NAME); + break; + } }, PNEWDEV, "SwitchDevice"); } |