This commit is contained in:
Vaxry 2024-06-29 18:18:19 +02:00
parent 9f761a9590
commit cb3a3a4998
6 changed files with 39 additions and 42 deletions

View File

@ -308,6 +308,14 @@ void CCompositor::initAllSignals() {
g_pInputManager->updateCapabilities();
},
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() {

View File

@ -654,7 +654,7 @@ std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) {
"address": "0x{:x}",
"name": "{}"
}},)#",
(uintptr_t)&d, escapeJSONStrings(d.pWlrDevice ? d.pWlrDevice->name : ""));
(uintptr_t)&d, escapeJSONStrings(d.pDevice ? d.pDevice->getName() : ""));
}
trimTrailingComma(result);
@ -702,7 +702,7 @@ std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) {
result += "\n\nSwitches:\n";
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() : "");
}
}

View File

@ -41,7 +41,7 @@ void Events::listener_newInput(wl_listener* listener, void* data) {
break;
case WLR_INPUT_DEVICE_SWITCH:
Debug::log(LOG, "Attached a switch device with name {}", DEVICE->name);
g_pInputManager->newSwitch(DEVICE);
// g_pInputManager->newSwitch(DEVICE);
break;
default: Debug::log(WARN, "Unrecognized input device plugged in: {}", DEVICE->name); break;
}

View File

@ -15,6 +15,8 @@ class IPointer;
class IKeyboard;
class CWLSurfaceResource;
AQUAMARINE_FORWARD(ISwitch);
struct SRenderData {
CMonitor* pMonitor;
timespec* when;
@ -70,14 +72,14 @@ struct SSwipeGesture {
};
struct SSwitchDevice {
wlr_input_device* pWlrDevice = nullptr;
WP<Aquamarine::ISwitch> pDevice;
int status = -1; // uninitialized
DYNLISTENER(destroy);
DYNLISTENER(toggle);
struct {
CHyprSignalListener destroy;
CHyprSignalListener fire;
} listeners;
bool operator==(const SSwitchDevice& other) const {
return pWlrDevice == other.pWlrDevice;
return pDevice == other.pDevice;
}
};

View File

@ -1568,44 +1568,30 @@ void CInputManager::setTabletConfigs() {
}
}
void CInputManager::newSwitch(wlr_input_device* pDevice) {
const auto PNEWDEV = &m_lSwitches.emplace_back();
PNEWDEV->pWlrDevice = pDevice;
void CInputManager::newSwitch(SP<Aquamarine::ISwitch> pDevice) {
const auto PNEWDEV = &m_lSwitches.emplace_back();
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(
&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;
Debug::log(LOG, "Switch {} fired, triggering binds.", NAME);
if (PDEVICE->status != -1 && PDEVICE->status == E->switch_state)
return;
g_pKeybindManager->onSwitchEvent(NAME);
Debug::log(LOG, "Switch {} fired, triggering binds.", NAME);
g_pKeybindManager->onSwitchEvent(NAME);
switch (E->switch_state) {
case WLR_SWITCH_STATE_ON:
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");
if (E.enable) {
Debug::log(LOG, "Switch {} turn on, triggering binds.", NAME);
g_pKeybindManager->onSwitchOnEvent(NAME);
} else {
Debug::log(LOG, "Switch {} turn off, triggering binds.", NAME);
g_pKeybindManager->onSwitchOffEvent(NAME);
}
});
}
void CInputManager::destroySwitch(SSwitchDevice* pDevice) {

View File

@ -21,6 +21,7 @@ class IKeyboard;
AQUAMARINE_FORWARD(IPointer);
AQUAMARINE_FORWARD(IKeyboard);
AQUAMARINE_FORWARD(ITouch);
AQUAMARINE_FORWARD(ISwitch);
enum eClickBehaviorMode {
CLICKMODE_DEFAULT = 0,
@ -91,7 +92,7 @@ class CInputManager {
void newMouse(SP<Aquamarine::IPointer>);
void newVirtualMouse(SP<CVirtualPointerV1Resource>);
void newTouchDevice(SP<Aquamarine::ITouch>);
void newSwitch(wlr_input_device*);
void newSwitch(SP<Aquamarine::ISwitch>);
void newTabletTool(wlr_tablet_tool*);
void newTabletPad(wlr_input_device*);
void newTablet(wlr_input_device*);