Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

Compact Input settings and hide auxiliary pointer interfaces

oxydizerdc2b9028594f
diff --git a/po/rediwm.pot b/po/rediwm.pot
index bb827b7..8498848 100644
--- a/po/rediwm.pot
+++ b/po/rediwm.pot
@@ -5363,6 +5363,10 @@ msgstr ""
msgid "Show Trash"
msgstr ""
+#: src/control_center/search_index.zig
+msgid "Show all devices"
+msgstr ""
+
#: src/control_center/sections/users.zig
msgid "Show all groups"
msgstr ""
diff --git a/src/control_center/search_index.zig b/src/control_center/search_index.zig
index fa6ebaa..a45b717 100644
--- a/src/control_center/search_index.zig
+++ b/src/control_center/search_index.zig
@@ -35,6 +35,7 @@ const source_entries = [_]SourceEntry{
.{ .page = .general, .title = i18n.msg("Brightness"), .target = "@Brightness", .heading = i18n.msg("Brightness"), .keywords = i18n.msg("backlight screen light") },
.{ .page = .general, .title = i18n.msg("Open files with a single click"), .target = "files_single_click_open", .keywords = i18n.msg("double click folders") },
.{ .page = .input, .title = i18n.msg("Pointer device"), .target = "pointer_device", .keywords = i18n.msg("mouse touchpad trackpad select") },
+ .{ .page = .input, .title = i18n.msg("Show all devices"), .target = "pointer_show_all", .keywords = i18n.msg("mouse touchpad trackpad select") },
.{ .page = .input, .title = i18n.msg("Reset pointer settings"), .target = "pointer_reset", .keywords = i18n.msg("mouse touchpad trackball default custom inherit") },
.{ .page = .input, .title = i18n.msg("Pointer speed"), .target = "pointer_speed", .keywords = i18n.msg("mouse touchpad trackpad acceleration sensitivity") },
.{ .page = .input, .title = i18n.msg("Disable while typing"), .target = "disable_while_typing", .keywords = i18n.msg("keyboard touchpad trackpad") },
diff --git a/src/control_center/sections/input.zig b/src/control_center/sections/input.zig
index 564bc92..b539f16 100644
--- a/src/control_center/sections/input.zig
+++ b/src/control_center/sections/input.zig
@@ -62,15 +62,16 @@ fn keyboardLayoutIndex(cfg: anytype) ?usize {
pub const Section = struct {
root: Widget = undefined,
top_children: [2]Widget = undefined,
- row_storage: [12]Widget = undefined,
+ row_storage: [7]Widget = undefined,
row_count: usize = 0,
- selector_children: [3]Widget = undefined,
+ selector_children: [4]Widget = undefined,
selector_header_children: [2]Widget = undefined,
speed_group_children: [2]Widget = undefined,
speed_header_children: [2]Widget = undefined,
speed_label_children: [2]Widget = undefined,
- bool_row_children: [5][2]Widget = undefined,
- bool_label_children: [5][2]Widget = undefined,
+ bool_rows: [bool_keys.len]Widget = undefined,
+ bool_row_children: [bool_keys.len][2]Widget = undefined,
+ bool_label_children: [bool_keys.len][2]Widget = undefined,
speed_value_buf: [16]u8 = undefined,
layout_row_children: [2]Widget = undefined,
pan_speed_row_children: [2]Widget = undefined,
@@ -83,6 +84,7 @@ pub const Section = struct {
device_ids: []u64 = &.{},
device_labels: [][]const u8 = &.{},
device_icons: []layout.IconId = &.{},
+ show_all_devices: bool = false,
selected_id: ?u64 = null,
status: enum { none, unavailable, apply_failed, save_failed, rollback_failed, reset_failed, reset_restore_failed } = .none,
input: *Input = undefined,
@@ -110,6 +112,15 @@ fn selected(s: *Section, id: usize) ?*Pointer {
return Pointer.find(s.input, @intCast(id));
}
+fn primaryPointer(input: *Input, pointer: *Pointer) bool {
+ if (!libinput.isSettingsPointer(pointer.device)) return false;
+ var it = input.pointers.iterator(.forward);
+ while (it.next()) |other| {
+ if (other != pointer and libinput.isTouchpadCompanion(pointer.device, other.device)) return false;
+ }
+ return true;
+}
+
fn enumerate(s: *Section) void {
_ = s.arena.reset(.retain_capacity);
const a = s.arena.allocator();
@@ -127,6 +138,7 @@ fn enumerate(s: *Section) void {
var n: usize = 0;
var preferred: ?u64 = null;
while (it.next()) |pointer| {
+ if (!s.show_all_devices and !primaryPointer(s.input, pointer)) continue;
const friendly = libinput.getFriendlyName(a, pointer.device) catch null;
const raw_name = if (pointer.device.name) |p| std.mem.span(p) else "";
const fallback_name = if (raw_name.len > 0) raw_name else i18n.tr("Pointer device");
@@ -177,8 +189,8 @@ fn enumerate(s: *Section) void {
return;
}
}
- // Automation/nested pointers remain selectable, but should not hide the
- // physical device controls when opening this page for the first time.
+ // In the full list, prefer a configurable device over automation/nested
+ // pointers when the previous selection disappeared.
s.selected_id = preferred orelse (if (n > 0) ids[0] else null);
s.status = .none;
}
@@ -234,11 +246,23 @@ fn buildSelector(s: *Section, row_count: *usize) ?*Pointer {
.width = .{ .percent = 1 },
},
dimLabel(statusText(s, pointer)),
+ .{ .name = "pointer_show_all", .kind = .{ .checkbox = .{
+ .label = i18n.tr("Show all devices"),
+ .checked = s.show_all_devices,
+ .owner = s,
+ .on_change = &onShowAllDevices,
+ } } },
};
layout.appendRow(&s.row_storage, row_count, .{ .kind = .container, .direction = .column, .gap = 8, .children = &s.selector_children });
return pointer;
}
+fn onShowAllDevices(owner: ?*anyopaque, _: usize, on: bool) void {
+ const s: *Section = @ptrCast(@alignCast(owner orelse return));
+ s.show_all_devices = on;
+ refresh(s);
+}
+
fn onDevicePicked(owner: ?*anyopaque, generation: usize, index: usize) void {
const s: *Section = @ptrCast(@alignCast(owner orelse return));
if (generation != std.hash.Wyhash.hash(0, std.mem.sliceAsBytes(s.device_ids))) return;
@@ -299,7 +323,7 @@ fn buildSpeed(s: *Section, pointer: ?*Pointer, row_count: *usize) void {
layout.appendRow(&s.row_storage, row_count, .{ .kind = .container, .direction = .column, .gap = 8, .children = s.speed_group_children[0..count] });
}
-fn buildToggle(s: *Section, pointer: ?*Pointer, row_count: *usize, index: usize, comptime key: []const u8, label: []const u8, comptime getter: anytype, comptime setter: anytype) void {
+fn buildToggle(s: *Section, pointer: ?*Pointer, index: usize, comptime key: []const u8, label: []const u8, comptime getter: anytype, comptime setter: anytype) Widget {
const value = if (pointer) |p| getter(p.device) else null;
const editable = if (pointer) |p| p.persistentId() != null else false;
s.bool_label_children[index] = .{ fgLabel(label), originLabel(s, pointer, key, value != null) };
@@ -326,7 +350,7 @@ fn buildToggle(s: *Section, pointer: ?*Pointer, row_count: *usize, index: usize,
},
},
};
- layout.appendRow(&s.row_storage, row_count, row(&s.bool_row_children[index]));
+ return row(&s.bool_row_children[index]);
}
/// Prepare memory before touching hardware or disk. Only publish the new
@@ -469,11 +493,14 @@ pub fn build(out: *Section, input: *Input) void {
var row_count: usize = 0;
const pointer = buildSelector(out, &row_count);
buildSpeed(out, pointer, &row_count);
- buildToggle(out, pointer, &row_count, 0, "natural_scroll", i18n.tr("Natural scroll"), libinput.getNaturalScroll, libinput.setNaturalScroll);
- buildToggle(out, pointer, &row_count, 1, "left_handed", i18n.tr("Left-handed mode"), libinput.getLeftHanded, libinput.setLeftHanded);
- buildToggle(out, pointer, &row_count, 2, "tap_to_click", i18n.tr("Tap to click"), libinput.getTapToClick, libinput.setTapToClick);
- buildToggle(out, pointer, &row_count, 3, "tap_drag", i18n.tr("Tap and drag"), libinput.getTapDrag, libinput.setTapDrag);
- buildToggle(out, pointer, &row_count, 4, "disable_while_typing", i18n.tr("Disable while typing"), libinput.getDisableWhileTyping, libinput.setDisableWhileTyping);
+ out.bool_rows = .{
+ buildToggle(out, pointer, 0, "natural_scroll", i18n.tr("Natural scroll"), libinput.getNaturalScroll, libinput.setNaturalScroll),
+ buildToggle(out, pointer, 1, "left_handed", i18n.tr("Left-handed mode"), libinput.getLeftHanded, libinput.setLeftHanded),
+ buildToggle(out, pointer, 2, "tap_to_click", i18n.tr("Tap to click"), libinput.getTapToClick, libinput.setTapToClick),
+ buildToggle(out, pointer, 3, "tap_drag", i18n.tr("Tap and drag"), libinput.getTapDrag, libinput.setTapDrag),
+ buildToggle(out, pointer, 4, "disable_while_typing", i18n.tr("Disable while typing"), libinput.getDisableWhileTyping, libinput.setDisableWhileTyping),
+ };
+ layout.appendRow(&out.row_storage, &row_count, .{ .kind = .container, .direction = .column, .gap = 10, .children = &out.bool_rows });
const repeat = firstKeyboardRepeat(input);
out.pan_speed_row_children = .{
diff --git a/src/libinput.zig b/src/libinput.zig
index b863b6d..349dbd1 100644
--- a/src/libinput.zig
+++ b/src/libinput.zig
@@ -70,6 +70,40 @@ pub fn getKind(device: *wlr.InputDevice) Kind {
return presentation.classify(tags);
}
+/// Settings defaults to physical pointing devices. Composite HID keyboards
+/// can expose wheels and even full mouse reports for macros; leave those in
+/// the optional full list. Never filter a touchpad, trackball or pointing stick
+/// merely because it shares a keyboard interface.
+pub fn isSettingsPointer(device: *wlr.InputDevice) bool {
+ const dev = handle(device) orelse return false;
+ const kind = getKind(device);
+ if (kind == .touchpad or kind == .trackball) return true;
+ if (c.libinput_device_get_udev_device(dev)) |udev| {
+ defer _ = c.udev_device_unref(udev);
+ if (propertyFlag(udev, "ID_INPUT_POINTINGSTICK")) return true;
+ if (std.mem.eql(u8, ancestorAttribute(udev, "bInterfaceClass") orelse "", "03") and
+ std.mem.eql(u8, ancestorAttribute(udev, "bInterfaceProtocol") orelse "", "01")) return false;
+ }
+ if (kind == .mouse) return true;
+ if (c.libinput_device_has_capability(dev, c.LIBINPUT_DEVICE_CAP_KEYBOARD) != 0) return false;
+ return getPointerSpeed(device) != null or getNaturalScroll(device) != null or getLeftHanded(device) != null;
+}
+
+/// Some touchpads expose a second, compatibility mouse interface. Only hide
+/// that interface when its actual touchpad is connected in the same libinput
+/// group. A paired pointing stick is a separate physical control.
+pub fn isTouchpadCompanion(device: *wlr.InputDevice, touchpad: *wlr.InputDevice) bool {
+ if (getKind(device) != .mouse or getKind(touchpad) != .touchpad) return false;
+ const dev = handle(device) orelse return false;
+ const pad = handle(touchpad) orelse return false;
+ if (c.libinput_device_get_udev_device(dev)) |udev| {
+ defer _ = c.udev_device_unref(udev);
+ if (propertyFlag(udev, "ID_INPUT_POINTINGSTICK")) return false;
+ }
+ const group = c.libinput_device_get_device_group(dev) orelse return false;
+ return group == c.libinput_device_get_device_group(pad);
+}
+
/// The returned key owns its bytes and survives removal of the libinput device.
/// No sysname, sysfs input number, pointer address, or connection index is used.
pub fn getIdentity(device: *wlr.InputDevice) ?Identity {
diff --git a/tests/input_persistence.py b/tests/input_persistence.py
index 571ca13..4520dbd 100644
--- a/tests/input_persistence.py
+++ b/tests/input_persistence.py
@@ -97,9 +97,11 @@ class Fixture:
wait(lambda: self.state_file.stat().st_mtime_ns != before, "fixture command")
def select(self, ui, ipc, device):
- # IPC automation owns the first (non-libinput) pointer in this headless
- # session. It is shown read-only alongside the fixture's real devices.
- index = self.connected.index(device) + 1
+ # The synthetic pointer is present only in the optional full list.
+ index = self.connected.index(device) + int(ui.find("pointer_show_all")["checked"])
+ self.select_index(ui, ipc, index)
+
+ def select_index(self, ui, ipc, index):
ui.click(ui.scroll_into_view("pointer_device"), panel="control_center")
ui.wait_settled("control_center")
ipc.key_down_up(102) # Home
@@ -171,6 +173,58 @@ def capture_input(ui, ipc, suffix, menu_open=False):
ipc.screenshot(str(path))
+def verify_primary_devices(fixture, ui, ipc):
+ def last_device(index):
+ ui.click(ui.scroll_into_view("pointer_device"), panel="control_center")
+ ipc.key_down_up(107) # End
+ ipc.key_down_up(28) # Return
+ ui.wait_settled("control_center")
+ selector = ui.find("pointer_device")
+ assert selector["selected_index"] == index, selector
+
+ # One mouse and one touchpad expose consumer controls, mouse macros, a
+ # compatibility mouse, and a keyboard's phantom mouse interface as well.
+ for device in (6, 7, 8, 9):
+ fixture.command(1, device)
+ ui.wait_settled("control_center")
+ last_device(1)
+ ui.click(ui.find("pointer_device"), panel="control_center")
+ capture_input(ui, ipc, "primary-devices", menu_open=True)
+ ipc.key_down_up(1)
+ ui.wait_settled("control_center")
+
+ fixture.click(ui, "pointer_show_all")
+ last_device(6)
+ fixture.select_index(ui, ipc, 0)
+ assert ui.find("pointer_speed")["role"] != "slider"
+ assert ui.find("natural_scroll")["is_disabled"]
+ fixture.select(ui, ipc, 7)
+ assert not ui.find("natural_scroll")["is_disabled"]
+ fixture.click(ui, "pointer_show_all")
+ assert ui.find("pointer_device")["selected_index"] == 0
+ last_device(1)
+
+ # The mouse interface remains usable if its touchpad peer is removed.
+ fixture.command(2, 1)
+ ui.wait_settled("control_center")
+ last_device(1)
+ fixture.command(1, 1)
+ ui.wait_settled("control_center")
+ assert ui.find("pointer_device")["selected_index"] == 0
+ last_device(1)
+
+ # A real pointing stick sharing the pad's group and a keyboard interface
+ # must stay visible, unlike the touchpad's compatibility mouse.
+ fixture.command(1, 10)
+ ui.wait_settled("control_center")
+ last_device(2)
+ for device in (6, 7, 8, 9, 10):
+ fixture.command(2, device)
+ ui.wait_settled("control_center")
+ fixture.select(ui, ipc, 0)
+ print("PASS: primary device list hides synthetic and auxiliary interfaces; full list, pointing sticks and peer hotplug remain usable")
+
+
def verify_trackball_profile(fixture, ui, ipc):
# udev identifies this unnamed device as a trackball; its display fallback
# is Kensington Expert Mouse, which deliberately omits the word trackball.
@@ -280,6 +334,9 @@ def run_session(fixture, restart):
print("PASS: per-device settings and reset-to-default inheritance restored after compositor restart")
return
+ verify_primary_devices(fixture, ui, ipc)
+ state = fixture.state()
+
# Global-only configurations still select the appropriate device defaults.
assert math.isclose(state[0]["speed"], -.4, abs_tol=1e-6) and math.isclose(state[1]["speed"], .3, abs_tol=1e-6), state
assert state[0]["natural"] and state[1]["natural"], state
@@ -373,6 +430,7 @@ def run_session(fixture, restart):
assert not fixture.state()[0]["natural"]
fixture.command(1, 4)
+ fixture.click(ui, "pointer_show_all")
fixture.select(ui, ipc, 4)
for name in ("natural_scroll", "left_handed", "tap_to_click", "tap_drag", "disable_while_typing"):
assert ui.find(name)["is_disabled"]
diff --git a/tests/pointer_settings_hook.c b/tests/pointer_settings_hook.c
index 6485f4b..e3dc06e 100644
--- a/tests/pointer_settings_hook.c
+++ b/tests/pointer_settings_hook.c
@@ -26,15 +26,22 @@ struct fake_device {
unsigned generation, writes, failures;
unsigned fail_after;
};
-static struct fake_device devices[6];
+enum { DEVICE_COUNT = 11 };
+static struct fake_device devices[DEVICE_COUNT];
static struct wlr_backend *backend;
static const struct wlr_pointer_impl impl = {.name = "pointer-settings-fixture"};
-static const char *names[] = {"Fixture Mouse", "Fixture Touchpad", "Fixture Mouse", "Fixture Mouse", "Fixture Unsupported", ""};
-static const char *paths[] = {"pci-fixture-usb-0:1:1.0", "platform-fixture-touchpad", "pci-fixture-usb-0:2:1.0", "pci-fixture-usb-0:1:1.0", NULL, "pci-fixture-usb-0:3:1.0"};
-static char sysnames[6][32];
+static const char *names[] = {
+ "Fixture Mouse", "Fixture Touchpad", "Fixture Mouse", "Fixture Mouse", "Fixture Unsupported", "",
+ "Fixture Consumer Control", "Fixture Mouse Macros", "Fixture Touchpad Mouse", "Fixture Keyboard Mouse", "Fixture Pointing Stick",
+};
+static const char *paths[] = {
+ "pci-fixture-usb-0:1:1.0", "platform-fixture-touchpad", "pci-fixture-usb-0:2:1.0", "pci-fixture-usb-0:1:1.0", NULL, "pci-fixture-usb-0:3:1.0",
+ "pci-fixture-usb-0:1:1.1", "pci-fixture-usb-0:1:1.2", "platform-fixture-touchpad", "pci-fixture-usb-0:4:1.3", "platform-fixture-touchpad",
+};
+static char sysnames[DEVICE_COUNT][32];
static int index_of(const void *device) {
- for (unsigned i = 0; i < 6; i++) if (device == &devices[i]) return (int)i;
+ for (unsigned i = 0; i < DEVICE_COUNT; i++) if (device == &devices[i]) return (int)i;
return -1;
}
static int live_index(const void *device) {
@@ -52,7 +59,7 @@ static void snapshot(void) {
FILE *file = fopen(temporary, "w");
assert(file);
fputs("[", file);
- for (unsigned i = 0; i < 6; i++) {
+ for (unsigned i = 0; i < DEVICE_COUNT; i++) {
struct fake_device *d = &devices[i];
fprintf(file, "%s{\"live\":%s,\"speed\":%.9g,\"natural\":%s,\"left\":%s,\"tap\":%s,\"drag\":%s,\"dwt\":%s,\"writes\":%u,\"failures\":%u}",
i ? "," : "", d->live ? "true" : "false", d->speed,
@@ -70,7 +77,7 @@ static int input_ready(int fd, uint32_t mask, void *data) {
ssize_t n;
while ((n = read(fd, packet, sizeof(packet))) == sizeof(packet)) {
unsigned index = packet[1];
- assert(index < 6);
+ assert(index < DEVICE_COUNT);
struct fake_device *d = &devices[index];
switch (packet[0]) {
case 1:
@@ -114,7 +121,7 @@ struct wlr_backend *wlr_headless_backend_create(struct wl_event_loop *loop) {
void wlr_backend_destroy(struct wlr_backend *target) {
REAL(wlr_backend_destroy);
if (target == backend) {
- for (unsigned i = 0; i < 6; i++) if (devices[i].live) {
+ for (unsigned i = 0; i < DEVICE_COUNT; i++) if (devices[i].live) {
wlr_pointer_finish(&devices[i].pointer);
devices[i].live = false;
}
@@ -122,12 +129,12 @@ void wlr_backend_destroy(struct wlr_backend *target) {
real(target);
}
bool wlr_input_device_is_libinput(struct wlr_input_device *device) {
- for (unsigned i = 0; i < 6; i++) if (device == &devices[i].pointer.base) return true;
+ for (unsigned i = 0; i < DEVICE_COUNT; i++) if (device == &devices[i].pointer.base) return true;
REAL(wlr_input_device_is_libinput);
return real(device);
}
struct libinput_device *wlr_libinput_get_device_handle(struct wlr_input_device *device) {
- for (unsigned i = 0; i < 6; i++) if (device == &devices[i].pointer.base) {
+ for (unsigned i = 0; i < DEVICE_COUNT; i++) if (device == &devices[i].pointer.base) {
assert(devices[i].live);
return (struct libinput_device *)&devices[i];
}
@@ -140,6 +147,11 @@ unsigned int libinput_device_get_id_bustype(struct libinput_device *device) { li
unsigned int libinput_device_get_id_vendor(struct libinput_device *device) { live_index(device); return 0x1234; }
unsigned int libinput_device_get_id_product(struct libinput_device *device) { int i = live_index(device); return i == 1 ? 2 : i == 5 ? 3 : 1; }
struct udev_device *libinput_device_get_udev_device(struct libinput_device *device) { live_index(device); return (struct udev_device *)device; }
+struct libinput_device_group *libinput_device_get_device_group(struct libinput_device *device) {
+ int i = live_index(device);
+ int group = (i == 6 || i == 7) ? 0 : (i == 8 || i == 10) ? 1 : i;
+ return (struct libinput_device_group *)&devices[group];
+}
struct udev_device *udev_device_unref(struct udev_device *device) {
if (index_of(device) >= 0) return NULL;
REAL(udev_device_unref); return real(device);
@@ -149,7 +161,13 @@ struct udev_device *udev_device_get_parent(struct udev_device *device) {
REAL(udev_device_get_parent); return real(device);
}
const char *udev_device_get_sysattr_value(struct udev_device *device, const char *key) {
- if (index_of(device) >= 0) return strcmp(key, "bInterfaceNumber") == 0 ? "00" : NULL;
+ int i = index_of(device);
+ if (i >= 0) {
+ if (strcmp(key, "bInterfaceNumber") == 0) return "00";
+ if (strcmp(key, "bInterfaceClass") == 0) return "03";
+ if (strcmp(key, "bInterfaceProtocol") == 0) return i == 7 || i == 9 || i == 10 ? "01" : "00";
+ return NULL;
+ }
REAL(udev_device_get_sysattr_value); return real(device, key);
}
const char *udev_device_get_property_value(struct udev_device *device, const char *key) {
@@ -158,8 +176,9 @@ const char *udev_device_get_property_value(struct udev_device *device, const cha
if (strcmp(key, "ID_PATH") == 0) return paths[i];
if (strcmp(key, "ID_SERIAL_SHORT") == 0 && i == 1) return "fixture-touchpad-serial";
if (strcmp(key, "ID_INPUT_TOUCHPAD") == 0) return i == 1 ? "1" : NULL;
- if (strcmp(key, "ID_INPUT_MOUSE") == 0) return i != 1 && i != 4 ? "1" : NULL;
+ if (strcmp(key, "ID_INPUT_MOUSE") == 0) return i != 1 && i != 4 && i != 6 ? "1" : NULL;
if (strcmp(key, "ID_INPUT_TRACKBALL") == 0) return i == 5 ? "1" : NULL;
+ if (strcmp(key, "ID_INPUT_POINTINGSTICK") == 0) return i == 10 ? "1" : NULL;
if (strcmp(key, "ID_VENDOR_FROM_DATABASE") == 0 && i == 5) return "Kensington";
if (strcmp(key, "ID_MODEL_FROM_DATABASE") == 0 && i == 5) return "Expert Mouse";
return NULL;
@@ -167,7 +186,8 @@ const char *udev_device_get_property_value(struct udev_device *device, const cha
REAL(udev_device_get_property_value); return real(device, key);
}
int libinput_device_has_capability(struct libinput_device *device, enum libinput_device_capability cap) {
- live_index(device); return cap == LIBINPUT_DEVICE_CAP_POINTER;
+ int i = live_index(device);
+ return cap == LIBINPUT_DEVICE_CAP_POINTER || (i == 6 && cap == LIBINPUT_DEVICE_CAP_KEYBOARD);
}
int libinput_device_config_accel_is_available(struct libinput_device *device) { return live_index(device) != 4; }
int libinput_device_config_scroll_has_natural_scroll(struct libinput_device *device) { return live_index(device) != 4; }