summaryrefslogtreecommitdiffhomepage
path: root/proto-libevdev
diff options
context:
space:
mode:
Diffstat (limited to 'proto-libevdev')
-rw-r--r--proto-libevdev/ftnoir_libevdev_controls.ui2
-rw-r--r--proto-libevdev/ftnoir_protocol_libevdev.cpp87
-rw-r--r--proto-libevdev/ftnoir_protocol_libevdev.h29
-rw-r--r--proto-libevdev/lang/de_DE.ts37
-rw-r--r--proto-libevdev/lang/nl_NL.ts26
-rw-r--r--proto-libevdev/lang/ru_RU.ts26
-rw-r--r--proto-libevdev/lang/stub.ts26
-rw-r--r--proto-libevdev/lang/zh_CN.ts37
8 files changed, 206 insertions, 64 deletions
diff --git a/proto-libevdev/ftnoir_libevdev_controls.ui b/proto-libevdev/ftnoir_libevdev_controls.ui
index d2b86445..8aa52627 100644
--- a/proto-libevdev/ftnoir_libevdev_controls.ui
+++ b/proto-libevdev/ftnoir_libevdev_controls.ui
@@ -14,7 +14,7 @@
</rect>
</property>
<property name="windowTitle">
- <string>VJoy</string>
+ <string>libevdev options</string>
</property>
<property name="windowIcon">
<iconset>
diff --git a/proto-libevdev/ftnoir_protocol_libevdev.cpp b/proto-libevdev/ftnoir_protocol_libevdev.cpp
index 6bf9b511..fefcd9bb 100644
--- a/proto-libevdev/ftnoir_protocol_libevdev.cpp
+++ b/proto-libevdev/ftnoir_protocol_libevdev.cpp
@@ -1,36 +1,65 @@
+// strerror_r(3)
+
+#ifdef __clang__
+# pragma clang diagnostic ignored "-Wreserved-id-macro"
+# pragma clang diagnostic ignored "-Wunused-macros"
+#endif
+
+#ifndef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 200112L
+#endif
+
#include "ftnoir_protocol_libevdev.h"
#include "api/plugin-api.hpp"
#include "compat/math.hpp"
-#include <stdio.h>
+#include <cstdlib>
+#include <cstring>
+#include <cstdio>
+#include <algorithm>
+
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
-#include <string.h>
-#include <algorithm>
+#include <QDebug>
-#define CHECK_LIBEVDEV(expr) if ((error = (expr)) != 0) goto error;
+#define CHECK_LIBEVDEV(expr) \
+ do { \
+ if (int error = (expr); error != 0) \
+ { \
+ error_code = -error; \
+ error_expr = #expr; \
+ goto fail; \
+ } \
+ } while (false)
-static const int max_input = 65535;
-static const int mid_input = 32767;
-static const int min_input = 0;
+static constexpr int max_input = 1 << 16;
+static constexpr int mid_input = (1 << 15) - 1;
+static constexpr int min_input = 0;
-evdev::evdev() : dev(NULL), uidev(NULL)
+evdev::evdev()
{
- int error = 0;
-
dev = libevdev_new();
if (!dev)
- goto error;
+ {
+ error_code = errno;
+ error_expr = "libevdev_new();";
+ goto fail;
+ }
CHECK_LIBEVDEV(libevdev_enable_property(dev, INPUT_PROP_BUTTONPAD));
libevdev_set_name(dev, "opentrack headpose");
+
+ libevdev_set_id_bustype(dev, 3);
+ libevdev_set_id_vendor(dev, 4324);
+ libevdev_set_id_product(dev, 3798);
+ libevdev_set_id_version(dev, 123);
struct input_absinfo absinfo;
@@ -57,15 +86,17 @@ evdev::evdev() : dev(NULL), uidev(NULL)
CHECK_LIBEVDEV(libevdev_uinput_create_from_device(dev, LIBEVDEV_UINPUT_OPEN_MANAGED, &uidev));
return;
-error:
+
+fail:
if (uidev)
libevdev_uinput_destroy(uidev);
if (dev)
libevdev_free(dev);
- if (error)
- fprintf(stderr, "libevdev error: %d\n", error);
- uidev = NULL;
- dev = NULL;
+
+ qDebug() << "libevdev error" << error_code;
+
+ uidev = nullptr;
+ dev = nullptr;
}
evdev::~evdev()
@@ -76,7 +107,7 @@ evdev::~evdev()
libevdev_free(dev);
}
-void evdev::pose(const double* headpose) {
+void evdev::pose(const double* headpose, const double*) {
static const int axes[] = {
/* translation goes first */
ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ
@@ -93,8 +124,8 @@ void evdev::pose(const double* headpose) {
for (int i = 0; i < 6; i++)
{
- int value = headpose[i] * mid_input / max_value[i] + mid_input;
- int normalized = clamp(value, min_input, max_input);
+ int value = (int)(headpose[i] * mid_input / max_value[i] + mid_input);
+ int normalized = std::clamp(value, min_input, max_input);
(void) libevdev_uinput_write_event(uidev, EV_ABS, axes[i], normalized);
}
@@ -103,14 +134,22 @@ void evdev::pose(const double* headpose) {
module_status evdev::initialize()
{
- if (access("/dev/uinput", R_OK | W_OK))
+ if (error_code)
{
+ const char* msg;
char buf[128] {};
- (void) strerror_r(errno, buf, sizeof(buf));
- return error(_("Can't open /dev/uinput: %1").arg(buf));
- }
- return status_ok();
+ if (!(msg = strerror_r(error_code, buf, sizeof(buf))))
+ {
+ snprintf(buf, sizeof(buf), "%d", error_code);
+ msg = buf;
+ }
+
+ return error(QStringLiteral("libevdev call '%1' failed with error '%2'")
+ .arg(!error_expr ? "<NULL>" : error_expr, msg));
+ }
+ else
+ return {};
}
OPENTRACK_DECLARE_PROTOCOL(evdev, LibevdevControls, evdevDll)
diff --git a/proto-libevdev/ftnoir_protocol_libevdev.h b/proto-libevdev/ftnoir_protocol_libevdev.h
index 7cf59053..b81c3baf 100644
--- a/proto-libevdev/ftnoir_protocol_libevdev.h
+++ b/proto-libevdev/ftnoir_protocol_libevdev.h
@@ -7,36 +7,34 @@
#pragma once
#include "ui_ftnoir_libevdev_controls.h"
-#include "compat/macros.hpp"
#include "api/plugin-api.hpp"
#include <libevdev/libevdev.h>
#include <libevdev/libevdev-uinput.h>
#include <QMessageBox>
-class evdev : public IProtocol
+class evdev : public TR, public IProtocol
{
+ Q_OBJECT
+
public:
evdev();
~evdev() override;
- bool correct() {
- return dev != NULL;
- }
- void pose(const double *headpose);
- QString game_name() {
- return _("Virtual joystick for Linux");
- }
-
+ void pose(const double *headpose, const double*) override;
+ QString game_name() override { return tr("Virtual joystick for Linux"); }
module_status initialize() override;
private:
- struct libevdev* dev;
- struct libevdev_uinput* uidev;
+ struct libevdev* dev = nullptr;
+ struct libevdev_uinput* uidev = nullptr;
+ int error_code = 0;
+ const char* error_expr = nullptr;
};
class LibevdevControls: public IProtocolDialog
{
Q_OBJECT
+
public:
LibevdevControls();
void register_protocol(IProtocol *) {}
@@ -53,7 +51,8 @@ private slots:
class evdevDll : public Metadata
{
-public:
- QString name() { return _("libevdev joystick receiver"); }
- QIcon icon() { return QIcon(":/images/linux.png"); }
+ Q_OBJECT
+
+ QString name() override { return tr("libevdev joystick receiver"); }
+ QIcon icon() override { return QIcon(":/images/linux.png"); }
};
diff --git a/proto-libevdev/lang/de_DE.ts b/proto-libevdev/lang/de_DE.ts
new file mode 100644
index 00000000..f66a1b39
--- /dev/null
+++ b/proto-libevdev/lang/de_DE.ts
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1" language="de_DE">
+<context>
+ <name>UICLibevdevControls</name>
+ <message>
+ <source>libevdev options</source>
+ <translation>libevdev-Optionen</translation>
+ </message>
+ <message>
+ <source>Make sure rw for /dev/input/uinput!</source>
+ <translation>Stelle sicher, dass /dev/input/uinput rw-Berechtigungen hat!</translation>
+ </message>
+ <message>
+ <source>OK</source>
+ <translation>Okay</translation>
+ </message>
+ <message>
+ <source>Cancel</source>
+ <translation>Abbruch</translation>
+ </message>
+</context>
+<context>
+ <name>evdev</name>
+ <message>
+ <source>Virtual joystick for Linux</source>
+ <translation>Virtueller Joystick für Linux</translation>
+ </message>
+</context>
+<context>
+ <name>evdevDll</name>
+ <message>
+ <source>libevdev joystick receiver</source>
+ <translation>libevdev-Joystick-Empfänger</translation>
+ </message>
+</context>
+</TS>
diff --git a/proto-libevdev/lang/nl_NL.ts b/proto-libevdev/lang/nl_NL.ts
index 503c6938..d6a2c333 100644
--- a/proto-libevdev/lang/nl_NL.ts
+++ b/proto-libevdev/lang/nl_NL.ts
@@ -4,24 +4,34 @@
<context>
<name>UICLibevdevControls</name>
<message>
- <location filename="../ftnoir_libevdev_controls.ui" line="+17"/>
- <source>VJoy</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location line="+16"/>
<source>Make sure rw for /dev/input/uinput!</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location line="+32"/>
<source>OK</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location line="+25"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
+ <message>
+ <source>libevdev options</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>evdev</name>
+ <message>
+ <source>Virtual joystick for Linux</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>evdevDll</name>
+ <message>
+ <source>libevdev joystick receiver</source>
+ <translation type="unfinished"></translation>
+ </message>
</context>
</TS>
diff --git a/proto-libevdev/lang/ru_RU.ts b/proto-libevdev/lang/ru_RU.ts
index 9e78d930..c6310cd0 100644
--- a/proto-libevdev/lang/ru_RU.ts
+++ b/proto-libevdev/lang/ru_RU.ts
@@ -4,24 +4,34 @@
<context>
<name>UICLibevdevControls</name>
<message>
- <location filename="../ftnoir_libevdev_controls.ui" line="+17"/>
- <source>VJoy</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location line="+16"/>
<source>Make sure rw for /dev/input/uinput!</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location line="+32"/>
<source>OK</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location line="+25"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
+ <message>
+ <source>libevdev options</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>evdev</name>
+ <message>
+ <source>Virtual joystick for Linux</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>evdevDll</name>
+ <message>
+ <source>libevdev joystick receiver</source>
+ <translation type="unfinished"></translation>
+ </message>
</context>
</TS>
diff --git a/proto-libevdev/lang/stub.ts b/proto-libevdev/lang/stub.ts
index ae9cf4cc..ffafa2ec 100644
--- a/proto-libevdev/lang/stub.ts
+++ b/proto-libevdev/lang/stub.ts
@@ -4,24 +4,34 @@
<context>
<name>UICLibevdevControls</name>
<message>
- <location filename="../ftnoir_libevdev_controls.ui" line="+17"/>
- <source>VJoy</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location line="+16"/>
<source>Make sure rw for /dev/input/uinput!</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location line="+32"/>
<source>OK</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location line="+25"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
+ <message>
+ <source>libevdev options</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>evdev</name>
+ <message>
+ <source>Virtual joystick for Linux</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>evdevDll</name>
+ <message>
+ <source>libevdev joystick receiver</source>
+ <translation type="unfinished"></translation>
+ </message>
</context>
</TS>
diff --git a/proto-libevdev/lang/zh_CN.ts b/proto-libevdev/lang/zh_CN.ts
new file mode 100644
index 00000000..f5e8694c
--- /dev/null
+++ b/proto-libevdev/lang/zh_CN.ts
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1" language="zh_CN">
+<context>
+ <name>UICLibevdevControls</name>
+ <message>
+ <source>Make sure rw for /dev/input/uinput!</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>OK</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Cancel</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>libevdev options</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>evdev</name>
+ <message>
+ <source>Virtual joystick for Linux</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>evdevDll</name>
+ <message>
+ <source>libevdev joystick receiver</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+</TS>