libratbag.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2015 Red Hat, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef LIBRATBAG_H
25 #define LIBRATBAG_H
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #include <stdlib.h>
32 #include <stdarg.h>
33 #include <libudev.h>
34 
35 #define LIBRATBAG_ATTRIBUTE_PRINTF(_format, _args) \
36  __attribute__ ((format (printf, _format, _args)))
37 #define LIBRATBAG_ATTRIBUTE_DEPRECATED __attribute__ ((deprecated))
38 
83 struct ratbag;
84 
93 
104 
115 
126 struct ratbag_resolution;
127 
128 
143 };
144 
159 typedef void (*ratbag_log_handler)(struct ratbag *ratbag,
160  enum ratbag_log_priority priority,
161  const char *format, va_list args)
163 
179 void
180 ratbag_log_set_priority(struct ratbag *ratbag,
181  enum ratbag_log_priority priority);
182 
198 ratbag_log_get_priority(const struct ratbag *ratbag);
199 
215 void
216 ratbag_log_set_handler(struct ratbag *ratbag,
217  ratbag_log_handler log_handler);
218 
219 
242  int (*open_restricted)(const char *path, int flags, void *user_data);
250  void (*close_restricted)(int fd, void *user_data);
251 };
252 
263 struct ratbag *
264 ratbag_create_context(const struct ratbag_interface *interface,
265  void *userdata);
266 
280 void
281 ratbag_set_user_data(struct ratbag *ratbag, void *userdata);
282 
292 void*
293 ratbag_get_user_data(const struct ratbag *ratbag);
294 
304 struct ratbag *
305 ratbag_ref(struct ratbag *ratbag);
306 
317 struct ratbag *
318 ratbag_unref(struct ratbag *ratbag);
319 
331 struct ratbag_device*
332 ratbag_device_new_from_udev_device(struct ratbag *ratbag,
333  struct udev_device *device);
334 
344 struct ratbag_device *
345 ratbag_device_ref(struct ratbag_device *device);
346 
357 struct ratbag_device *
358 ratbag_device_unref(struct ratbag_device *device);
359 
371 void
372 ratbag_device_set_user_data(struct ratbag_device *device, void *userdata);
373 
383 void*
384 ratbag_device_get_user_data(const struct ratbag_device *device);
385 
392 const char *
393 ratbag_device_get_name(const struct ratbag_device* device);
394 
402 const char *
403 ratbag_device_get_svg_name(const struct ratbag_device* device);
404 
427 
433 
438 
446 };
447 
460 int
461 ratbag_device_has_capability(const struct ratbag_device *device,
462  enum ratbag_device_capability cap);
463 
479 unsigned int
481 
490 unsigned int
492 
502 struct ratbag_profile *
503 ratbag_profile_ref(struct ratbag_profile *profile);
504 
515 struct ratbag_profile *
516 ratbag_profile_unref(struct ratbag_profile *profile);
517 
529 void
530 ratbag_profile_set_user_data(struct ratbag_profile *profile, void *userdata);
531 
541 void*
542 ratbag_profile_get_user_data(const struct ratbag_profile *profile);
543 
562 struct ratbag_profile *
563 ratbag_device_get_profile(struct ratbag_device *device, unsigned int index);
564 
576 int
578 
588 int
590 
606 int
608 
631 struct ratbag_resolution *
632 ratbag_profile_get_resolution(struct ratbag_profile *profile, unsigned int idx);
633 
643 struct ratbag_resolution *
644 ratbag_resolution_ref(struct ratbag_resolution *resolution);
645 
656 struct ratbag_resolution *
657 ratbag_resolution_unref(struct ratbag_resolution *resolution);
658 
670 void
671 ratbag_resolution_set_user_data(struct ratbag_resolution *resolution, void *userdata);
672 
682 void*
683 ratbag_resolution_get_user_data(const struct ratbag_resolution *resolution);
684 
692 
697 };
698 
706 int
709 
728 int
730  unsigned int dpi);
731 
754 int
756  unsigned int x, unsigned int y);
757 
772 int
773 ratbag_resolution_get_dpi(struct ratbag_resolution *resolution);
774 
789 int
791 
806 int
808 
824 int
826  unsigned int hz);
827 
844 int
846 
860 int
862 
876 int
877 ratbag_resolution_is_active(const struct ratbag_resolution *resolution);
878 
894 int
896 
911 int
912 ratbag_resolution_is_default(const struct ratbag_resolution *resolution);
913 
932 struct ratbag_button*
933 ratbag_profile_get_button(struct ratbag_profile *profile, unsigned int index);
934 
946 void
947 ratbag_button_set_user_data(struct ratbag_button *button, void *userdata);
948 
958 void*
959 ratbag_button_get_user_data(const struct ratbag_button *button);
960 
968 
969  /* mouse buttons */
990 
991  /* DPI switch */
995 
996  /* Profile */
1000 };
1001 
1018 enum ratbag_button_type
1019 ratbag_button_get_type(struct ratbag_button *button);
1020 
1052 };
1053 
1061 
1079 int
1081  enum ratbag_button_action_type action_type);
1082 
1092 
1094 
1095  /* Wheel mappings */
1101 
1102  /* DPI switch */
1108 
1109  /* Profile */
1113 
1114  /* second mode for buttons */
1116 
1117  /* battery level */
1119 
1120 };
1121 
1141 unsigned int
1142 ratbag_button_get_button(struct ratbag_button *button);
1143 
1156 int
1158  unsigned int btn);
1159 
1175 
1188 int
1190  enum ratbag_button_action_special action);
1191 
1212 unsigned int
1213 ratbag_button_get_key(struct ratbag_button *button,
1214  unsigned int *modifiers,
1215  size_t *sz);
1216 
1232 int
1233 ratbag_button_set_key(struct ratbag_button *button,
1234  unsigned int key,
1235  unsigned int *modifiers,
1236  size_t sz);
1237 
1246 int
1247 ratbag_button_disable(struct ratbag_button *button);
1248 
1260 };
1261 
1275 const char *
1277 
1294 ratbag_button_get_macro_event_type(struct ratbag_button *button, unsigned int index);
1295 
1314 int
1315 ratbag_button_get_macro_event_key(struct ratbag_button *button, unsigned int index);
1316 
1333 int
1334 ratbag_button_get_macro_event_timeout(struct ratbag_button *button, unsigned int index);
1335 
1342 int
1343 ratbag_button_set_macro(struct ratbag_button *button, const char *name);
1344 
1345 int
1347 
1354 int
1356  unsigned int index,
1357  enum ratbag_macro_event_type type,
1358  unsigned int data);
1359 
1369 struct ratbag_button *
1370 ratbag_button_ref(struct ratbag_button *button);
1371 
1382 struct ratbag_button *
1383 ratbag_button_unref(struct ratbag_button *button);
1384 
1385 #ifdef __cplusplus
1386 }
1387 #endif
1388 #endif /* LIBRATBAG_H */
Definition: libratbag.h:976
struct ratbag_device * ratbag_device_ref(struct ratbag_device *device)
Add a reference to the device.
ratbag_macro_event_type
Macro event types describing the event.
Definition: libratbag.h:1254
int ratbag_button_set_key(struct ratbag_button *button, unsigned int key, unsigned int *modifiers, size_t sz)
A button to toggle the wheel from free-spinning to click-based.
Definition: libratbag.h:985
enum ratbag_button_action_type ratbag_button_get_action_type(struct ratbag_button *button)
int ratbag_button_set_macro_event(struct ratbag_button *button, unsigned int index, enum ratbag_macro_event_type type, unsigned int data)
Sets the macro&#39;s event at the given index to the given type with the key code or timeout given...
struct ratbag_profile * ratbag_profile_ref(struct ratbag_profile *profile)
Add a reference to the profile.
int ratbag_resolution_get_dpi(struct ratbag_resolution *resolution)
Get the resolution in DPI for the resolution mode.
int ratbag_resolution_set_default(struct ratbag_resolution *resolution)
Set the default resolution mode for the associated profile.
Definition: libratbag.h:971
int ratbag_device_has_capability(const struct ratbag_device *device, enum ratbag_device_capability cap)
Note that a device may not support any of the capabilities but still initialize fine otherwise...
Definition: libratbag.h:987
Definition: libratbag.h:1115
ratbag_resolution_capability
Definition: libratbag.h:685
This button is not set up for a special action.
Definition: libratbag.h:1090
int ratbag_resolution_is_active(const struct ratbag_resolution *resolution)
Check if the resolution mode is the currently active one.
Definition: libratbag.h:1259
int ratbag_resolution_get_dpi_x(struct ratbag_resolution *resolution)
Get the x resolution in DPI for the resolution mode.
int ratbag_resolution_set_dpi_xy(struct ratbag_resolution *resolution, unsigned int x, unsigned int y)
Set the x and y resolution in DPI for the resolution mode.
enum ratbag_button_type ratbag_button_get_type(struct ratbag_button *button)
Return the type of the physical button.
int ratbag_button_has_action_type(struct ratbag_button *button, enum ratbag_button_action_type action_type)
Check if a button supports a specific action type.
unsigned int ratbag_button_get_button(struct ratbag_button *button)
If a button&#39;s action is RATBAG_BUTTON_ACTION_TYPE_BUTTON, this function returns the logical button nu...
enum ratbag_log_priority ratbag_log_get_priority(const struct ratbag *ratbag)
Get the context&#39;s log priority.
Raw protocol messages.
Definition: libratbag.h:139
Definition: libratbag.h:979
int ratbag_button_disable(struct ratbag_button *button)
The device supports user-defined key or button sequences.
Definition: libratbag.h:437
The device can switch between hardware profiles.
Definition: libratbag.h:426
Definition: libratbag.h:1097
Definition: libratbag.h:978
The resolution can be set for x and y separately.
Definition: libratbag.h:696
int ratbag_resolution_get_report_rate(struct ratbag_resolution *resolution)
Get the the report rate in Hz for the resolution mode.
int ratbag_button_set_macro(struct ratbag_button *button, const char *name)
Sets the button&#39;s action to RATBAG_BUTTON_ACTION_TYPE_MACRO and allocates the required memory to stor...
Definition: libratbag.h:1255
The device can change resolution, either software-controlled or by a hardware button.
Definition: libratbag.h:418
struct ratbag_resolution * ratbag_profile_get_resolution(struct ratbag_profile *profile, unsigned int idx)
Return the resolution in DPI and the report rate in Hz for the resolution mode identified by the give...
Button action is unknown.
Definition: libratbag.h:1030
Definition: libratbag.h:1098
int ratbag_profile_is_active(struct ratbag_profile *profile)
Check if the given profile is the currently active one.
void ratbag_profile_set_user_data(struct ratbag_profile *profile, void *userdata)
Set caller-specific data associated with this profile.
ratbag_device_capability
Definition: libratbag.h:408
Definition: libratbag.h:975
const char * ratbag_device_get_svg_name(const struct ratbag_device *device)
int ratbag_profile_get_num_resolutions(struct ratbag_profile *profile)
Get the number of ratbag_resolution available in this profile.
const char * ratbag_button_get_macro_name(struct ratbag_button *button)
If a button&#39;s action is RATBAG_BUTTON_ACTION_TYPE_MACRO, this function returns the macro name...
void * ratbag_profile_get_user_data(const struct ratbag_profile *profile)
Get the caller-specific data associated with this profile, if any.
Represents a resolution setting on the device.
Definition: libratbag.h:114
Definition: libratbag.h:141
Definition: libratbag.h:986
ratbag_button_action_special
Definition: libratbag.h:1086
struct ratbag_button * ratbag_button_unref(struct ratbag_button *button)
Dereference the ratbag button.
struct ratbag_profile * ratbag_device_get_profile(struct ratbag_device *device, unsigned int index)
This function creates if necessary and returns a profile for the given index.
int ratbag_button_get_macro_event_key(struct ratbag_button *button, unsigned int index)
If a button&#39;s action is RATBAG_BUTTON_ACTION_TYPE_MACRO, and if the event stored at the given index i...
int ratbag_profile_set_active(struct ratbag_profile *profile)
Make the given profile the currently active profile.
struct ratbag_resolution * ratbag_resolution_ref(struct ratbag_resolution *resolution)
Add a reference to the resolution.
Definition: libratbag.h:993
Definition: libratbag.h:998
void ratbag_resolution_set_user_data(struct ratbag_resolution *resolution, void *userdata)
Set caller-specific data associated with this resolution.
Definition: libratbag.h:142
void ratbag_device_set_user_data(struct ratbag_device *device, void *userdata)
Set caller-specific data associated with this device.
unsigned int ratbag_button_get_key(struct ratbag_button *button, unsigned int *modifiers, size_t *sz)
If a button&#39;s action is RATBAG_BUTTON_ACTION_TYPE_KEY, this function returns the key or button config...
void * ratbag_device_get_user_data(const struct ratbag_device *device)
Get the caller-specific data associated with this device, if any.
enum ratbag_button_action_special ratbag_button_get_special(struct ratbag_button *button)
If a button&#39;s action is RATBAG_BUTTON_ACTION_TYPE_SPECIAL, this function returns the special function...
void(* close_restricted)(int fd, void *user_data)
Close the file descriptor.
Definition: libratbag.h:250
void ratbag_log_set_handler(struct ratbag *ratbag, ratbag_log_handler log_handler)
Set the context&#39;s log handler.
ratbag_log_priority
Log priority for internal logging messages.
Definition: libratbag.h:134
struct ratbag_button * ratbag_button_ref(struct ratbag_button *button)
Add a reference to the button.
struct ratbag_device * ratbag_device_new_from_udev_device(struct ratbag *ratbag, struct udev_device *device)
Create a new ratbag context from the given udev device.
The report rate can be set per resolution mode.
Definition: libratbag.h:691
Definition: libratbag.h:977
int ratbag_button_set_button(struct ratbag_button *button, unsigned int btn)
See ratbag_button_get_button() for a description of the button number.
Definition: libratbag.h:1256
unsigned int ratbag_device_get_num_profiles(struct ratbag_device *device)
Return the number of profiles supported by this device.
Definition: libratbag.h:1099
struct ratbag * ratbag_create_context(const struct ratbag_interface *interface, void *userdata)
Create a new ratbag context.
Button sends a key or key + modifier combination.
Definition: libratbag.h:1047
void ratbag_set_user_data(struct ratbag *ratbag, void *userdata)
Set caller-specific data associated with this context.
struct ratbag_resolution * ratbag_resolution_unref(struct ratbag_resolution *resolution)
Dereference the ratbag resolution.
Button is disabled.
Definition: libratbag.h:1034
Definition: libratbag.h:1093
Definition: libratbag.h:994
The device can have one profile assigned as a default profile.
Definition: libratbag.h:445
void(*) voi ratbag_log_set_priority)(struct ratbag *ratbag, enum ratbag_log_priority priority)
Set the log priority for the ratbag context.
Definition: libratbag.h:180
int ratbag_button_write_macro(struct ratbag_button *button)
A handle to a profile context on devices with the RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE capability...
Definition: libratbag.h:92
int ratbag_resolution_has_capability(struct ratbag_resolution *resolution, enum ratbag_resolution_capability cap)
Check if a resolution has a specific capability.
Definition: libratbag.h:973
Definition: libratbag.h:972
libratbag does not open file descriptors to devices directly, instead open_restricted() and close_res...
Definition: libratbag.h:230
void ratbag_button_set_user_data(struct ratbag_button *button, void *userdata)
Set caller-specific data associated with this button.
void * ratbag_resolution_get_user_data(const struct ratbag_resolution *resolution)
Get the caller-specific data associated with this resolution, if any.
Definition: libratbag.h:974
Button triggers a mouse-specific special function.
Definition: libratbag.h:1043
Definition: libratbag.h:992
struct ratbag_device * ratbag_device_unref(struct ratbag_device *device)
Dereference the ratbag device.
The device supports assigning button numbers, key events or key + modifier combinations.
Definition: libratbag.h:432
int ratbag_resolution_is_default(const struct ratbag_resolution *resolution)
Check if the resolution mode is the default one in this profile.
Definition: libratbag.h:409
Definition: libratbag.h:1096
ratbag_button_action_type
The type assigned to a button.
Definition: libratbag.h:1026
Definition: libratbag.h:980
int(* open_restricted)(const char *path, int flags, void *user_data)
Open the device at the given path with the flags provided and return the fd.
Definition: libratbag.h:242
enum ratbag_macro_event_type ratbag_button_get_macro_event_type(struct ratbag_button *button, unsigned int index)
If a button&#39;s action is RATBAG_BUTTON_ACTION_TYPE_MACRO, this function returns the macro event type c...
Definition: libratbag.h:981
void * ratbag_button_get_user_data(const struct ratbag_button *button)
Get the caller-specific data associated with this button, if any.
int ratbag_button_set_special(struct ratbag_button *button, enum ratbag_button_action_special action)
This function sets the special function assigned to this button.
Definition: libratbag.h:989
Definition: libratbag.h:1112
struct ratbag * ratbag_unref(struct ratbag *ratbag)
Dereference the ratbag context.
Definition: libratbag.h:1257
Definition: libratbag.h:967
Definition: libratbag.h:1104
const char * ratbag_device_get_name(const struct ratbag_device *device)
int ratbag_resolution_set_active(struct ratbag_resolution *resolution)
Activate the given resolution mode.
struct ratbag_button * ratbag_profile_get_button(struct ratbag_profile *profile, unsigned int index)
Return a reference to the button given by the index.
#define LIBRATBAG_ATTRIBUTE_PRINTF(_format, _args)
Definition: libratbag.h:35
A ratbag context represents one single device.
Definition: libratbag.h:83
Definition: libratbag.h:999
Definition: libratbag.h:1258
unsigned int ratbag_device_get_num_buttons(struct ratbag_device *device)
Return the number of buttons available on this device.
int ratbag_resolution_get_dpi_y(struct ratbag_resolution *resolution)
Get the y resolution in DPI for the resolution mode.
int ratbag_button_get_macro_event_timeout(struct ratbag_button *button, unsigned int index)
If a button&#39;s action is RATBAG_BUTTON_ACTION_TYPE_MACRO, and if the event stored at the given index i...
Definition: libratbag.h:988
struct ratbag * ratbag_ref(struct ratbag *ratbag)
Add a reference to the context.
int ratbag_resolution_set_report_rate(struct ratbag_resolution *resolution, unsigned int hz)
Set the the report rate in Hz for the resolution mode.
struct ratbag_profile * ratbag_profile_unref(struct ratbag_profile *profile)
Dereference the ratbag profile.
int ratbag_resolution_set_dpi(struct ratbag_resolution *resolution, unsigned int dpi)
Set the resolution in DPI for the resolution mode.
Definition: libratbag.h:970
A handle for accessing ratbag contexts.
ratbag_button_type
Button types describing the physical button.
Definition: libratbag.h:966
Definition: libratbag.h:997
void * ratbag_get_user_data(const struct ratbag *ratbag)
Get the caller-specific data associated with this context, if any.
Definition: libratbag.h:1118
Button sends numeric button events.
Definition: libratbag.h:1038
Definition: libratbag.h:1111
Represents a button on the device.
Definition: libratbag.h:103
void(* ratbag_log_handler)(struct ratbag *ratbag, enum ratbag_log_priority priority, const char *format, va_list args) LIBRATBAG_ATTRIBUTE_PRINTF(3
Log handler type for custom logging.
Definition: libratbag.h:159
Button sends a user-defined key or button sequence.
Definition: libratbag.h:1051
Definition: libratbag.h:1091
Definition: libratbag.h:140