ratbagd: add support for macros in the test device

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2017-07-25 14:57:21 +10:00
committed by Benjamin Tissoires
parent 4f62424e8a
commit 129551f3f4
3 changed files with 31 additions and 17 deletions

View File

@@ -206,7 +206,16 @@ static const struct ratbag_test_device ratbagd_test_device_descr = {
.key = KEY_3 },
{ .type = RATBAG_BUTTON_ACTION_TYPE_SPECIAL,
.special = RATBAG_BUTTON_ACTION_SPECIAL_PROFILE_CYCLE_UP },
{ .type = RATBAG_BUTTON_ACTION_TYPE_MACRO },
{ .type = RATBAG_BUTTON_ACTION_TYPE_MACRO,
.macro = {
{ .type = RATBAG_MACRO_EVENT_KEY_PRESSED,
.value = KEY_B },
{ .type = RATBAG_MACRO_EVENT_KEY_RELEASED,
.value = KEY_B },
{ .type = RATBAG_MACRO_EVENT_WAIT,
.value = 300 },
},
}
},
.resolutions = {
{ .xres = 100, .yres = 200, .hz = 1000 },
@@ -260,7 +269,15 @@ static const struct ratbag_test_device ratbagd_test_device_descr = {
{ .type = RATBAG_BUTTON_ACTION_TYPE_SPECIAL,
.special = RATBAG_BUTTON_ACTION_SPECIAL_PROFILE_CYCLE_UP },
{ .type = RATBAG_BUTTON_ACTION_TYPE_MACRO,
.button = 1 },
.macro = {
{ .type = RATBAG_MACRO_EVENT_KEY_PRESSED,
.value = KEY_A },
{ .type = RATBAG_MACRO_EVENT_KEY_RELEASED,
.value = KEY_A },
{ .type = RATBAG_MACRO_EVENT_WAIT,
.value = 150 },
}
},
{ .type = RATBAG_BUTTON_ACTION_TYPE_BUTTON,
.button = 2 },
{ .type = RATBAG_BUTTON_ACTION_TYPE_BUTTON,

View File

@@ -97,12 +97,12 @@ test_read_button(struct ratbag_button *button)
struct ratbag_device *device = button->profile->device;
struct ratbag_test_device *d = ratbag_get_drv_data(device);
struct ratbag_test_profile *p = &d->profiles[button->profile->index];
struct ratbag_test_button *b = &p->buttons[button->index];
struct ratbag_button_macro *m;
const char data[] = "TEST";
const char *c;
struct ratbag_test_macro_event *e;
int idx;
switch (p->buttons[button->index].type) {
switch (b->type) {
case RATBAG_BUTTON_ACTION_TYPE_BUTTON:
button->action.type = RATBAG_BUTTON_ACTION_TYPE_BUTTON;
button->action.action.button = p->buttons[button->index].button;
@@ -116,19 +116,10 @@ test_read_button(struct ratbag_button *button)
m = ratbag_button_macro_new("test macro");
idx = 0;
ARRAY_FOR_EACH(data, c) {
char str[6];
if (*c == '\0')
ARRAY_FOR_EACH(b->macro, e) {
if (e->type == RATBAG_MACRO_EVENT_NONE)
break;
snprintf_safe(str, 6, "KEY_%c", *c);
ratbag_button_macro_set_event(m,
idx++,
RATBAG_MACRO_EVENT_KEY_PRESSED,
libevdev_event_code_from_name(EV_KEY, str));
ratbag_button_macro_set_event(m,
idx++,
RATBAG_MACRO_EVENT_KEY_RELEASED,
libevdev_event_code_from_name(EV_KEY, str));
ratbag_button_macro_set_event(m, idx++, e->type, e->value);
}
ratbag_button_copy_macro(button, m);
ratbag_button_macro_unref(m);

View File

@@ -31,12 +31,18 @@
#define RATBAG_TEST_MAX_RESOLUTIONS 8
#define RATBAG_TEST_MAX_LEDS 8
struct ratbag_test_macro_event {
enum ratbag_macro_event_type type;
unsigned int value;
};
struct ratbag_test_button {
enum ratbag_button_action_type type;
union {
int button;
int key;
enum ratbag_button_action_special special;
struct ratbag_test_macro_event macro[24];
};
};