From 8edd0af80c4de940cdada9a741ff5476639e6a81 Mon Sep 17 00:00:00 2001 From: rockerBOO Date: Tue, 23 Sep 2025 01:14:38 -0400 Subject: [PATCH 1/4] Add map input to output to constrain tablet to a device. Add config.tablet_output_name for the monitor to attach to --- src/config/parse_config.h | 16 ++++++++++++++++ src/ext-protocol/tablet.h | 11 +++++++++++ src/mango.c | 11 +++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 71027b67..a9b4314b 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -262,6 +262,8 @@ typedef struct { char autostart[3][256]; + char *tablet_output_name; + ConfigTagRule *tag_rules; // 动态数组 int tag_rules_count; // 数量 @@ -1983,6 +1985,11 @@ void parse_config_line(Config *config, const char *line) { } else if (strncmp(key, "source", 6) == 0) { parse_config_file(config, value); + } else if (strcmp(key, "tablet_output") == 0) { + if (config->tablet_output_name) { + free(config->tablet_output_name); + } + config->tablet_output_name = strdup(value); } else { fprintf(stderr, "Error: Unknown key: %s\n", key); } @@ -2270,6 +2277,11 @@ void free_config(void) { config.cursor_theme = NULL; } + if (config.tablet_output_name) { + free(config.tablet_output_name); + config.tablet_output_name = NULL; + } + // 释放 circle_layout free_circle_layout(&config); @@ -2559,6 +2571,10 @@ void set_value_default() { config.shadows_position_y = shadows_position_y; config.focused_opacity = focused_opacity; config.unfocused_opacity = unfocused_opacity; + + /* tablet */ + config.tablet_output_name = strdup(""); + // memcpy(config.shadowscolor, shadowscolor, sizeof(shadowscolor)); memcpy(config.animation_curve_move, animation_curve_move, diff --git a/src/ext-protocol/tablet.h b/src/ext-protocol/tablet.h index 2e1f21eb..3e15c107 100644 --- a/src/ext-protocol/tablet.h +++ b/src/ext-protocol/tablet.h @@ -1,6 +1,7 @@ #include #include #include +#include static const int tabletmaptosurface = 0; /* map tablet input to surface(1) or monitor(0) */ @@ -32,6 +33,7 @@ static struct wl_listener tablet_tool_destroy = {.notify = destroytablettool}; static struct wl_listener tablet_tool_proximity = {.notify = tablettoolproximity}; static struct wl_listener tablet_tool_tip = {.notify = tablettooltip}; +static Monitor *find_monitor_by_name(const char *output_name); void createtablet(struct wlr_input_device *device) { if (!tablet) { @@ -47,6 +49,15 @@ void createtablet(struct wlr_input_device *device) { libinput_device_config_send_events_set_mode(device_handle, send_events_mode); wlr_cursor_attach_input_device(cursor, device); + // Map tablet to specific monitor if configured + if (config.tablet_output_name[0] != '\0') { + Monitor *target_monitor = find_monitor_by_name(config.tablet_output_name); + if (target_monitor) { + wlr_log(WLR_INFO, "Mapping input to output for device: %s", config.tablet_output_name); + wlr_cursor_map_input_to_output(cursor, device, + target_monitor->wlr_output); + } + } } } else if (device == tablet->wlr_device) { wlr_log(WLR_ERROR, "createtablet: duplicate device"); diff --git a/src/mango.c b/src/mango.c index db226a00..101d158a 100644 --- a/src/mango.c +++ b/src/mango.c @@ -5616,6 +5616,17 @@ static void setgeometrynotify(struct wl_listener *listener, void *data) { } #endif +static Monitor *find_monitor_by_name(const char *output_name) { + if (!output_name) return NULL; + Monitor *m; + wl_list_for_each(m, &mons, link) { + if (m->wlr_output && strcmp(m->wlr_output->name, output_name) == 0) { + return m; + } + } + return NULL; +} + int main(int argc, char *argv[]) { char *startup_cmd = NULL; int c; From f2ba08b262b86eaebec6482343baaae0df0c32c2 Mon Sep 17 00:00:00 2001 From: rockerBOO Date: Tue, 23 Sep 2025 02:28:40 -0400 Subject: [PATCH 2/4] Remove extra line --- src/config/parse_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/parse_config.h b/src/config/parse_config.h index a9b4314b..6f03ab0f 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -2572,9 +2572,9 @@ void set_value_default() { config.focused_opacity = focused_opacity; config.unfocused_opacity = unfocused_opacity; - /* tablet */ + /* Tablet */ config.tablet_output_name = strdup(""); - // + memcpy(config.shadowscolor, shadowscolor, sizeof(shadowscolor)); memcpy(config.animation_curve_move, animation_curve_move, From 6971b00e1b2eb9ff6834c1e689c26fb07cb52084 Mon Sep 17 00:00:00 2001 From: rockerBOO Date: Tue, 23 Sep 2025 02:31:49 -0400 Subject: [PATCH 3/4] Use NULL --- src/config/parse_config.h | 2 +- src/ext-protocol/tablet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 6f03ab0f..d82dfc30 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -2573,7 +2573,7 @@ void set_value_default() { config.unfocused_opacity = unfocused_opacity; /* Tablet */ - config.tablet_output_name = strdup(""); + config.tablet_output_name = NULL; memcpy(config.shadowscolor, shadowscolor, sizeof(shadowscolor)); diff --git a/src/ext-protocol/tablet.h b/src/ext-protocol/tablet.h index 3e15c107..39cf011a 100644 --- a/src/ext-protocol/tablet.h +++ b/src/ext-protocol/tablet.h @@ -50,7 +50,7 @@ void createtablet(struct wlr_input_device *device) { send_events_mode); wlr_cursor_attach_input_device(cursor, device); // Map tablet to specific monitor if configured - if (config.tablet_output_name[0] != '\0') { + if (config.tablet_output_name) { Monitor *target_monitor = find_monitor_by_name(config.tablet_output_name); if (target_monitor) { wlr_log(WLR_INFO, "Mapping input to output for device: %s", config.tablet_output_name); From 500aa97f3c7c8e13950e0e316d09e27ba7ccef69 Mon Sep 17 00:00:00 2001 From: rockerBOO Date: Wed, 24 Sep 2025 23:31:38 -0400 Subject: [PATCH 4/4] Fix tablet_output_name key for config --- src/config/parse_config.h | 2 +- src/ext-protocol/tablet.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/config/parse_config.h b/src/config/parse_config.h index d82dfc30..0dec1487 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -1985,7 +1985,7 @@ void parse_config_line(Config *config, const char *line) { } else if (strncmp(key, "source", 6) == 0) { parse_config_file(config, value); - } else if (strcmp(key, "tablet_output") == 0) { + } else if (strcmp(key, "tablet_output_name") == 0) { if (config->tablet_output_name) { free(config->tablet_output_name); } diff --git a/src/ext-protocol/tablet.h b/src/ext-protocol/tablet.h index 39cf011a..34878ef7 100644 --- a/src/ext-protocol/tablet.h +++ b/src/ext-protocol/tablet.h @@ -56,6 +56,8 @@ void createtablet(struct wlr_input_device *device) { wlr_log(WLR_INFO, "Mapping input to output for device: %s", config.tablet_output_name); wlr_cursor_map_input_to_output(cursor, device, target_monitor->wlr_output); + } else { + wlr_log(WLR_WARN, "No monitor found with name: %s", config.tablet_output_name); } } }