From 23ecc3256276642ec2641e9e2c731f763b62d0dd Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Fri, 29 Dec 2023 22:36:06 +0100 Subject: [PATCH] config: add tablet rotate configuration Co-authored-by: Consolatis <35009135+Consolatis@users.noreply.github.com> --- docs/rc.xml.all | 10 ++++++---- include/config/rcxml.h | 1 + include/config/tablet.h | 8 ++++++++ src/config/rcxml.c | 2 ++ src/config/tablet.c | 18 ++++++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/docs/rc.xml.all b/docs/rc.xml.all index bbf61189..ddd9236a 100644 --- a/docs/rc.xml.all +++ b/docs/rc.xml.all @@ -394,12 +394,14 @@ - + diff --git a/include/config/rcxml.h b/include/config/rcxml.h index ead62c78..acb34260 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -83,6 +83,7 @@ struct rcxml { /* graphics tablet */ struct tablet_config { + enum rotation rotation; uint16_t button_map_count; struct button_map_entry button_map[BUTTON_MAP_MAX]; } tablet; diff --git a/include/config/tablet.h b/include/config/tablet.h index 25a232c3..c5b90b93 100644 --- a/include/config/tablet.h +++ b/include/config/tablet.h @@ -4,12 +4,20 @@ #include +enum rotation { + LAB_ROTATE_NONE = 0, + LAB_ROTATE_90, + LAB_ROTATE_180, + LAB_ROTATE_270, +}; + #define BUTTON_MAP_MAX 16 struct button_map_entry { uint32_t from; uint32_t to; }; +enum rotation tablet_parse_rotation(int value); uint32_t tablet_button_from_str(const char *button); uint32_t mouse_button_from_str(const char *button); void tablet_button_mapping_add(uint32_t from, uint32_t to); diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 321a5197..4f3f5a54 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -826,6 +826,8 @@ entry(xmlNode *node, char *nodename, char *content) } else { wlr_log(WLR_ERROR, "Invalid value for "); } + } else if (!strcasecmp(nodename, "rotate.tablet")) { + rc.tablet.rotation = tablet_parse_rotation(atoi(content)); } else if (!strcasecmp(nodename, "button.map.tablet")) { button_map_from = tablet_button_from_str(content); } else if (!strcasecmp(nodename, "to.map.tablet")) { diff --git a/src/config/tablet.c b/src/config/tablet.c index 5d138af3..81460db1 100644 --- a/src/config/tablet.c +++ b/src/config/tablet.c @@ -7,6 +7,24 @@ #include "config/tablet.h" #include "config/rcxml.h" +enum rotation tablet_parse_rotation(int value) +{ + switch (value) { + case 0: + return LAB_ROTATE_NONE; + case 90: + return LAB_ROTATE_90; + case 180: + return LAB_ROTATE_180; + case 270: + return LAB_ROTATE_270; + default: + wlr_log(WLR_ERROR, "Invalid value for tablet rotation: %d", value); + break; + } + return LAB_ROTATE_NONE; +} + uint32_t tablet_button_from_str(const char *button) { if (!strcasecmp(button, "Tip")) {