command/input: cleanup memory manangement a bit

This commit is contained in:
Isaac Freund 2024-02-19 18:07:15 +01:00
parent 931b6268e7
commit a7b174ccf4
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
2 changed files with 12 additions and 16 deletions

View File

@ -82,8 +82,8 @@ pub fn init(device: *InputDevice, seat: *Seat, wlr_device: *wlr.InputDevice) !vo
// Keyboard groups are implemented as "virtual" input devices which we don't want to expose
// in riverctl list-inputs as they can't be configured.
if (!isKeyboardGroup(wlr_device)) {
// Apply any matching input device configuration.
for (server.input_manager.configs.items) |*input_config| {
// Apply all matching input device configuration.
for (server.input_manager.configs.items) |input_config| {
if (globber.match(identifier, input_config.glob)) {
input_config.apply(device);
}

View File

@ -16,8 +16,6 @@
const std = @import("std");
const mem = std.mem;
const meta = std.meta;
const math = std.math;
const sort = std.sort;
const globber = @import("globber");
@ -28,7 +26,6 @@ const util = @import("../util.zig");
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
const InputConfig = @import("../InputConfig.zig");
const InputManager = @import("../InputManager.zig");
pub fn listInputs(
_: *Seat,
@ -96,20 +93,19 @@ pub fn input(
try input_config.parse(args[2], args[3]);
}
} else {
const glob_owned = try util.gpa.dupe(u8, args[1]);
errdefer util.gpa.free(glob_owned);
var input_config: InputConfig = .{
.glob = try util.gpa.dupe(u8, args[1]),
};
errdefer util.gpa.free(input_config.glob);
try server.input_manager.configs.ensureUnusedCapacity(1);
const input_config = server.input_manager.configs.addOneAssumeCapacity();
errdefer _ = server.input_manager.configs.pop();
input_config.* = .{
.glob = glob_owned,
};
try input_config.parse(args[2], args[3]);
server.input_manager.configs.appendAssumeCapacity(input_config);
}
// Sort input configs by generality.
// Sort input configs from most general to least general
sort.insertion(InputConfig, server.input_manager.configs.items, {}, lessThan);
// We need to update all input device matching the glob. The user may
@ -123,9 +119,9 @@ pub fn input(
// the same.
if (!globber.match(device.identifier, args[1])) continue;
for (server.input_manager.configs.items) |ic| {
if (globber.match(device.identifier, ic.glob)) {
ic.apply(device);
for (server.input_manager.configs.items) |config| {
if (globber.match(device.identifier, config.glob)) {
config.apply(device);
}
}
}