aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar iff <98851855+iffse@users.noreply.github.com>2023-09-07 03:31:35 +0200
committerLibravatar GitHub <noreply@github.com>2023-09-07 01:31:35 +0000
commit3dd2f4a67fb2ac45f336f075779cc3bccec2aac3 (patch)
treee2324b470f8a7de20dd12bd477ea6d5630e2f9f5
parentbuild: fix build with wayland-scanner subproject (diff)
downloadsway-3dd2f4a67fb2ac45f336f075779cc3bccec2aac3.tar.gz
sway-3dd2f4a67fb2ac45f336f075779cc3bccec2aac3.tar.zst
sway-3dd2f4a67fb2ac45f336f075779cc3bccec2aac3.zip
commands/input/map_from_region: don't treat 0x prefix as hex identifier
When using the `map_from_region` for pen tables, we will usually make the available area as big as possible while maintaining the proportions with the screen. As most of the tablets uses a 16:10 ratios while the most popular screen ratios is still 16:9, the argument for most people should be `0x0 1x0.9` to have the maximum effective area. However, the argument above won't work because the current code will treat `0x...` as a hexadecimal number, instead of setting both `x` and `y` to `0`. This fix allows the use of the following syntax: ``` input type:tablet_tool { map_from_region 0x0 1x0.9 } ```
-rw-r--r--sway/commands/input/map_from_region.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/sway/commands/input/map_from_region.c b/sway/commands/input/map_from_region.c
index de00b714..4400e111 100644
--- a/sway/commands/input/map_from_region.c
+++ b/sway/commands/input/map_from_region.c
@@ -11,11 +11,21 @@ static bool parse_coords(const char *str, double *x, double *y, bool *mm) {
11 *mm = false; 11 *mm = false;
12 12
13 char *end; 13 char *end;
14 *x = strtod(str, &end); 14
15 if (end[0] != 'x') { 15 // Check for "0x" prefix to avoid strtod treating the string as hex
16 return false; 16 if (str[0] == '0' && str[1] == 'x') {
17 if (strlen(str) < 3) {
18 return false;
19 }
20 *x = 0;
21 end = (char *)str + 2;
22 } else {
23 *x = strtod(str, &end);
24 if (end[0] != 'x') {
25 return false;
26 }
27 ++end;
17 } 28 }
18 ++end;
19 29
20 *y = strtod(end, &end); 30 *y = strtod(end, &end);
21 if (end[0] == 'm') { 31 if (end[0] == 'm') {