mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-29 15:45:59 +01:00
Add switch device handling and binds
This commit is contained in:
parent
9bbae5b8e2
commit
0d702b556d
8 changed files with 84 additions and 8 deletions
|
@ -402,6 +402,24 @@ R"#( {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove trailing comma
|
||||||
|
if (result[result.size() - 1] == ',')
|
||||||
|
result.pop_back();
|
||||||
|
result += "\n],\n";
|
||||||
|
|
||||||
|
result += "\"switches\": [\n";
|
||||||
|
|
||||||
|
for (auto& d : g_pInputManager->m_lSwitches) {
|
||||||
|
result += getFormat(
|
||||||
|
R"#( {
|
||||||
|
"address": "0x%x",
|
||||||
|
"name": "%s"
|
||||||
|
},)#",
|
||||||
|
&d,
|
||||||
|
d.pWlrDevice ? d.pWlrDevice->name : ""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// remove trailing comma
|
// remove trailing comma
|
||||||
if (result[result.size() - 1] == ',')
|
if (result[result.size() - 1] == ',')
|
||||||
result.pop_back();
|
result.pop_back();
|
||||||
|
@ -442,6 +460,12 @@ R"#( {
|
||||||
for (auto& d : g_pInputManager->m_lTouchDevices) {
|
for (auto& d : g_pInputManager->m_lTouchDevices) {
|
||||||
result += getFormat("\tTouch Device at %x:\n\t\t%s\n", &d, d.pWlrDevice ? d.pWlrDevice->name : "");
|
result += getFormat("\tTouch Device at %x:\n\t\t%s\n", &d, d.pWlrDevice ? d.pWlrDevice->name : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result += "\n\nSwitches:\n";
|
||||||
|
|
||||||
|
for (auto& d : g_pInputManager->m_lSwitches) {
|
||||||
|
result += getFormat("\tSwitch Device at %x:\n\t\t%s\n", &d, d.pWlrDevice ? d.pWlrDevice->name : "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -82,6 +82,10 @@ void Events::listener_newInput(wl_listener* listener, void* data) {
|
||||||
Debug::log(LOG, "Attached a tablet pad with name %s", DEVICE->name);
|
Debug::log(LOG, "Attached a tablet pad with name %s", DEVICE->name);
|
||||||
g_pInputManager->newTabletPad(DEVICE);
|
g_pInputManager->newTabletPad(DEVICE);
|
||||||
break;
|
break;
|
||||||
|
case WLR_INPUT_DEVICE_SWITCH:
|
||||||
|
Debug::log(LOG, "Attached a switch device with name %s", DEVICE->name);
|
||||||
|
g_pInputManager->newSwitch(DEVICE);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Debug::log(WARN, "Unrecognized input device plugged in: %s", DEVICE->name);
|
Debug::log(WARN, "Unrecognized input device plugged in: %s", DEVICE->name);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -332,3 +332,14 @@ struct STouchDevice {
|
||||||
return pWlrDevice == other.pWlrDevice;
|
return pWlrDevice == other.pWlrDevice;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SSwitchDevice {
|
||||||
|
wlr_input_device* pWlrDevice = nullptr;
|
||||||
|
|
||||||
|
DYNLISTENER(destroy);
|
||||||
|
DYNLISTENER(toggle);
|
||||||
|
|
||||||
|
bool operator==(const SSwitchDevice& other) {
|
||||||
|
return pWlrDevice == other.pWlrDevice;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -101,6 +101,7 @@ extern "C" {
|
||||||
#include <wlr/types/wlr_input_method_v2.h>
|
#include <wlr/types/wlr_input_method_v2.h>
|
||||||
#include <wlr/types/wlr_text_input_v3.h>
|
#include <wlr/types/wlr_text_input_v3.h>
|
||||||
#include <wlr/types/wlr_touch.h>
|
#include <wlr/types/wlr_touch.h>
|
||||||
|
#include <wlr/types/wlr_switch.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef delete
|
#undef delete
|
||||||
|
|
|
@ -202,9 +202,9 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard
|
||||||
m_dPressedKeycodes.push_back(KEYCODE);
|
m_dPressedKeycodes.push_back(KEYCODE);
|
||||||
m_dPressedKeysyms.push_back(keysym);
|
m_dPressedKeysyms.push_back(keysym);
|
||||||
|
|
||||||
found = g_pKeybindManager->handleKeybinds(MODS, "", keysym, 0, true, e->time_msec) || found;
|
found = handleKeybinds(MODS, "", keysym, 0, true, e->time_msec) || found;
|
||||||
|
|
||||||
found = g_pKeybindManager->handleKeybinds(MODS, "", 0, KEYCODE, true, e->time_msec) || found;
|
found = handleKeybinds(MODS, "", 0, KEYCODE, true, e->time_msec) || found;
|
||||||
|
|
||||||
if (found)
|
if (found)
|
||||||
shadowKeybinds(keysym, KEYCODE);
|
shadowKeybinds(keysym, KEYCODE);
|
||||||
|
@ -219,9 +219,9 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard
|
||||||
m_dPressedKeycodes.erase(std::remove(m_dPressedKeycodes.begin(), m_dPressedKeycodes.end(), KEYCODE), m_dPressedKeycodes.end());
|
m_dPressedKeycodes.erase(std::remove(m_dPressedKeycodes.begin(), m_dPressedKeycodes.end(), KEYCODE), m_dPressedKeycodes.end());
|
||||||
m_dPressedKeysyms.erase(std::remove(m_dPressedKeysyms.begin(), m_dPressedKeysyms.end(), keysym), m_dPressedKeysyms.end());
|
m_dPressedKeysyms.erase(std::remove(m_dPressedKeysyms.begin(), m_dPressedKeysyms.end(), keysym), m_dPressedKeysyms.end());
|
||||||
|
|
||||||
found = g_pKeybindManager->handleKeybinds(MODS, "", keysym, 0, false, e->time_msec) || found;
|
found = handleKeybinds(MODS, "", keysym, 0, false, e->time_msec) || found;
|
||||||
|
|
||||||
found = g_pKeybindManager->handleKeybinds(MODS, "", 0, KEYCODE, false, e->time_msec) || found;
|
found = handleKeybinds(MODS, "", 0, KEYCODE, false, e->time_msec) || found;
|
||||||
|
|
||||||
shadowKeybinds();
|
shadowKeybinds();
|
||||||
}
|
}
|
||||||
|
@ -244,9 +244,9 @@ bool CKeybindManager::onAxisEvent(wlr_pointer_axis_event* e) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
if (e->source == WLR_AXIS_SOURCE_WHEEL && e->orientation == WLR_AXIS_ORIENTATION_VERTICAL) {
|
if (e->source == WLR_AXIS_SOURCE_WHEEL && e->orientation == WLR_AXIS_ORIENTATION_VERTICAL) {
|
||||||
if (e->delta < 0) {
|
if (e->delta < 0) {
|
||||||
found = g_pKeybindManager->handleKeybinds(MODS, "mouse_down", 0, 0, true, 0);
|
found = handleKeybinds(MODS, "mouse_down", 0, 0, true, 0);
|
||||||
} else {
|
} else {
|
||||||
found = g_pKeybindManager->handleKeybinds(MODS, "mouse_up", 0, 0, true, 0);
|
found = handleKeybinds(MODS, "mouse_up", 0, 0, true, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found)
|
if (found)
|
||||||
|
@ -268,12 +268,12 @@ bool CKeybindManager::onMouseEvent(wlr_pointer_button_event* e) {
|
||||||
bool mouseBindWasActive = ensureMouseBindState();
|
bool mouseBindWasActive = ensureMouseBindState();
|
||||||
|
|
||||||
if (e->state == WLR_BUTTON_PRESSED) {
|
if (e->state == WLR_BUTTON_PRESSED) {
|
||||||
found = g_pKeybindManager->handleKeybinds(MODS, "mouse:" + std::to_string(e->button), 0, 0, true, 0);
|
found = handleKeybinds(MODS, "mouse:" + std::to_string(e->button), 0, 0, true, 0);
|
||||||
|
|
||||||
if (found)
|
if (found)
|
||||||
shadowKeybinds();
|
shadowKeybinds();
|
||||||
} else {
|
} else {
|
||||||
found = g_pKeybindManager->handleKeybinds(MODS, "mouse:" + std::to_string(e->button), 0, 0, false, 0);
|
found = handleKeybinds(MODS, "mouse:" + std::to_string(e->button), 0, 0, false, 0);
|
||||||
|
|
||||||
shadowKeybinds();
|
shadowKeybinds();
|
||||||
}
|
}
|
||||||
|
@ -281,6 +281,10 @@ bool CKeybindManager::onMouseEvent(wlr_pointer_button_event* e) {
|
||||||
return !found && !mouseBindWasActive;
|
return !found && !mouseBindWasActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CKeybindManager::onSwitchEvent(const std::string& switchName) {
|
||||||
|
handleKeybinds(0, "switch:" + switchName, 0, 0, true, 0);
|
||||||
|
}
|
||||||
|
|
||||||
int repeatKeyHandler(void* data) {
|
int repeatKeyHandler(void* data) {
|
||||||
SKeybind** ppActiveKeybind = (SKeybind**)data;
|
SKeybind** ppActiveKeybind = (SKeybind**)data;
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
bool onKeyEvent(wlr_keyboard_key_event*, SKeyboard*);
|
bool onKeyEvent(wlr_keyboard_key_event*, SKeyboard*);
|
||||||
bool onAxisEvent(wlr_pointer_axis_event*);
|
bool onAxisEvent(wlr_pointer_axis_event*);
|
||||||
bool onMouseEvent(wlr_pointer_button_event*);
|
bool onMouseEvent(wlr_pointer_button_event*);
|
||||||
|
void onSwitchEvent(const std::string&);
|
||||||
|
|
||||||
void addKeybind(SKeybind);
|
void addKeybind(SKeybind);
|
||||||
void removeKeybind(uint32_t, const std::string&);
|
void removeKeybind(uint32_t, const std::string&);
|
||||||
|
|
|
@ -1006,3 +1006,29 @@ void CInputManager::destroyTouchDevice(STouchDevice* pDevice) {
|
||||||
|
|
||||||
m_lTouchDevices.remove(*pDevice);
|
m_lTouchDevices.remove(*pDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CInputManager::newSwitch(wlr_input_device* pDevice) {
|
||||||
|
const auto PNEWDEV = &m_lSwitches.emplace_back();
|
||||||
|
PNEWDEV->pWlrDevice = pDevice;
|
||||||
|
|
||||||
|
Debug::log(LOG, "New switch with name \"%s\" added", pDevice->name);
|
||||||
|
|
||||||
|
PNEWDEV->hyprListener_destroy.initCallback(&pDevice->events.destroy, [&](void* owner, void* data) {
|
||||||
|
destroySwitch((SSwitchDevice*)owner);
|
||||||
|
}, PNEWDEV, "SwitchDevice");
|
||||||
|
|
||||||
|
const auto PSWITCH = wlr_switch_from_input_device(pDevice);
|
||||||
|
|
||||||
|
PNEWDEV->hyprListener_toggle.initCallback(&PSWITCH->events.toggle, [&](void* owner, void* data) {
|
||||||
|
const auto PDEVICE = (SSwitchDevice*)owner;
|
||||||
|
const auto NAME = std::string(PDEVICE->pWlrDevice->name);
|
||||||
|
|
||||||
|
Debug::log(LOG, "Switch %s fired, triggering binds.", NAME.c_str());
|
||||||
|
|
||||||
|
g_pKeybindManager->onSwitchEvent(NAME);
|
||||||
|
}, PNEWDEV, "SwitchDevice");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInputManager::destroySwitch(SSwitchDevice* pDevice) {
|
||||||
|
m_lSwitches.remove(*pDevice);
|
||||||
|
}
|
|
@ -37,9 +37,11 @@ public:
|
||||||
void newVirtualKeyboard(wlr_input_device*);
|
void newVirtualKeyboard(wlr_input_device*);
|
||||||
void newMouse(wlr_input_device*, bool virt = false);
|
void newMouse(wlr_input_device*, bool virt = false);
|
||||||
void newTouchDevice(wlr_input_device*);
|
void newTouchDevice(wlr_input_device*);
|
||||||
|
void newSwitch(wlr_input_device*);
|
||||||
void destroyTouchDevice(STouchDevice*);
|
void destroyTouchDevice(STouchDevice*);
|
||||||
void destroyKeyboard(SKeyboard*);
|
void destroyKeyboard(SKeyboard*);
|
||||||
void destroyMouse(wlr_input_device*);
|
void destroyMouse(wlr_input_device*);
|
||||||
|
void destroySwitch(SSwitchDevice*);
|
||||||
|
|
||||||
void constrainMouse(SMouse*, wlr_pointer_constraint_v1*);
|
void constrainMouse(SMouse*, wlr_pointer_constraint_v1*);
|
||||||
void recheckConstraint(SMouse*);
|
void recheckConstraint(SMouse*);
|
||||||
|
@ -89,6 +91,9 @@ public:
|
||||||
// Touch devices
|
// Touch devices
|
||||||
std::list<STouchDevice> m_lTouchDevices;
|
std::list<STouchDevice> m_lTouchDevices;
|
||||||
|
|
||||||
|
// Switches
|
||||||
|
std::list<SSwitchDevice> m_lSwitches;
|
||||||
|
|
||||||
void newTabletTool(wlr_input_device*);
|
void newTabletTool(wlr_input_device*);
|
||||||
void newTabletPad(wlr_input_device*);
|
void newTabletPad(wlr_input_device*);
|
||||||
void focusTablet(STablet*, wlr_tablet_tool*, bool motion = false);
|
void focusTablet(STablet*, wlr_tablet_tool*, bool motion = false);
|
||||||
|
|
Loading…
Reference in a new issue