mirror of
https://github.com/hyprwm/aquamarine.git
synced 2024-11-17 07:15:59 +01:00
libinput: add switch support
This commit is contained in:
parent
84b936b21e
commit
c7fa62afe8
5 changed files with 113 additions and 9 deletions
|
@ -109,6 +109,10 @@ namespace Aquamarine {
|
|||
Hyprutils::Signal::CSignal newPointer;
|
||||
Hyprutils::Signal::CSignal newKeyboard;
|
||||
Hyprutils::Signal::CSignal newTouch;
|
||||
Hyprutils::Signal::CSignal newSwitch;
|
||||
Hyprutils::Signal::CSignal newTablet;
|
||||
Hyprutils::Signal::CSignal newTabletTool;
|
||||
Hyprutils::Signal::CSignal newTabletPad;
|
||||
} events;
|
||||
|
||||
Hyprutils::Memory::CSharedPointer<IAllocator> allocator;
|
||||
|
|
|
@ -99,6 +99,23 @@ namespace Aquamarine {
|
|||
Hyprutils::Memory::CWeakPointer<CLibinputDevice> device;
|
||||
};
|
||||
|
||||
class CLibinputSwitch : public ISwitch {
|
||||
public:
|
||||
CLibinputSwitch(Hyprutils::Memory::CSharedPointer<CLibinputDevice> dev);
|
||||
virtual ~CLibinputSwitch() {
|
||||
;
|
||||
}
|
||||
|
||||
virtual libinput_device* getLibinputHandle();
|
||||
virtual const std::string& getName();
|
||||
|
||||
eSwitchType type = AQ_SWITCH_TYPE_UNKNOWN;
|
||||
bool state = false;
|
||||
|
||||
private:
|
||||
Hyprutils::Memory::CWeakPointer<CLibinputDevice> device;
|
||||
};
|
||||
|
||||
class CLibinputDevice {
|
||||
public:
|
||||
CLibinputDevice(libinput_device* device, Hyprutils::Memory::CWeakPointer<CSession> session_);
|
||||
|
@ -114,6 +131,7 @@ namespace Aquamarine {
|
|||
Hyprutils::Memory::CSharedPointer<CLibinputKeyboard> keyboard;
|
||||
Hyprutils::Memory::CSharedPointer<CLibinputMouse> mouse;
|
||||
Hyprutils::Memory::CSharedPointer<CLibinputTouch> touch;
|
||||
Hyprutils::Memory::CSharedPointer<CLibinputSwitch> switchy; // :)
|
||||
};
|
||||
|
||||
class CSession {
|
||||
|
|
|
@ -189,6 +189,33 @@ namespace Aquamarine {
|
|||
} events;
|
||||
};
|
||||
|
||||
class ISwitch {
|
||||
public:
|
||||
virtual ~ISwitch() {
|
||||
events.destroy.emit();
|
||||
}
|
||||
|
||||
virtual libinput_device* getLibinputHandle();
|
||||
virtual const std::string& getName() = 0;
|
||||
|
||||
enum eSwitchType {
|
||||
AQ_SWITCH_TYPE_UNKNOWN = 0,
|
||||
AQ_SWITCH_TYPE_LID,
|
||||
AQ_SWITCH_TYPE_TABLET_MODE,
|
||||
};
|
||||
|
||||
struct SFireEvent {
|
||||
uint32_t timeMs = 0;
|
||||
eSwitchType type = AQ_SWITCH_TYPE_UNKNOWN;
|
||||
bool enable = false;
|
||||
};
|
||||
|
||||
struct {
|
||||
Hyprutils::Signal::CSignal destroy;
|
||||
Hyprutils::Signal::CSignal fire;
|
||||
} events;
|
||||
};
|
||||
|
||||
class ITablet {
|
||||
public:
|
||||
// FIXME:
|
||||
|
|
|
@ -267,6 +267,8 @@ void Aquamarine::CSession::onReady() {
|
|||
backend->events.newPointer.emit(SP<IPointer>(d->mouse));
|
||||
if (d->touch)
|
||||
backend->events.newTouch.emit(SP<ITouch>(d->touch));
|
||||
if (d->switchy)
|
||||
backend->events.newSwitch.emit(SP<ITouch>(d->touch));
|
||||
|
||||
// FIXME: other devices.
|
||||
}
|
||||
|
@ -571,7 +573,7 @@ void Aquamarine::CSession::handleLibinputEvent(libinput_event* e) {
|
|||
break;
|
||||
}
|
||||
|
||||
// ---------- touch
|
||||
// --------- touch
|
||||
|
||||
case LIBINPUT_EVENT_TOUCH_DOWN: {
|
||||
auto te = libinput_event_get_touch_event(e);
|
||||
|
@ -612,6 +614,33 @@ void Aquamarine::CSession::handleLibinputEvent(libinput_event* e) {
|
|||
break;
|
||||
}
|
||||
|
||||
// --------- switch
|
||||
|
||||
case LIBINPUT_EVENT_SWITCH_TOGGLE: {
|
||||
auto se = libinput_event_get_switch_event(e);
|
||||
|
||||
const bool ENABLED = libinput_event_switch_get_switch_state(se) == LIBINPUT_SWITCH_STATE_ON;
|
||||
|
||||
if (ENABLED == hlDevice->switchy->state)
|
||||
return;
|
||||
|
||||
switch (libinput_event_switch_get_switch(se)) {
|
||||
case LIBINPUT_SWITCH_LID: hlDevice->switchy->type = ISwitch::AQ_SWITCH_TYPE_LID; break;
|
||||
case LIBINPUT_SWITCH_TABLET_MODE: hlDevice->switchy->type = ISwitch::AQ_SWITCH_TYPE_TABLET_MODE; break;
|
||||
}
|
||||
|
||||
hlDevice->switchy->events.fire.emit(ISwitch::SFireEvent{
|
||||
.timeMs = (uint32_t)(libinput_event_switch_get_time_usec(se) / 1000),
|
||||
.type = hlDevice->switchy->type,
|
||||
.enable = ENABLED,
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
// --------- tbalet
|
||||
|
||||
|
||||
|
||||
// FIXME: other events
|
||||
|
||||
default: break;
|
||||
|
@ -652,6 +681,12 @@ void Aquamarine::CLibinputDevice::init() {
|
|||
session->backend->events.newTouch.emit(SP<ITouch>(touch));
|
||||
}
|
||||
|
||||
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_SWITCH)) {
|
||||
switchy = makeShared<CLibinputSwitch>(self.lock());
|
||||
if (session->backend->ready)
|
||||
session->backend->events.newSwitch.emit(SP<ISwitch>(switchy));
|
||||
}
|
||||
|
||||
// FIXME: other devices
|
||||
}
|
||||
|
||||
|
@ -710,3 +745,19 @@ const std::string& Aquamarine::CLibinputTouch::getName() {
|
|||
return AQ_UNKNOWN_DEVICE_NAME;
|
||||
return device->name;
|
||||
}
|
||||
|
||||
Aquamarine::CLibinputSwitch::CLibinputSwitch(Hyprutils::Memory::CSharedPointer<CLibinputDevice> dev) : device(dev) {
|
||||
;
|
||||
}
|
||||
|
||||
libinput_device* Aquamarine::CLibinputSwitch::getLibinputHandle() {
|
||||
if (!device)
|
||||
return nullptr;
|
||||
return device->device;
|
||||
}
|
||||
|
||||
const std::string& Aquamarine::CLibinputSwitch::getName() {
|
||||
if (!device)
|
||||
return AQ_UNKNOWN_DEVICE_NAME;
|
||||
return device->name;
|
||||
}
|
|
@ -12,6 +12,10 @@ libinput_device* Aquamarine::ITouch::getLibinputHandle() {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
libinput_device* Aquamarine::ISwitch::getLibinputHandle() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Aquamarine::IKeyboard::updateLEDs(uint32_t leds) {
|
||||
;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue