libinput: add switch support

This commit is contained in:
Vaxry 2024-06-29 18:10:21 +02:00
parent 84b936b21e
commit c7fa62afe8
5 changed files with 113 additions and 9 deletions

View file

@ -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;

View file

@ -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 {

View file

@ -13,7 +13,7 @@ namespace Aquamarine {
}
virtual libinput_device* getLibinputHandle();
virtual const std::string& getName() = 0;
virtual void updateLEDs(uint32_t leds);
virtual void updateLEDs(uint32_t leds);
struct SKeyEvent {
uint32_t timeMs = 0;
@ -79,7 +79,7 @@ namespace Aquamarine {
ePointerAxis axis = AQ_POINTER_AXIS_VERTICAL;
ePointerAxisSource source = AQ_POINTER_AXIS_SOURCE_WHEEL;
ePointerAxisRelativeDirection direction = AQ_POINTER_AXIS_RELATIVE_IDENTICAL;
double delta = 0.0, discrete = 0.0;
double delta = 0.0, discrete = 0.0;
};
struct SSwipeBeginEvent {
@ -88,8 +88,8 @@ namespace Aquamarine {
};
struct SSwipeUpdateEvent {
uint32_t timeMs = 0;
uint32_t fingers = 0;
uint32_t timeMs = 0;
uint32_t fingers = 0;
Hyprutils::Math::Vector2D delta;
};
@ -104,10 +104,10 @@ namespace Aquamarine {
};
struct SPinchUpdateEvent {
uint32_t timeMs = 0;
uint32_t fingers = 0;
uint32_t timeMs = 0;
uint32_t fingers = 0;
Hyprutils::Math::Vector2D delta;
double scale = 1.0, rotation = 0.0;
double scale = 1.0, rotation = 0.0;
};
struct SPinchEndEvent {
@ -155,7 +155,7 @@ namespace Aquamarine {
virtual libinput_device* getLibinputHandle();
virtual const std::string& getName() = 0;
Hyprutils::Math::Vector2D physicalSize; // in mm, 0,0 if unknown
Hyprutils::Math::Vector2D physicalSize; // in mm, 0,0 if unknown
struct SDownEvent {
uint32_t timeMs = 0;
@ -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:

View file

@ -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;
}

View file

@ -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) {
;
}