mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
libratbag: refactor ratbag_action_macro_num_keys()
Also use a helper for checking modifiers, this will be handy for drivers.
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <linux/input-event-codes.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -364,3 +366,21 @@ get_unaligned_be_u32(const uint8_t *buf)
|
||||
{
|
||||
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
||||
}
|
||||
|
||||
static inline bool
|
||||
ratbag_key_is_modifier(const unsigned int key)
|
||||
{
|
||||
switch (key) {
|
||||
case KEY_LEFTALT:
|
||||
case KEY_LEFTCTRL:
|
||||
case KEY_LEFTMETA:
|
||||
case KEY_LEFTSHIFT:
|
||||
case KEY_RIGHTALT:
|
||||
case KEY_RIGHTCTRL:
|
||||
case KEY_RIGHTMETA:
|
||||
case KEY_RIGHTSHIFT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1952,31 +1952,21 @@ int
|
||||
ratbag_action_macro_num_keys(const struct ratbag_button_action *action)
|
||||
{
|
||||
const struct ratbag_macro *macro = action->macro;
|
||||
int i, count;
|
||||
|
||||
count = 0;
|
||||
for (i = 0; i < MAX_MACRO_EVENTS; i++) {
|
||||
struct ratbag_macro_event event;
|
||||
|
||||
event = macro->events[i];
|
||||
if (event.type == RATBAG_MACRO_EVENT_KEY_PRESSED)
|
||||
{
|
||||
switch(event.event.key) {
|
||||
case KEY_LEFTCTRL:
|
||||
case KEY_LEFTSHIFT:
|
||||
case KEY_LEFTALT:
|
||||
case KEY_LEFTMETA:
|
||||
case KEY_RIGHTCTRL:
|
||||
case KEY_RIGHTSHIFT:
|
||||
case KEY_RIGHTALT:
|
||||
case KEY_RIGHTMETA:
|
||||
break;
|
||||
default:
|
||||
count++;
|
||||
}
|
||||
int count = 0;
|
||||
for (int i = 0; i < MAX_MACRO_EVENTS; i++) {
|
||||
struct ratbag_macro_event event = macro->events[i];
|
||||
if (event.type == RATBAG_MACRO_EVENT_NONE ||
|
||||
event.type == RATBAG_MACRO_EVENT_INVALID) {
|
||||
break;
|
||||
}
|
||||
if (ratbag_key_is_modifier(event.event.key)) {
|
||||
continue;
|
||||
}
|
||||
if (event.type == RATBAG_MACRO_EVENT_KEY_PRESSED) {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user