Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input device updates #2510

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pixman = dependency('pixman-1')
xkbcommon = dependency('xkbcommon')
libdl = meson.get_compiler('cpp').find_library('dl')
json = dependency('nlohmann_json', version: '>= 3.11.2')
udev = dependency('libudev')

# We're not to use system wlroots: So we'll use the subproject
if get_option('use_system_wlroots').disabled()
Expand Down
67 changes: 63 additions & 4 deletions src/core/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "wayfire/signal-definitions.hpp"
#include <wayfire/util/log.hpp>
#include <wayfire/config-backend.hpp>
#include <libudev.h>

void wf::plugin_interface_t::fini()
{}
Expand All @@ -27,18 +28,76 @@ std::shared_ptr<config::section_t> wf::config_backend_t::get_output_section(
return config.get_section(name);
}

static struct udev_property_and_desc
{
char const *property_name;
char const *description;
} properties_and_descs[] =
{
{"ID_PATH", "stable physical connection path"},
{"ID_SERIAL", "stable vendor+pn+sn info"},
{"LIBINPUT_DEVICE_GROUP", "stable libinput info"},
// sometimes it contains info "by path", sometimes "by id"
{"DEVPATH", "unstable devpath"},
// used for debugging, to find DEVPATH and match the right
// device in `udevadm info --tree`
};

std::shared_ptr<config::section_t> wf::config_backend_t::get_input_device_section(
wlr_input_device *device)
{
auto& config = wf::get_core().config;
std::shared_ptr<wf::config::section_t> section;
auto print_devpath = getenv("WF_PRINT_UDEV_DEVPATH");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you are looking for here are the debug categories, they are rather simple to add, maybe an input-device category?

Check these here: https://github.com/WayfireWM/wayfire/blob/master/src/api/wayfire/debug.hpp#L42

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, this makes more sense. This way we can use wayfire -d input-device to get the additional message(s).


if (wlr_input_device_is_libinput(device))
{
auto libinput_dev = wlr_libinput_get_device_handle(device);
if (libinput_dev)
{
udev_device *udev_dev = libinput_device_get_udev_device(libinput_dev);
if (udev_dev)
{
for (struct udev_property_and_desc const & pd : properties_and_descs)
{
if (!print_devpath && !strncmp(pd.property_name, "DEVPATH", strlen("DEVPATH")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, wouldn't it be more appropriate to send this info over via IPC and print it in the scripts we already have for listing input devices? I can imagine that this would be much easier to use.

Otherwise, I think we can/should just print every property we are querying here (in the corresponding debug category).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree that we should require ipc for this task. It should be as easy as wayfire -d input-device (or plural, input-devices).

{
continue;
}

const char *value = udev_device_get_property_value(udev_dev, pd.property_name);
if (value == nullptr)
{
continue;
}

std::string name = std::string("input-device:") + nonull(value);
LOGD("Checking for config section [", name, "] ",
pd.property_name, " (", pd.description, ")");
section = config.get_section(name);
if (section)
{
LOGD("Using config section [", name, "] for ", nonull(device->name));
return section;
}
}
}
}
}

std::string name = nonull(device->name);
name = "input-device:" + name;
auto& config = wf::get_core().config;
if (!config.get_section(name))
LOGD("Checking for config section [", name, "]");
section = config.get_section(name);
if (section)
{
config.merge_section(
config.get_section("input-device")->clone_with_name(name));
LOGD("Using config section [", name, "]");
return section;
}

config.merge_section(
config.get_section("input-device")->clone_with_name(name));

return config.get_section(name);
}

Expand Down
3 changes: 2 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ wayfire_sources = ['geometry.cpp',

wayfire_dependencies = [wayland_server, wlroots, xkbcommon, libinput,
pixman, drm, egl, glesv2, glm, wf_protos, libdl,
wfconfig, libinotify, backtrace, wfutils, xcb, wftouch, json]
wfconfig, libinotify, backtrace, wfutils, xcb,
wftouch, json, udev]

if conf_data.get('BUILD_WITH_IMAGEIO')
wayfire_dependencies += [jpeg, png]
Expand Down