Skip to content

Commit

Permalink
Start adding input handling to qpa
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jan 25, 2024
1 parent 95f3b9b commit b2f261f
Show file tree
Hide file tree
Showing 10 changed files with 720 additions and 12 deletions.
2 changes: 1 addition & 1 deletion shared/libblight/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace Blight{
}
event_packet_t data;
memcpy(&data, maybe.value(), sizeof(event_packet_t));
delete maybe.value();
delete[] maybe.value();
return data;
}

Expand Down
19 changes: 15 additions & 4 deletions shared/libblight/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ std::optional<Blight::data_t> Blight::recv(
continue;
}
// Recieve the data
res = ::recv(fd, data, size, MSG_DONTWAIT);
res = ::recv(fd, data, size, MSG_WAITALL | MSG_DONTWAIT);
if(res > -1){
break;
}
Expand All @@ -69,9 +69,19 @@ std::optional<Blight::data_t> Blight::recv(
errno = EAGAIN;
return {};
}
// We started getting data, but didn't get all of it, try getting some more
if(res && res < size){
// TODO this should be in the main loop
auto maybe = recv_blocking(fd, size - res);
if(maybe.has_value()){
memcpy(&data[res], maybe.value(), size - res);
delete[] maybe.value();
return data;
}
}
// The data we recieved isn't the same size as what we expected
if(res != size){
_WARN("recv %d != %d", res, size);
_WARN("recv %d != %d", size, res);
delete[] data;
errno = EBADMSG;
return {};
Expand All @@ -83,7 +93,7 @@ std::optional<Blight::data_t> Blight::recv_blocking(int fd, ssize_t size){
auto data = new unsigned char[size];
ssize_t res = -1;
while(res < 0){
res = ::recv(fd, data, size, 0);
res = ::recv(fd, data, size, MSG_WAITALL);
// Something was recieved
if(res > 0){
break;
Expand All @@ -98,7 +108,7 @@ std::optional<Blight::data_t> Blight::recv_blocking(int fd, ssize_t size){
}
// The data we recieved isn't the same size as what we expected
if(res != size){
_WARN("recv %d != %d", res, size);
_WARN("recv_blocking %d != %d", size, res);
delete[] data;
errno = EBADMSG;
return {};
Expand All @@ -123,6 +133,7 @@ bool Blight::send_blocking(int fd, const data_t data, ssize_t size){
}
// The data we sent isn't the same size as what we expected
if(res != size){
_WARN("send_blocking %d != %d", size, res);
errno = EMSGSIZE;
return false;
}
Expand Down
26 changes: 22 additions & 4 deletions shared/liboxide/devicesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,20 @@ namespace Oxide {
qputenv("QT_QPA_GENERIC_PLUGINS", "evdevtablet");
}
}

bool DeviceSettings::keyboardAttached(){ return !physicalKeyboards().empty(); }

void DeviceSettings::onKeyboardAttachedChanged(std::function<void()> callback){
auto manager = QGuiApplicationPrivate::inputDeviceManager();
QObject::connect(manager, &QInputDeviceManager::deviceListChanged, [callback](QInputDeviceManager::DeviceType type){
if(type == QInputDeviceManager::DeviceTypeKeyboard){
callback();
QObject::connect(
manager,
&QInputDeviceManager::deviceListChanged,
[callback](QInputDeviceManager::DeviceType type){
if(type == QInputDeviceManager::DeviceTypeKeyboard){
callback();
}
}
});
);
}

QList<event_device> DeviceSettings::inputDevices(){
Expand All @@ -241,6 +247,18 @@ namespace Oxide {
return devices;
}

void DeviceSettings::onInputDevicesChanged(std::function<void()> callback){
auto manager = QGuiApplicationPrivate::inputDeviceManager();
QObject::connect(
manager,
&QInputDeviceManager::deviceListChanged,
[callback](QInputDeviceManager::DeviceType type){
Q_UNUSED(type);
callback();
}
);
}

QList<event_device> DeviceSettings::keyboards(){
QList<event_device> keyboards;
for(auto device : inputDevices()){
Expand Down
5 changes: 5 additions & 0 deletions shared/liboxide/devicesettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ namespace Oxide{
* \return All input devices
*/
QList<event_device> inputDevices();
/*!
* \brief Run a callback when inputDevices changes
* \param callback callback to run
*/
void onInputDevicesChanged(std::function<void()> callback);
/*!
* \brief Get the list of all keyboard evdev devices
* \return All keyboard devices
Expand Down
Loading

0 comments on commit b2f261f

Please sign in to comment.