1
0
forked from drath/libratbag

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>
This commit is contained in:
Peter Hutterer
2016-03-11 15:18:08 +10:00
parent 578142964d
commit 4054616190
10 changed files with 303 additions and 122 deletions

View File

@@ -174,18 +174,20 @@ static const char *strip_ev_key(int key)
char *
button_action_macro_to_str(struct ratbag_button *button)
{
struct ratbag_button_macro *macro;
char str[4096] = {0};
const char *name;
int offset;
unsigned int i;
name = ratbag_button_get_macro_name(button);
macro = ratbag_button_get_macro(button);
name = ratbag_button_macro_get_name(macro);
offset = snprintf(str, sizeof(str), "macro \"%s\":",
name ? name : "UNKNOWN");
for (i = 0; i < MAX_MACRO_EVENTS; i++) {
enum ratbag_macro_event_type type = ratbag_button_get_macro_event_type(button, i);
int key = ratbag_button_get_macro_event_key(button, i);
int timeout = ratbag_button_get_macro_event_timeout(button, i);
enum ratbag_macro_event_type type = ratbag_button_macro_get_event_type(macro, i);
int key = ratbag_button_macro_get_event_key(macro, i);
int timeout = ratbag_button_macro_get_event_timeout(macro, i);
if (type == RATBAG_MACRO_EVENT_NONE)
break;
@@ -205,6 +207,8 @@ button_action_macro_to_str(struct ratbag_button *button)
}
}
ratbag_button_macro_unref(macro);
return strdup_safe(str);
}