Skip to content

Commit

Permalink
More useful description of input devices
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanGriffiths committed Apr 15, 2024
1 parent ac97f87 commit dbbec03
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/platforms/evdev/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <boost/throw_exception.hpp>

#include <libinput.h>
#include <format>
#include <string>

namespace mi = mir::input;
Expand All @@ -53,13 +54,22 @@ std::string describe(libinput_device* dev)
auto const udev_dev = mir::raii::deleter_for(libinput_device_get_udev_device(dev), &udev_device_unref);
std::string desc(udev_device_get_devnode(udev_dev.get()));

char const * const model = udev_device_get_property_value(udev_dev.get(), "ID_MODEL");
if (model)
desc += ": " + std::string(model);
auto const vendor = libinput_device_get_id_vendor(dev);
auto const product = libinput_device_get_id_product(dev);
desc += std::format(" [{:0>4x}:{:0>4x}]", vendor, product);

// Yes, we could use std::replace but this will compile smaller and faster
for (auto &c : desc)
if (c == '_') c = ' ';
if (auto const name = libinput_device_get_name(dev))
{
desc += std::format(" '{:s}'", name);
}

for (auto const key : {/*"ID_MODEL", "ID_VENDOR_ID", "ID_MODEL_ID",*/ "ID_PATH"})
{
if (char const *const value = udev_device_get_property_value(udev_dev.get(), key))
{
desc += ": " + std::string(key) + "=" + value;
}
}

return desc;
}
Expand Down

0 comments on commit dbbec03

Please sign in to comment.