InputDevice: move to separate file
This commit is contained in:
parent
78d96d19e4
commit
c40dc5ee75
@ -27,7 +27,7 @@ const c = @import("c.zig");
|
|||||||
const server = &@import("main.zig").server;
|
const server = &@import("main.zig").server;
|
||||||
const util = @import("util.zig");
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const InputDevice = @import("InputManager.zig").InputDevice;
|
const InputDevice = @import("InputDevice.zig");
|
||||||
|
|
||||||
// TODO - keyboards
|
// TODO - keyboards
|
||||||
// - mapping to output / region
|
// - mapping to output / region
|
||||||
|
75
river/InputDevice.zig
Normal file
75
river/InputDevice.zig
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
// This file is part of river, a dynamic tiling wayland compositor.
|
||||||
|
//
|
||||||
|
// Copyright 2022 The River Developers
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, version 3.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
const InputDevice = @This();
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
|
const mem = std.mem;
|
||||||
|
const ascii = std.ascii;
|
||||||
|
const wlr = @import("wlroots");
|
||||||
|
const wl = @import("wayland").server.wl;
|
||||||
|
|
||||||
|
const server = &@import("main.zig").server;
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
|
const log = std.log.scoped(.input_manager);
|
||||||
|
|
||||||
|
device: *wlr.InputDevice,
|
||||||
|
destroy: wl.Listener(*wlr.InputDevice) = wl.Listener(*wlr.InputDevice).init(handleDestroy),
|
||||||
|
|
||||||
|
/// Careful: The identifier is not unique! A physical input device may have
|
||||||
|
/// multiple logical input devices with the exact same vendor id, product id
|
||||||
|
/// and name. However identifiers of InputConfigs are unique.
|
||||||
|
identifier: []const u8,
|
||||||
|
|
||||||
|
pub fn init(self: *InputDevice, device: *wlr.InputDevice) !void {
|
||||||
|
const identifier = try std.fmt.allocPrint(
|
||||||
|
util.gpa,
|
||||||
|
"{s}-{}-{}-{s}",
|
||||||
|
.{
|
||||||
|
@tagName(device.type),
|
||||||
|
device.vendor,
|
||||||
|
device.product,
|
||||||
|
mem.trim(u8, mem.span(device.name), &ascii.spaces),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
for (identifier) |*char| {
|
||||||
|
if (char.* == ' ' or !ascii.isPrint(char.*)) {
|
||||||
|
char.* = '_';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.* = .{
|
||||||
|
.device = device,
|
||||||
|
.identifier = identifier,
|
||||||
|
};
|
||||||
|
log.debug("new input device: {s}", .{self.identifier});
|
||||||
|
device.events.destroy.add(&self.destroy);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(self: *InputDevice) void {
|
||||||
|
util.gpa.free(self.identifier);
|
||||||
|
self.destroy.link.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handleDestroy(listener: *wl.Listener(*wlr.InputDevice), _: *wlr.InputDevice) void {
|
||||||
|
const self = @fieldParentPtr(InputDevice, "destroy", listener);
|
||||||
|
log.debug("removed input device: {s}", .{self.identifier});
|
||||||
|
self.deinit();
|
||||||
|
|
||||||
|
const node = @fieldParentPtr(std.TailQueue(InputDevice).Node, "data", self);
|
||||||
|
server.input_manager.input_devices.remove(node);
|
||||||
|
util.gpa.destroy(node);
|
||||||
|
}
|
@ -19,7 +19,6 @@ const Self = @This();
|
|||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const mem = std.mem;
|
const mem = std.mem;
|
||||||
const ascii = std.ascii;
|
|
||||||
const wlr = @import("wlroots");
|
const wlr = @import("wlroots");
|
||||||
const wl = @import("wayland").server.wl;
|
const wl = @import("wayland").server.wl;
|
||||||
|
|
||||||
@ -27,64 +26,14 @@ const server = &@import("main.zig").server;
|
|||||||
const util = @import("util.zig");
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const InputConfig = @import("InputConfig.zig");
|
const InputConfig = @import("InputConfig.zig");
|
||||||
|
const InputDevice = @import("InputDevice.zig");
|
||||||
const Seat = @import("Seat.zig");
|
const Seat = @import("Seat.zig");
|
||||||
const Server = @import("Server.zig");
|
|
||||||
const View = @import("View.zig");
|
|
||||||
const PointerConstraint = @import("PointerConstraint.zig");
|
const PointerConstraint = @import("PointerConstraint.zig");
|
||||||
|
|
||||||
const default_seat_name = "default";
|
const default_seat_name = "default";
|
||||||
|
|
||||||
const log = std.log.scoped(.input_manager);
|
const log = std.log.scoped(.input_manager);
|
||||||
|
|
||||||
pub const InputDevice = struct {
|
|
||||||
device: *wlr.InputDevice,
|
|
||||||
destroy: wl.Listener(*wlr.InputDevice) = wl.Listener(*wlr.InputDevice).init(handleDestroy),
|
|
||||||
|
|
||||||
/// Careful: The identifier is not unique! A physical input device may have
|
|
||||||
/// multiple logical input devices with the exact same vendor id, product id
|
|
||||||
/// and name. However identifiers of InputConfigs are unique.
|
|
||||||
identifier: []const u8,
|
|
||||||
|
|
||||||
pub fn init(self: *InputDevice, device: *wlr.InputDevice) !void {
|
|
||||||
const identifier = try std.fmt.allocPrint(
|
|
||||||
util.gpa,
|
|
||||||
"{s}-{}-{}-{s}",
|
|
||||||
.{
|
|
||||||
@tagName(device.type),
|
|
||||||
device.vendor,
|
|
||||||
device.product,
|
|
||||||
mem.trim(u8, mem.span(device.name), &ascii.spaces),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
for (identifier) |*char| {
|
|
||||||
if (char.* == ' ' or !ascii.isPrint(char.*)) {
|
|
||||||
char.* = '_';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.* = .{
|
|
||||||
.device = device,
|
|
||||||
.identifier = identifier,
|
|
||||||
};
|
|
||||||
log.debug("new input device: {s}", .{self.identifier});
|
|
||||||
device.events.destroy.add(&self.destroy);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn deinit(self: *InputDevice) void {
|
|
||||||
util.gpa.free(self.identifier);
|
|
||||||
self.destroy.link.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handleDestroy(listener: *wl.Listener(*wlr.InputDevice), _: *wlr.InputDevice) void {
|
|
||||||
const self = @fieldParentPtr(InputDevice, "destroy", listener);
|
|
||||||
log.debug("removed input device: {s}", .{self.identifier});
|
|
||||||
self.deinit();
|
|
||||||
|
|
||||||
const node = @fieldParentPtr(std.TailQueue(InputDevice).Node, "data", self);
|
|
||||||
server.input_manager.input_devices.remove(node);
|
|
||||||
util.gpa.destroy(node);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
new_input: wl.Listener(*wlr.InputDevice) = wl.Listener(*wlr.InputDevice).init(handleNewInput),
|
new_input: wl.Listener(*wlr.InputDevice) = wl.Listener(*wlr.InputDevice).init(handleNewInput),
|
||||||
|
|
||||||
idle: *wlr.Idle,
|
idle: *wlr.Idle,
|
||||||
|
Loading…
Reference in New Issue
Block a user