michaelforney / swc

a library for making a simple Wayland compositor
MIT License
614 stars 52 forks source link

Add support for configuring libinput devices from window manager #43

Closed ghost closed 7 years ago

ghost commented 7 years ago

Adds another optional callback to swc_manager, which is called when libinput detects new device. It's purpose is to be able to setup input devices from window manager.

Example: part of code from window manager which will set accel speed of touchpad

#include <libinput.h>

...

static void
new_device(struct libinput_device *device)
{
    const char *dev_name = libinput_device_get_name(device);

    if (strcmp("AlpsPS/2 ALPS DualPoint TouchPad", dev_name) == 0) {
        libinput_device_config_accel_set_speed(device, 0.7);
    }
}

...

const struct swc_manager manager = {
    ...
    .new_device = &new_device
};
DmitryHetman commented 7 years ago

Why this should be implemented in widow mangager? You can't add/remove touchpad on the fly.

ghost commented 7 years ago

It's purpose is to be able to setup input devices from window manager.

"New" devices are also detected when you start your wm, they're set up on startup. And libinput handles all input devices except keyboards (on my computer it detects power switch, rf kill switch, etc.).

BTW of course you can add/remove touchpad(s) on the fly, as well as mice and other peripherals.

michaelforney commented 7 years ago

I squashed the two commits and moved the forward struct declaration to within the extern "C". Thanks!