# HG changeset patch # User František Kučera # Date 1616801350 -3600 # Node ID 8d44cba0a3d14e59b0511951f9d089921fdf4d97 # Parent 3bbf848b3565300ae37768f8882c60ae959390e1 list input devices: add type diff -r 3bbf848b3565 -r 8d44cba0a3d1 src/X11Command.h --- 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 #include +#include #include #include @@ -58,11 +59,24 @@ std::wstring_convert> 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) { 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)); } }