config: add tablet rotate configuration

Co-authored-by: Consolatis <35009135+Consolatis@users.noreply.github.com>
This commit is contained in:
Jens Peters 2023-12-29 22:36:06 +01:00 committed by Johan Malm
parent 20bba35570
commit 23ecc32562
5 changed files with 35 additions and 4 deletions

View file

@ -394,12 +394,14 @@
</mouse> </mouse>
<!-- <!--
Tablet buttons emulate regular mouse buttons. The tablet orientation can be changed in 90 degree steps, thus
rotation can be set to [0|90|180|270].
The tablet *button* can be set to any of [tip|stylus|stylus2|stylus3]. Tablet buttons emulate regular mouse buttons. The tablet *button* can
Valid *to* mouse buttons are [left|right|middle]. be set to any of [tip|stylus|stylus2|stylus3]. Valid *to* mouse buttons
are [left|right|middle].
--> -->
<tablet> <tablet rotate="0">
<map button="tip" to="left" /> <map button="tip" to="left" />
<map button="stylus" to="right" /> <map button="stylus" to="right" />
<map button="stylus2" to="middle" /> <map button="stylus2" to="middle" />

View file

@ -83,6 +83,7 @@ struct rcxml {
/* graphics tablet */ /* graphics tablet */
struct tablet_config { struct tablet_config {
enum rotation rotation;
uint16_t button_map_count; uint16_t button_map_count;
struct button_map_entry button_map[BUTTON_MAP_MAX]; struct button_map_entry button_map[BUTTON_MAP_MAX];
} tablet; } tablet;

View file

@ -4,12 +4,20 @@
#include <stdint.h> #include <stdint.h>
enum rotation {
LAB_ROTATE_NONE = 0,
LAB_ROTATE_90,
LAB_ROTATE_180,
LAB_ROTATE_270,
};
#define BUTTON_MAP_MAX 16 #define BUTTON_MAP_MAX 16
struct button_map_entry { struct button_map_entry {
uint32_t from; uint32_t from;
uint32_t to; uint32_t to;
}; };
enum rotation tablet_parse_rotation(int value);
uint32_t tablet_button_from_str(const char *button); uint32_t tablet_button_from_str(const char *button);
uint32_t mouse_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); void tablet_button_mapping_add(uint32_t from, uint32_t to);

View file

@ -826,6 +826,8 @@ entry(xmlNode *node, char *nodename, char *content)
} else { } else {
wlr_log(WLR_ERROR, "Invalid value for <resize popupShow />"); wlr_log(WLR_ERROR, "Invalid value for <resize popupShow />");
} }
} else if (!strcasecmp(nodename, "rotate.tablet")) {
rc.tablet.rotation = tablet_parse_rotation(atoi(content));
} else if (!strcasecmp(nodename, "button.map.tablet")) { } else if (!strcasecmp(nodename, "button.map.tablet")) {
button_map_from = tablet_button_from_str(content); button_map_from = tablet_button_from_str(content);
} else if (!strcasecmp(nodename, "to.map.tablet")) { } else if (!strcasecmp(nodename, "to.map.tablet")) {

View file

@ -7,6 +7,24 @@
#include "config/tablet.h" #include "config/tablet.h"
#include "config/rcxml.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) uint32_t tablet_button_from_str(const char *button)
{ {
if (!strcasecmp(button, "Tip")) { if (!strcasecmp(button, "Tip")) {