mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-23 22:25:59 +01:00
switches
This commit is contained in:
parent
920e34efa1
commit
6e35f6335e
6 changed files with 39 additions and 43 deletions
|
@ -307,6 +307,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() {
|
||||
|
|
|
@ -627,7 +627,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);
|
||||
|
@ -675,7 +675,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() : "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1532,45 +1532,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();
|
||||
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->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;
|
||||
|
||||
if (PDEVICE->status != -1 && PDEVICE->status == E->switch_state)
|
||||
return;
|
||||
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);
|
||||
|
||||
Debug::log(LOG, "Switch {} fired, triggering binds.", NAME);
|
||||
|
||||
g_pKeybindManager->onSwitchEvent(NAME);
|
||||
|
||||
switch (E->switch_state) {
|
||||
case WLR_SWITCH_STATE_ON:
|
||||
if (E.enable) {
|
||||
Debug::log(LOG, "Switch {} turn on, triggering binds.", NAME);
|
||||
g_pKeybindManager->onSwitchOnEvent(NAME);
|
||||
break;
|
||||
case WLR_SWITCH_STATE_OFF:
|
||||
} else {
|
||||
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) {
|
||||
|
|
|
@ -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*);
|
||||
|
|
Loading…
Reference in a new issue