command/input: cleanup memory manangement a bit
This commit is contained in:
parent
931b6268e7
commit
a7b174ccf4
@ -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
|
// 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.
|
// in riverctl list-inputs as they can't be configured.
|
||||||
if (!isKeyboardGroup(wlr_device)) {
|
if (!isKeyboardGroup(wlr_device)) {
|
||||||
// Apply any matching input device configuration.
|
// Apply all matching input device configuration.
|
||||||
for (server.input_manager.configs.items) |*input_config| {
|
for (server.input_manager.configs.items) |input_config| {
|
||||||
if (globber.match(identifier, input_config.glob)) {
|
if (globber.match(identifier, input_config.glob)) {
|
||||||
input_config.apply(device);
|
input_config.apply(device);
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const mem = std.mem;
|
const mem = std.mem;
|
||||||
const meta = std.meta;
|
|
||||||
const math = std.math;
|
|
||||||
const sort = std.sort;
|
const sort = std.sort;
|
||||||
|
|
||||||
const globber = @import("globber");
|
const globber = @import("globber");
|
||||||
@ -28,7 +26,6 @@ const util = @import("../util.zig");
|
|||||||
const Error = @import("../command.zig").Error;
|
const Error = @import("../command.zig").Error;
|
||||||
const Seat = @import("../Seat.zig");
|
const Seat = @import("../Seat.zig");
|
||||||
const InputConfig = @import("../InputConfig.zig");
|
const InputConfig = @import("../InputConfig.zig");
|
||||||
const InputManager = @import("../InputManager.zig");
|
|
||||||
|
|
||||||
pub fn listInputs(
|
pub fn listInputs(
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
@ -96,20 +93,19 @@ pub fn input(
|
|||||||
try input_config.parse(args[2], args[3]);
|
try input_config.parse(args[2], args[3]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const glob_owned = try util.gpa.dupe(u8, args[1]);
|
var input_config: InputConfig = .{
|
||||||
errdefer util.gpa.free(glob_owned);
|
.glob = try util.gpa.dupe(u8, args[1]),
|
||||||
|
};
|
||||||
|
errdefer util.gpa.free(input_config.glob);
|
||||||
|
|
||||||
try server.input_manager.configs.ensureUnusedCapacity(1);
|
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]);
|
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);
|
sort.insertion(InputConfig, server.input_manager.configs.items, {}, lessThan);
|
||||||
|
|
||||||
// We need to update all input device matching the glob. The user may
|
// We need to update all input device matching the glob. The user may
|
||||||
@ -123,9 +119,9 @@ pub fn input(
|
|||||||
// the same.
|
// the same.
|
||||||
if (!globber.match(device.identifier, args[1])) continue;
|
if (!globber.match(device.identifier, args[1])) continue;
|
||||||
|
|
||||||
for (server.input_manager.configs.items) |ic| {
|
for (server.input_manager.configs.items) |config| {
|
||||||
if (globber.match(device.identifier, ic.glob)) {
|
if (globber.match(device.identifier, config.glob)) {
|
||||||
ic.apply(device);
|
config.apply(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user