]> git.mdlowis.com Git - proto/labwc.git/commitdiff
config: add tablet area configuration
authorJens Peters <jp7677@gmail.com>
Mon, 1 Jan 2024 17:26:38 +0000 (18:26 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Mon, 1 Jan 2024 22:11:33 +0000 (22:11 +0000)
docs/rc.xml.all
include/config/rcxml.h
include/config/tablet.h
src/config/rcxml.c
src/config/tablet.c

index 7e6d653065d770a736bbb12dcffd9b5ecd8fb492..9cc6dd0a18414986f7bd5aca68b5f10e30322711 100644 (file)
   </mouse>
 
   <!--
+    The active tablet area can be specified by setting the top/left
+    coordinate (in mm) and/or width/height (in mm). If width or height
+    are omitted or default (0.0), width/height will be set to the
+    remaining width/height seen from top/left.
+
     The tablet orientation can be changed in 90 degree steps, thus
-    rotation can be set to [0|90|180|270].
+    rotation can be set to [0|90|180|270]. Rotation will be applied
+    after applying tablet area transformation.
 
     Tablet buttons emulate regular mouse buttons. The tablet *button* can
     be set to any of [tip|stylus|stylus2|stylus3]. Valid *to* mouse buttons
     are [left|right|middle].
   -->
   <tablet rotate="0">
+    <!-- Active area dimensions are in mm -->
+    <area top="0.0" left="0.0" width="0.0" height="0.0">
     <map button="tip" to="left" />
     <map button="stylus" to="right" />
     <map button="stylus2" to="middle" />
index 2fa7463ac8bb7cccd62a957b8e6c63b89db3b5d0..d03e4a74c9aa34e908341b745723bfbeb77f6731 100644 (file)
@@ -89,6 +89,7 @@ struct rcxml {
 
        /* graphics tablet */
        struct tablet_config {
+               struct wlr_fbox box;
                enum rotation rotation;
                uint16_t button_map_count;
                struct button_map_entry button_map[BUTTON_MAP_MAX];
index c5b90b937335fe0ee105203351cebfc1870aaa80..0ba6a87be28df17d5974d2bfd2e9be0abc7ea5ff 100644 (file)
@@ -17,6 +17,7 @@ struct button_map_entry {
        uint32_t to;
 };
 
+double tablet_get_dbl_if_positive(const char *content, const char *name);
 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);
index c649ad8b1cde71ce313d9f14fa06c4eba0ec840d..54aacb9c75cec92fd72e3eb4c0ad44db06c6a9d1 100644 (file)
@@ -854,6 +854,14 @@ entry(xmlNode *node, char *nodename, char *content)
                } else {
                        wlr_log(WLR_ERROR, "Invalid value for <resize popupShow />");
                }
+       } else if (!strcasecmp(nodename, "left.area.tablet")) {
+               rc.tablet.box.x = tablet_get_dbl_if_positive(content, "left");
+       } else if (!strcasecmp(nodename, "top.area.tablet")) {
+               rc.tablet.box.y = tablet_get_dbl_if_positive(content, "top");
+       } else if (!strcasecmp(nodename, "width.area.tablet")) {
+               rc.tablet.box.width = tablet_get_dbl_if_positive(content, "width");
+       } else if (!strcasecmp(nodename, "height.area.tablet")) {
+               rc.tablet.box.height = tablet_get_dbl_if_positive(content, "height");
        } else if (!strcasecmp(nodename, "rotate.tablet")) {
                rc.tablet.rotation = tablet_parse_rotation(atoi(content));
        } else if (!strcasecmp(nodename, "button.map.tablet")) {
@@ -1027,7 +1035,7 @@ rcxml_init(void)
        rc.doubleclick_time = 500;
        rc.scroll_factor = 1.0;
 
-       rc.tablet.button_map_count = 0;
+       rc.tablet.box = (struct wlr_fbox){0};
        tablet_load_default_button_mappings();
 
        rc.repeat_rate = 25;
index 4c2c584692b69e0a201fb2f7ec3cf80cb14ad826..7c6ee2f1fae5191ee5d0125cd48bb34195fe1813 100644 (file)
@@ -7,6 +7,17 @@
 #include "config/tablet.h"
 #include "config/rcxml.h"
 
+double
+tablet_get_dbl_if_positive(const char *content, const char *name)
+{
+       double value = atof(content);
+       if (value < 0) {
+               wlr_log(WLR_ERROR, "Invalid value for tablet area %s", name);
+               return 0;
+       }
+       return value;
+}
+
 enum rotation
 tablet_parse_rotation(int value)
 {
@@ -84,6 +95,7 @@ tablet_button_mapping_add(uint32_t from, uint32_t to)
 void
 tablet_load_default_button_mappings(void)
 {
+       rc.tablet.button_map_count = 0;
        tablet_button_mapping_add(BTN_TOOL_PEN, BTN_LEFT); /* Used for the pen tip */
        tablet_button_mapping_add(BTN_STYLUS, BTN_RIGHT);
        tablet_button_mapping_add(BTN_STYLUS2, BTN_MIDDLE);