56 }; |
57 }; |
57 |
58 |
58 |
59 |
59 std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings and use platform encoding as default |
60 std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings and use platform encoding as default |
60 |
61 |
|
62 relpipe::common::type::StringX getDeviceType(Display& display, XDeviceInfo* device) { |
|
63 if (device && device->type) { |
|
64 char* raw = XGetAtomName(display.display, device->type); |
|
65 if (raw) { |
|
66 relpipe::common::type::StringX type = convertor.from_bytes(raw); |
|
67 XFree(raw); |
|
68 transform(type.begin(), type.end(), type.begin(), ::tolower); |
|
69 return type; |
|
70 } |
|
71 } |
|
72 return L""; |
|
73 } |
|
74 |
61 void listInputDevices(Display& display, Configuration& configuration, std::shared_ptr<writer::RelationalWriter> writer) { |
75 void listInputDevices(Display& display, Configuration& configuration, std::shared_ptr<writer::RelationalWriter> writer) { |
62 writer->startRelation(L"x11_input_device",{ |
76 writer->startRelation(L"x11_input_device",{ |
63 {L"id", relpipe::writer::TypeId::INTEGER}, |
77 {L"id", relpipe::writer::TypeId::INTEGER}, |
64 {L"name", relpipe::writer::TypeId::STRING}, |
78 {L"name", relpipe::writer::TypeId::STRING}, |
65 // TODO: device type name and ID |
79 {L"type", relpipe::writer::TypeId::STRING}, |
66 }, true); |
80 }, true); |
67 |
81 |
68 DeviceList devices; |
82 DeviceList devices; |
69 devices.items = XListInputDevices(display.display, &devices.count); |
83 devices.items = XListInputDevices(display.display, &devices.count); |
70 |
84 |
71 for (int i = 0; i < devices.count; i++) { |
85 for (int i = 0; i < devices.count; i++) { |
72 relpipe::common::type::Integer id = (devices.items + i)->id; |
86 relpipe::common::type::Integer id = (devices.items + i)->id; |
73 relpipe::common::type::StringX name = convertor.from_bytes((devices.items + i)->name); |
87 relpipe::common::type::StringX name = convertor.from_bytes((devices.items + i)->name); |
|
88 relpipe::common::type::StringX type = getDeviceType(display, devices.items + i); |
74 |
89 |
75 writer->writeAttribute(&id, typeid (id)); |
90 writer->writeAttribute(&id, typeid (id)); |
76 writer->writeAttribute(&name, typeid (name)); |
91 writer->writeAttribute(&name, typeid (name)); |
77 |
92 writer->writeAttribute(&type, typeid (type)); |
78 } |
93 } |
79 } |
94 } |
80 |
95 |
81 void listInputEvents(Display& display, Configuration& configuration, std::shared_ptr<writer::RelationalWriter> writer) { |
96 void listInputEvents(Display& display, Configuration& configuration, std::shared_ptr<writer::RelationalWriter> writer) { |
82 writer->startRelation(L"x11_input_event",{ |
97 writer->startRelation(L"x11_input_event",{ |