mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-25 07:49:49 +01:00
switches
This commit is contained in:
parent
9f761a9590
commit
cb3a3a4998
6 changed files with 39 additions and 42 deletions
|
@ -308,6 +308,14 @@ void CCompositor::initAllSignals() {
|
||||||
g_pInputManager->updateCapabilities();
|
g_pInputManager->updateCapabilities();
|
||||||
},
|
},
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
|
m_pAqBackend->events.newSwitch.registerStaticListener(
|
||||||
|
[](void* data, std::any d) {
|
||||||
|
auto dev = std::any_cast<SP<Aquamarine::ISwitch>>(d);
|
||||||
|
Debug::log(LOG, "New aquamarine switch with name {}", dev->getName());
|
||||||
|
g_pInputManager->newSwitch(dev);
|
||||||
|
},
|
||||||
|
nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCompositor::removeAllSignals() {
|
void CCompositor::removeAllSignals() {
|
||||||
|
|
|
@ -654,7 +654,7 @@ std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) {
|
||||||
"address": "0x{:x}",
|
"address": "0x{:x}",
|
||||||
"name": "{}"
|
"name": "{}"
|
||||||
}},)#",
|
}},)#",
|
||||||
(uintptr_t)&d, escapeJSONStrings(d.pWlrDevice ? d.pWlrDevice->name : ""));
|
(uintptr_t)&d, escapeJSONStrings(d.pDevice ? d.pDevice->getName() : ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
trimTrailingComma(result);
|
trimTrailingComma(result);
|
||||||
|
@ -702,7 +702,7 @@ std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) {
|
||||||
result += "\n\nSwitches:\n";
|
result += "\n\nSwitches:\n";
|
||||||
|
|
||||||
for (auto& d : g_pInputManager->m_lSwitches) {
|
for (auto& d : g_pInputManager->m_lSwitches) {
|
||||||
result += std::format("\tSwitch Device at {:x}:\n\t\t{}\n", (uintptr_t)&d, d.pWlrDevice ? d.pWlrDevice->name : "");
|
result += std::format("\tSwitch Device at {:x}:\n\t\t{}\n", (uintptr_t)&d, d.pDevice ? d.pDevice->getName() : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ void Events::listener_newInput(wl_listener* listener, void* data) {
|
||||||
break;
|
break;
|
||||||
case WLR_INPUT_DEVICE_SWITCH:
|
case WLR_INPUT_DEVICE_SWITCH:
|
||||||
Debug::log(LOG, "Attached a switch device with name {}", DEVICE->name);
|
Debug::log(LOG, "Attached a switch device with name {}", DEVICE->name);
|
||||||
g_pInputManager->newSwitch(DEVICE);
|
// g_pInputManager->newSwitch(DEVICE);
|
||||||
break;
|
break;
|
||||||
default: Debug::log(WARN, "Unrecognized input device plugged in: {}", DEVICE->name); break;
|
default: Debug::log(WARN, "Unrecognized input device plugged in: {}", DEVICE->name); break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ class IPointer;
|
||||||
class IKeyboard;
|
class IKeyboard;
|
||||||
class CWLSurfaceResource;
|
class CWLSurfaceResource;
|
||||||
|
|
||||||
|
AQUAMARINE_FORWARD(ISwitch);
|
||||||
|
|
||||||
struct SRenderData {
|
struct SRenderData {
|
||||||
CMonitor* pMonitor;
|
CMonitor* pMonitor;
|
||||||
timespec* when;
|
timespec* when;
|
||||||
|
@ -70,14 +72,14 @@ struct SSwipeGesture {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SSwitchDevice {
|
struct SSwitchDevice {
|
||||||
wlr_input_device* pWlrDevice = nullptr;
|
WP<Aquamarine::ISwitch> pDevice;
|
||||||
|
|
||||||
int status = -1; // uninitialized
|
struct {
|
||||||
|
CHyprSignalListener destroy;
|
||||||
DYNLISTENER(destroy);
|
CHyprSignalListener fire;
|
||||||
DYNLISTENER(toggle);
|
} listeners;
|
||||||
|
|
||||||
bool operator==(const SSwitchDevice& other) const {
|
bool operator==(const SSwitchDevice& other) const {
|
||||||
return pWlrDevice == other.pWlrDevice;
|
return pDevice == other.pDevice;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1568,44 +1568,30 @@ void CInputManager::setTabletConfigs() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInputManager::newSwitch(wlr_input_device* pDevice) {
|
void CInputManager::newSwitch(SP<Aquamarine::ISwitch> pDevice) {
|
||||||
const auto PNEWDEV = &m_lSwitches.emplace_back();
|
const auto PNEWDEV = &m_lSwitches.emplace_back();
|
||||||
PNEWDEV->pWlrDevice = pDevice;
|
PNEWDEV->pDevice = pDevice;
|
||||||
|
|
||||||
Debug::log(LOG, "New switch with name \"{}\" added", pDevice->name);
|
Debug::log(LOG, "New switch with name \"{}\" added", pDevice->getName());
|
||||||
|
|
||||||
PNEWDEV->hyprListener_destroy.initCallback(&pDevice->events.destroy, [&](void* owner, void* data) { destroySwitch((SSwitchDevice*)owner); }, PNEWDEV, "SwitchDevice");
|
PNEWDEV->listeners.destroy = pDevice->events.destroy.registerListener([this, PNEWDEV](std::any d) { destroySwitch(PNEWDEV); });
|
||||||
|
|
||||||
const auto PSWITCH = wlr_switch_from_input_device(pDevice);
|
PNEWDEV->listeners.fire = pDevice->events.fire.registerListener([PNEWDEV](std::any d) {
|
||||||
|
const auto NAME = PNEWDEV->pDevice->getName();
|
||||||
|
const auto E = std::any_cast<Aquamarine::ISwitch::SFireEvent>(d);
|
||||||
|
|
||||||
PNEWDEV->hyprListener_toggle.initCallback(
|
Debug::log(LOG, "Switch {} fired, triggering binds.", NAME);
|
||||||
&PSWITCH->events.toggle,
|
|
||||||
[&](void* owner, void* data) {
|
|
||||||
const auto PDEVICE = (SSwitchDevice*)owner;
|
|
||||||
const auto NAME = std::string(PDEVICE->pWlrDevice->name);
|
|
||||||
const auto E = (wlr_switch_toggle_event*)data;
|
|
||||||
|
|
||||||
if (PDEVICE->status != -1 && PDEVICE->status == E->switch_state)
|
g_pKeybindManager->onSwitchEvent(NAME);
|
||||||
return;
|
|
||||||
|
|
||||||
Debug::log(LOG, "Switch {} fired, triggering binds.", NAME);
|
if (E.enable) {
|
||||||
|
Debug::log(LOG, "Switch {} turn on, triggering binds.", NAME);
|
||||||
g_pKeybindManager->onSwitchEvent(NAME);
|
g_pKeybindManager->onSwitchOnEvent(NAME);
|
||||||
|
} else {
|
||||||
switch (E->switch_state) {
|
Debug::log(LOG, "Switch {} turn off, triggering binds.", NAME);
|
||||||
case WLR_SWITCH_STATE_ON:
|
g_pKeybindManager->onSwitchOffEvent(NAME);
|
||||||
Debug::log(LOG, "Switch {} turn on, triggering binds.", NAME);
|
}
|
||||||
g_pKeybindManager->onSwitchOnEvent(NAME);
|
});
|
||||||
break;
|
|
||||||
case WLR_SWITCH_STATE_OFF:
|
|
||||||
Debug::log(LOG, "Switch {} turn off, triggering binds.", NAME);
|
|
||||||
g_pKeybindManager->onSwitchOffEvent(NAME);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
PDEVICE->status = E->switch_state;
|
|
||||||
},
|
|
||||||
PNEWDEV, "SwitchDevice");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInputManager::destroySwitch(SSwitchDevice* pDevice) {
|
void CInputManager::destroySwitch(SSwitchDevice* pDevice) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ class IKeyboard;
|
||||||
AQUAMARINE_FORWARD(IPointer);
|
AQUAMARINE_FORWARD(IPointer);
|
||||||
AQUAMARINE_FORWARD(IKeyboard);
|
AQUAMARINE_FORWARD(IKeyboard);
|
||||||
AQUAMARINE_FORWARD(ITouch);
|
AQUAMARINE_FORWARD(ITouch);
|
||||||
|
AQUAMARINE_FORWARD(ISwitch);
|
||||||
|
|
||||||
enum eClickBehaviorMode {
|
enum eClickBehaviorMode {
|
||||||
CLICKMODE_DEFAULT = 0,
|
CLICKMODE_DEFAULT = 0,
|
||||||
|
@ -91,7 +92,7 @@ class CInputManager {
|
||||||
void newMouse(SP<Aquamarine::IPointer>);
|
void newMouse(SP<Aquamarine::IPointer>);
|
||||||
void newVirtualMouse(SP<CVirtualPointerV1Resource>);
|
void newVirtualMouse(SP<CVirtualPointerV1Resource>);
|
||||||
void newTouchDevice(SP<Aquamarine::ITouch>);
|
void newTouchDevice(SP<Aquamarine::ITouch>);
|
||||||
void newSwitch(wlr_input_device*);
|
void newSwitch(SP<Aquamarine::ISwitch>);
|
||||||
void newTabletTool(wlr_tablet_tool*);
|
void newTabletTool(wlr_tablet_tool*);
|
||||||
void newTabletPad(wlr_input_device*);
|
void newTabletPad(wlr_input_device*);
|
||||||
void newTablet(wlr_input_device*);
|
void newTablet(wlr_input_device*);
|
||||||
|
|
Loading…
Reference in a new issue