Skip to content

Commit

Permalink
Fix multitouch handling to fix onscreen keyboard handling (#298)
Browse files Browse the repository at this point in the history
* Fix #296

* Add code to handle skipping SYN_DROPPED events

* Fix version reporting to sentry

* Handle invalid touch events

* Add install-lib methods, don't set existing if invalid touch event
  • Loading branch information
Eeems authored Apr 24, 2023
1 parent c87afd0 commit 80eb537
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 21 deletions.
3 changes: 3 additions & 0 deletions applications/system-service/buttonhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ void button_exit_handler(){
}

void flush_stream(istream* stream){
// Skip the next event
input_event ie;
streamsize sie = static_cast<streamsize>(sizeof(struct input_event));
stream->read((char*)&ie, sie);
}
void press_button(event_device& evdev, int code, istream* stream){
#ifdef DEBUG
qDebug() << "inject button " << code;
#endif
unlock_device(evdev);
ev_key(evdev, code, 1);
flush_stream(stream);
Expand Down
50 changes: 44 additions & 6 deletions applications/system-service/digitizerhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <linux/input.h>
#include <iostream>
#include <string>
#include <vector>
#include <liboxide.h>

#include "event_device.h"
Expand Down Expand Up @@ -91,7 +92,9 @@ class DigitizerHandler : public QThread {
void write(ushort type, ushort code, int value){
auto event = createEvent(type, code, value);
::write(device.fd, &event, sizeof(input_event));
#ifdef DEBUG
qDebug() << "Emitted event " << event.time.tv_sec << event.time.tv_usec << type << code << value;
#endif
}
void write(input_event* events, size_t size){
::write(device.fd, events, size);
Expand Down Expand Up @@ -125,7 +128,7 @@ class DigitizerHandler : public QThread {
input_event* build_flood(){
auto n = 512 * 8;
auto num_inst = 4;
input_event* ev = (input_event *)malloc(sizeof(struct input_event) * n * num_inst);
input_event* ev = (input_event*)malloc(sizeof(struct input_event) * n * num_inst);
memset(ev, 0, sizeof(input_event) * n * num_inst);
auto i = 0;
while (i < n) {
Expand All @@ -147,13 +150,48 @@ class DigitizerHandler : public QThread {
}
}
bool handle_events(){
vector<input_event> event_buffer;
bool success = true;
while(true){
input_event event;
if(!read(&event)){
success = false;
goto exitLoop;
}
event_buffer.push_back(event);
switch(event.type){
case EV_SYN:
switch(event.code){
case SYN_DROPPED:
event_buffer.clear();
skip_event();
case SYN_REPORT:
case SYN_MT_REPORT:
goto exitLoop;
break;
}
break;
}
}
exitLoop:
if(event_buffer.size()){
for(input_event event : event_buffer){
emit inputEvent(event);
}
emit activity();
}
return success;
}
void skip_event(){
input_event event;
if(!read(&event)){
return false;
while(read(&event)){
if(event.type != EV_SYN){
continue;
}
if(event.code == SYN_REPORT || event.code == SYN_MT_REPORT){
break;
}
}
emit inputEvent(event);
emit activity();
return true;
}
__gnu_cxx::stdio_filebuf<char> filebuf;
istream stream;
Expand Down
6 changes: 6 additions & 0 deletions applications/system-service/event_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ void ev_syn(event_device& evdev){
key_input_event.code = SYN_REPORT;
write_event(evdev, key_input_event);
}
void ev_dropped(event_device& evdev){
struct input_event key_input_event;
key_input_event.type = EV_SYN;
key_input_event.code = SYN_DROPPED;
write_event(evdev, key_input_event);
}
void ev_key(event_device& evdev, int code, int value){
struct input_event key_input_event;
key_input_event.type = EV_KEY;
Expand Down
1 change: 1 addition & 0 deletions applications/system-service/event_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ int lock_device(event_device& evdev);
int unlock_device(event_device& evdev);
void write_event(event_device& evdev, input_event ie);
void ev_syn(event_device& evdev);
void ev_dropped(event_device& evdev);
void ev_key(event_device& evdev, int code, int value = 0);

#endif // EVENT_DEVICE_H
41 changes: 29 additions & 12 deletions applications/system-service/systemapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ struct Inhibitor {
bool released() { return fd == -1; }
};

#define NULL_TOUCH_COORD -1

struct Touch {
int slot = 0;
int id = -1;
int x = 0;
int y = 0;
int x = NULL_TOUCH_COORD;
int y = NULL_TOUCH_COORD;
bool active = false;
bool existing = false;
bool modified = true;
Expand Down Expand Up @@ -470,7 +472,7 @@ private slots:
// Setup touches for next event set
for(auto touch : touches.values()){
touch->modified = false;
touch->existing = true;
touch->existing = touch->existing || (touch->x != NULL_TOUCH_COORD && touch->y != NULL_TOUCH_COORD);
}
break;
}
Expand All @@ -487,11 +489,8 @@ private slots:
}break;
case ABS_MT_TRACKING_ID:{
auto touch = getEvent(currentSlot);
if(event.value == -1){
touch->active = false;
currentSlot = 0;
}else{
touch->active = true;
touch->active = event.value != -1;
if(touch->active){
touch->id = event.value;
}
}break;
Expand Down Expand Up @@ -614,7 +613,7 @@ private slots:
return;
}
auto touch = touches.first();
if(swipeDirection != None){
if(swipeDirection != None || touch->x == NULL_TOUCH_COORD || touch->y == NULL_TOUCH_COORD){
return;
}
int offset = 20;
Expand Down Expand Up @@ -686,6 +685,13 @@ private slots:
return;
}
auto touch = touches.first();
if(touch->x == NULL_TOUCH_COORD || touch->y == NULL_TOUCH_COORD){
if(Oxide::debugEnabled()){
qDebug() << "Invalid touch event";
}
swipeDirection = None;
return;
}
if(swipeDirection == Up){
if(!swipeStates[Up] || touch->y < location.y() || touch->y - startLocation.y() < swipeLengths[Up]){
// Must end swiping up and having gone far enough
Expand Down Expand Up @@ -795,11 +801,22 @@ private slots:
if(Oxide::debugEnabled()){
qDebug() << "Write touch move" << touch;
}
int size = sizeof(input_event) * 8;
int count = 8;
if(touch->x == NULL_TOUCH_COORD){
count--;
}
if(touch->y == NULL_TOUCH_COORD){
count--;
}
int size = sizeof(input_event) * count;
input_event* events = (input_event*)malloc(size);
events[2] = DigitizerHandler::createEvent(EV_ABS, ABS_MT_SLOT, touch->slot);
events[2] = DigitizerHandler::createEvent(EV_ABS, ABS_MT_POSITION_X, touch->x);
events[2] = DigitizerHandler::createEvent(EV_ABS, ABS_MT_POSITION_Y, touch->y);
if(touch->x != NULL_TOUCH_COORD){
events[2] = DigitizerHandler::createEvent(EV_ABS, ABS_MT_POSITION_X, touch->x);
}
if(touch->y != NULL_TOUCH_COORD){
events[2] = DigitizerHandler::createEvent(EV_ABS, ABS_MT_POSITION_Y, touch->y);
}
events[2] = DigitizerHandler::createEvent(EV_ABS, ABS_MT_PRESSURE, touch->pressure);
events[2] = DigitizerHandler::createEvent(EV_ABS, ABS_MT_TOUCH_MAJOR, touch->major);
events[2] = DigitizerHandler::createEvent(EV_ABS, ABS_MT_TOUCH_MINOR, touch->minor);
Expand Down
37 changes: 37 additions & 0 deletions package
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,43 @@ source=(oxide.tar.gz)
sha256sums=(SKIP)
image=qt:latest
_sentry=0.5.0
########################################
# These functions come from install-lib:
# https://raw.githubusercontent.com/toltec-dev/toltec/master/scripts/install-lib
########################################
is-active() {
systemctl --quiet is-active "$1" 2> /dev/null
}
is-enabled() {
systemctl --quiet is-enabled "$1" 2> /dev/null
}
get-conflicts() {
# Find enabled units that have a conflicting name
for name in $(systemctl cat "$1" | awk -F'=' '/^Alias=/{print $2}'); do
local realname
if realname="$(basename "$(readlink "/etc/systemd/system/$name")")"; then
echo "$realname"
fi
done

# Find units that are declared as conflicting
# (systemd automatically adds a conflict with "shutdown.target" to all
# service units see systemd.service(5), section "Automatic Dependencies")
systemctl show "$1" | awk -F'=' '/^Conflicts=/{print $2}' \
| sed 's|\bshutdown.target\b||'
}
how-to-enable() {
for conflict in $(get-conflicts "$1"); do
if is-enabled "$conflict"; then
echo "$ systemctl disable --now ${conflict/.service/}"
fi
done

echo "$ systemctl enable --now ${1/.service/}"
}
########################################
# End of install-lib methods
########################################

build() {
find . -name "*.pro" -type f -print0 \
Expand Down
10 changes: 10 additions & 0 deletions shared/liboxide/liboxide.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
#include <QThread>

#include <sys/types.h>
#ifndef VERSION
#ifdef APP_VERSION
#define VERSION APP_VERSION
#else
#define VERSION "2.6"
#endif
#endif
#ifndef APP_VERSION
#define APP_VERSION VERSION
#endif
/*!
* \def deviceSettings()
* \brief Get the Oxide::DeviceSettings instance
Expand Down
6 changes: 3 additions & 3 deletions shared/liboxide/oxide_sentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ namespace Oxide::Sentry{
}
sentry_options_set_debug(options, debugEnabled());
sentry_options_set_database_path(options, "/home/root/.cache/Eeems/sentry");
sentry_options_set_release(options, (std::string(name) + "@2.4").c_str());
sentry_init(options);
sentry_options_set_release(options, (std::string(name) + "@" + APP_VERSION).c_str());
::sentry_init(options);

// Setup user
sentry_value_t user = sentry_value_new_object();
Expand All @@ -171,7 +171,7 @@ namespace Oxide::Sentry{
sentry_set_tag("name", name);
sentry_value_t device = sentry_value_new_object();
sentry_value_set_by_key(device, "machine-id", sentry_value_new_string(machineId()));
sentry_value_set_by_key(device, "version", sentry_value_new_string(readFile("/etc/version").c_str()));
sentry_value_set_by_key(device, "version", sentry_value_new_string(version.c_str()));
sentry_value_set_by_key(device, "model", sentry_value_new_string(deviceSettings.getDeviceName()));
sentry_set_context("device", device);
// Setup transaction
Expand Down

0 comments on commit 80eb537

Please sign in to comment.