--- a/src/X11Command.h Fri Mar 26 22:29:46 2021 +0100
+++ b/src/X11Command.h Sat Mar 27 00:29:10 2021 +0100
@@ -18,6 +18,7 @@
#include <codecvt>
#include <memory>
+#include <algorithm>
#include <iostream>
#include <stdexcept>
@@ -58,11 +59,24 @@
std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings and use platform encoding as default
+ relpipe::common::type::StringX getDeviceType(Display& display, XDeviceInfo* device) {
+ if (device && device->type) {
+ char* raw = XGetAtomName(display.display, device->type);
+ if (raw) {
+ relpipe::common::type::StringX type = convertor.from_bytes(raw);
+ XFree(raw);
+ transform(type.begin(), type.end(), type.begin(), ::tolower);
+ return type;
+ }
+ }
+ return L"";
+ }
+
void listInputDevices(Display& display, Configuration& configuration, std::shared_ptr<writer::RelationalWriter> writer) {
writer->startRelation(L"x11_input_device",{
{L"id", relpipe::writer::TypeId::INTEGER},
{L"name", relpipe::writer::TypeId::STRING},
- // TODO: device type name and ID
+ {L"type", relpipe::writer::TypeId::STRING},
}, true);
DeviceList devices;
@@ -71,10 +85,11 @@
for (int i = 0; i < devices.count; i++) {
relpipe::common::type::Integer id = (devices.items + i)->id;
relpipe::common::type::StringX name = convertor.from_bytes((devices.items + i)->name);
+ relpipe::common::type::StringX type = getDeviceType(display, devices.items + i);
writer->writeAttribute(&id, typeid (id));
writer->writeAttribute(&name, typeid (name));
-
+ writer->writeAttribute(&type, typeid (type));
}
}