Skip to content

Commit 9072b9b

Browse files
committed
feat: touch map to monitor
1 parent 5abc281 commit 9072b9b

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

docs/configuration/input.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ emulation so the touchscreen keeps working with non-touch clients.
8383
| :--- | :--- | :--- |
8484
| `touch_enable` | `1` | Set to `0` to completely disable touchscreen support. |
8585
| `touch_enable_mouse_emulation` | `0` | When `1`, touch events landing on surfaces that do not accept touch are emulated as left mouse button clicks/moves. Set to `0` to disable emulation (such touches are ignored). |
86+
| `touch_map_to_mon` | *(unset)* | Restrict a touchscreen to one output. Accepts a [monitor spec](/docs/configuration/monitors#monitor-spec-format). Leave unset to map the touchscreen to the whole output layout. Useful on multi-monitor setups where the touchscreen would otherwise be stretched across all outputs. |
8687

8788
---
8889

src/common/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#define _GNU_SOURCE
22
#include "log.h"
3+
#include "util.h"
34
#include <stdarg.h>
45
#include <stdio.h>
56
#include <stdlib.h>
6-
#include "util.h"
77

88
void mango_log_init(enum wlr_log_importance verbosity,
99
wlr_log_func_t callback) {

src/config/parse_config.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ typedef struct {
353353
/* touch */
354354
int32_t touch_enable;
355355
int32_t touch_enable_mouse_emulation;
356+
char *touch_map_to_mon;
356357

357358
/* window effects */
358359
int32_t blur;
@@ -1924,6 +1925,10 @@ bool parse_option(Config *config, char *key, char *value, int line_number) {
19241925
config->touch_enable = atoi(value);
19251926
} else if (strcmp(key, "touch_enable_mouse_emulation") == 0) {
19261927
config->touch_enable_mouse_emulation = atoi(value);
1928+
} else if (strcmp(key, "touch_map_to_mon") == 0) {
1929+
if (config->touch_map_to_mon)
1930+
free(config->touch_map_to_mon);
1931+
config->touch_map_to_mon = value[0] ? strdup(value) : NULL;
19271932
} else if (strcmp(key, "tap_to_click") == 0) {
19281933
config->tap_to_click = atoi(value);
19291934
} else if (strcmp(key, "tap_and_drag") == 0) {
@@ -3906,6 +3911,11 @@ void free_config(void) {
39063911
config.tablet_map_to_mon = NULL;
39073912
}
39083913

3914+
if (config.touch_map_to_mon) {
3915+
free(config.touch_map_to_mon);
3916+
config.touch_map_to_mon = NULL;
3917+
}
3918+
39093919
if (config.jump_labels) {
39103920
free(config.jump_labels);
39113921
config.jump_labels = NULL;
@@ -4473,6 +4483,7 @@ bool parse_config(void) {
44734483
config.jumplabeldata.font_desc = NULL;
44744484
config.groupbardata.font_desc = NULL;
44754485
config.tablet_map_to_mon = NULL;
4486+
config.touch_map_to_mon = NULL;
44764487
config.jump_labels = NULL;
44774488
strcpy(config.keymode, "default");
44784489

src/input/touch.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ static struct wl_listener cursor_touch_cancel = {.notify = touch_cancel};
4040
static struct wl_listener cursor_touch_motion = {.notify = touch_motion};
4141
static struct wl_listener cursor_touch_frame = {.notify = touch_frame};
4242

43+
// 将触摸设备映射到 touch_map_to_mon 指定的显示器。
44+
// 支持热插拔输出和配置重载,每次触摸按下时重新应用。
45+
static void touch_apply_monitor_mapping(struct wlr_touch *touch) {
46+
if (!config.touch_map_to_mon)
47+
return;
48+
49+
Monitor *m = NULL;
50+
wl_list_for_each(m, &mons, link) {
51+
if (match_monitor_spec(config.touch_map_to_mon, m)) {
52+
wlr_cursor_map_input_to_output(cursor, &touch->base, m->wlr_output);
53+
mango_error(true, WLR_DEBUG, "Mapping touch %s to output %s",
54+
touch->base.name, config.touch_map_to_mon);
55+
return;
56+
}
57+
}
58+
}
59+
4360
void createtouch(struct wlr_touch *touch) {
4461
struct libinput_device *device = NULL;
4562

@@ -50,6 +67,7 @@ void createtouch(struct wlr_touch *touch) {
5067
device, config.send_events_mode);
5168
}
5269
wlr_cursor_attach_input_device(cursor, &touch->base);
70+
touch_apply_monitor_mapping(touch);
5371
}
5472

5573
void touch_point_surface_destroy(struct wl_listener *listener, void *data) {
@@ -133,6 +151,8 @@ void touch_down(struct wl_listener *listener, void *data) {
133151
return;
134152
}
135153

154+
touch_apply_monitor_mapping(event->touch);
155+
136156
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
137157

138158
point->surface = touch_get_coords(event->touch, event->x, event->y,

0 commit comments

Comments
 (0)