Commit Graph

30 Commits

Author SHA1 Message Date
Yaroslav Chvanov
85cab665b5 tools: remove helpers for the deprecated ratbag_button_type 2023-02-25 13:03:37 +03:00
Yaroslav Chvanov
b275204c87 tools: check snprintf size argument to prevent potential overflow 2023-02-25 00:22:07 +03:00
Filipe Laíns
0d3b4f1b64 libratbag: add 'switches' led type
Signed-off-by: Filipe Laíns <lains@archlinux.org>
2019-12-19 12:06:15 +00:00
Peter Hutterer
17d8bcacf6 Switch to using hidraw as base event source
We started with event nodes for some reason lost in the distant past (probably
because that's what a lot of other tools use). But since we exclusively deal
with hidraw devices here and event nodes only serve to look up the hidraw
node, let's get rid of that indirection layer and work with hidraw directly.

Note that changes how ratbagctl works, it used the event nodes before. So
anyone who hardcoded the event node in one way or another is going to see
breakage. Then again, the "eventX" string was the device ID as advertised by
ratbagd, so it's supposed to be treated as an opaque string anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-02-21 10:23:08 +01:00
maxice8
208bb15149 tools/shared.c: Use portable realpath() instead of (#606)
canonicalize_file_name()

Fixes compilation on musl systems
2019-01-24 14:26:05 +01:00
Justin Gottula
44d36d2bf0 tools: canonicalize path first in udev_device_from_path (#592)
* tools: canonicalize path first in udev_device_from_path

This fixes a problem in which running ratbag-command with the path to a
device node symlink (e.g. /dev/logi-g502 -> /dev/input/event4), such as
one created by a udev rule, would not work correctly, due to the code
failing to resolve the symlink prior to checking for the presence of the
"/dev/input/event" prefix.

This resulted in nonsensical error messages (shown below) and the
curious inability to run ratbag-command successfully with anything but
the actual raw path to the device node itself (e.g. /dev/input/event4
would work fine, but /dev/logi-g502 would not, despite both being valid
ways of getting to the same device node).

    Error: Can't open '/dev/logi-g502': Success
    Error: Device '/dev/logi-g502' is not supported

Note that this same problem also prevented the usage of autogenerated
symlinks by udev, i.e. '/dev/input/by-id/' and '/dev/input/by-path/'.

* Update tools/shared.c

Co-Authored-By: jgottula <justin@jgottula.com>
2018-12-24 19:04:04 +01:00
Thomas Hindoe Paaboel Andersen
790c5e90bd add RATBAG_LED_TYPE_SCROLL_WHEEL 2017-10-18 00:19:12 +02:00
Peter Hutterer
186d626c40 Remove RATBAG_LED_TYPE_UNKNOWN from the enum list
A driver is supposed to know what type an LED is, unknown doesn't help anyone
here. So replace this with a private #define and abort when a driver doesn't
set the type. This also adds a requirement that any driver initializing a LED
must have the read_led() function, otherwise we can't fill it in correctly.

And bump the enum up by one, the first valid value should start at 1 (or some
other non-boolean value).

Related #365
Fixes #364

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-10-09 19:12:17 +02:00
Ogier Bouvier
8edf6e7609 tools: use new RATBAG_LED_TYPEs
Signed-off-by: Ogier Bouvier <obouvier@logitech.com>
2017-10-03 19:48:32 +10:00
Peter Hutterer
9450d1402f Move the _cleanup_ functions over to shared-macro.h
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-19 10:09:01 +02:00
Christian Kellner
c05c3dcaa3 tools: consistently call led mode "breathing"
Rename "breath" in the help text and reporting for the led mode to
"breathing". The actual command to set the mode was already called
that way.

Signed-off-by: Christian Kellner <christian@kellner.me>
2017-05-24 09:05:15 +10:00
Peter Hutterer
7fdcf62bf2 tools: fix compiler warning
../tools/shared.c:132:1: warning: ‘static’ is not at beginning of declaration [-Wold-style-declaration]

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-03 09:55:53 +02:00
Ilya Guterman
8e5ad717c4 ratbag-command: implement LED commands 2017-03-07 11:07:50 +10:00
mxmgh
4d6390ea66 Teach ratbag-command the "ratchet mode switch" special action name 2017-02-13 08:10:45 +10:00
Clément Vuchener
c4013ca4b0 Add special actions for cycling down resolutions and profiles
Signed-off-by: Clément Vuchener <clement.vuchener@gmail.com>
2017-01-24 07:41:22 +10:00
Peter Hutterer
4054616190 Revamp the button macro code
The previous API was inconsistent and different to the rest of libratbag's
API. Replace with one where a macro is a separate struct, can be initialized
and then written to the device with a set_macro() call. The device copies the
contents, the macro is otherwise unmodified and can be re-used by the client
if need be.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-03-14 14:22:22 +10:00
Peter Hutterer
37bd43511b Switch to using an emum for error codes
Whenever we do something that may fail, return an enum of possible errors.

This also changes the API for ratbag_device_new_from_udev_device() to return
an error code now too instead of just NULL on failure.

Error numbers start at -1000 to avoid overlap with errnos, error_code() should
be used internally to avoid returning an errno.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-03-14 14:20:47 +10:00
Benjamin Tissoires
cb4c34337a hidpp10: implement parsing of special keys
Create new RATBAG_BUTTON_ACTION_SPECIAL_BATTERY_LEVEL.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-11-26 17:57:00 +01:00
Benjamin Tissoires
32e18e5cad tools: shared: keep only one instance of the mapping action/str
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-22 15:13:58 -04:00
Benjamin Tissoires
f85a700c27 tools: shared: fix reporting of RATBAG_BUTTON_ACTION_SPECIAL_SECOND_MODE
Setting the special command and displaying it were using a different
spelling. Fix that.

We should really only have one entry point for that.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-22 15:13:29 -04:00
Benjamin Tissoires
a2a1f296e6 Add 2 special keys found on the Logitech G502
RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_ALTERNATE (for the "sniper switch")
RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_DEFAULT -> means what it means

And fix one missing entry in str_to_special_action.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-20 15:25:01 -04:00
Peter Hutterer
31dc1f4772 Use _cleanup_ functions for udev/udev_device
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-10-13 08:33:55 +10:00
Peter Hutterer
5b8f3c4744 Add snprintf_safe() and sprintf_safe helpers
Blows up when sprintf encounters an error, the result string is empty or the
result string is truncated.

Note: sprintf_safe only works on static buffers, it uses ARRAY_LENGTH.

Fixes #14

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-10-13 07:01:09 +10:00
Peter Hutterer
1abc7cdb69 Add strdup_safe() as a reliable strdup function
Handles NULL and guarantees a successful strdup

Fixes #14

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-10-13 07:00:16 +10:00
Benjamin Tissoires
2bc5b1910a Add roccat implementation
This driver is basically a duplicate of the Etekcity.
After the copy-paste, I renamed all the the "etekcity"
by "roccat" and then rev-engineered the various constants.

Still a WIP, but it is getting usable.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-09-11 17:44:58 -04:00
Benjamin Tissoires
0429609634 tools: fix macro time conversion to str
Those breaks... I keep forgetting them

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-09-10 18:03:37 -04:00
Peter Hutterer
a4515a59ae tools: strncmp -> strneq
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-11 03:57:59 +10:00
Benjamin Tissoires
cdf710d807 add support for getting/setting the macro name
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-09-09 11:26:15 -04:00
Benjamin Tissoires
ce10bb1e84 macro: add first implementation
The doctext needs fixes and the API might not be final.
This however works and allow to read the macro.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-09-09 11:26:15 -04:00
Benjamin Tissoires
b9376bdc67 tools: split out some shared functions
Allows to reuse them in other tools

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2015-09-02 22:20:00 -04:00