river: remove InputManager.server

The server is now global so this is no longer needed.
This commit is contained in:
Isaac Freund 2021-05-13 14:53:08 +02:00
parent ac27db236a
commit ece465b7ed
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
18 changed files with 71 additions and 70 deletions

View file

@ -94,7 +94,7 @@ swipe_end: wl.Listener(*wlr.Pointer.event.SwipeEnd) =
pub fn init(self: *Self, seat: *Seat) !void {
const wlr_cursor = try wlr.Cursor.create();
errdefer wlr_cursor.destroy();
wlr_cursor.attachOutputLayout(seat.input_manager.server.root.output_layout);
wlr_cursor.attachOutputLayout(server.root.output_layout);
// This is here so that self.xcursor_manager doesn't need to be an
// optional pointer. This isn't optimal as it does a needless allocation,
@ -105,7 +105,7 @@ pub fn init(self: *Self, seat: *Seat) !void {
self.* = .{
.seat = seat,
.wlr_cursor = wlr_cursor,
.pointer_gestures = try wlr.PointerGesturesV1.create(seat.input_manager.server.wl_server),
.pointer_gestures = try wlr.PointerGesturesV1.create(server.wl_server),
.xcursor_manager = xcursor_manager,
};
try self.setTheme(null, null);
@ -346,8 +346,7 @@ fn handlePointerMapping(self: *Self, event: *wlr.Pointer.event.Button, view: *Vi
const fullscreen = view.current.fullscreen or view.pending.fullscreen;
const config = self.seat.input_manager.server.config;
return for (config.modes.items[self.seat.mode_id].pointer_mappings.items) |mapping| {
return for (server.config.modes.items[self.seat.mode_id].pointer_mappings.items) |mapping| {
if (event.button == mapping.event_code and std.meta.eql(modifiers, mapping.modifiers)) {
switch (mapping.action) {
.move => if (!fullscreen) self.enterMode(.move, view),
@ -427,14 +426,13 @@ fn handleRequestSetCursor(
/// surface coordinates.
/// This function must be kept in sync with the rendering order in render.zig.
fn surfaceAt(self: Self, lx: f64, ly: f64, sx: *f64, sy: *f64) ?*wlr.Surface {
const root = self.seat.input_manager.server.root;
const wlr_output = root.output_layout.outputAt(lx, ly) orelse return null;
const wlr_output = server.root.output_layout.outputAt(lx, ly) orelse return null;
const output = @intToPtr(*Output, wlr_output.data);
// Get output-local coords from the layout coords
var ox = lx;
var oy = ly;
root.output_layout.outputCoords(wlr_output, &ox, &oy);
server.root.output_layout.outputCoords(wlr_output, &ox, &oy);
// Check surfaces in the reverse order they are rendered in:
// 1. overlay layer (+ popups)
@ -643,8 +641,7 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64,
view.applyPending();
},
.resize => |data| {
const config = &self.seat.input_manager.server.config;
const border_width = if (data.view.draw_borders) config.border_width else 0;
const border_width = if (data.view.draw_borders) server.config.border_width else 0;
// Set width/height of view, clamp to view size constraints and output dimensions
const box = &data.view.pending.box;
@ -671,9 +668,6 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64,
/// Pass an event on to the surface under the cursor, if any.
fn passthrough(self: *Self, time: u32) void {
const root = &self.seat.input_manager.server.root;
const config = self.seat.input_manager.server.config;
var sx: f64 = undefined;
var sy: f64 = undefined;
if (self.surfaceAt(self.wlr_cursor.x, self.wlr_cursor.y, &sx, &sy)) |surface| {
@ -687,12 +681,12 @@ fn passthrough(self: *Self, time: u32) void {
self.seat.wlr_seat.pointerNotifyEnter(surface, sx, sy);
self.seat.wlr_seat.pointerNotifyMotion(time, sx, sy);
const follow_mode = config.focus_follows_cursor;
const follow_mode = server.config.focus_follows_cursor;
if (follow_mode == .strict or (follow_mode == .normal and focus_change)) {
if (View.fromWlrSurface(surface)) |view| {
self.seat.focusOutput(view.output);
self.seat.focus(view);
root.startTransaction();
server.root.startTransaction();
}
}
}

View file

@ -21,6 +21,7 @@ const std = @import("std");
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
const server = &@import("main.zig").server;
const util = @import("util.zig");
const Seat = @import("Seat.zig");
@ -37,8 +38,7 @@ pub fn init(self: *Self, seat: *Seat, wlr_drag_icon: *wlr.Drag.Icon) void {
fn handleDestroy(listener: *wl.Listener(*wlr.Drag.Icon), wlr_drag_icon: *wlr.Drag.Icon) void {
const self = @fieldParentPtr(Self, "destroy", listener);
const root = &self.seat.input_manager.server.root;
const node = @fieldParentPtr(std.SinglyLinkedList(Self).Node, "data", self);
root.drag_icons.remove(node);
server.root.drag_icons.remove(node);
util.gpa.destroy(node);
}

View file

@ -22,6 +22,7 @@ const std = @import("std");
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
const server = &@import("main.zig").server;
const util = @import("util.zig");
const Seat = @import("Seat.zig");
@ -33,7 +34,6 @@ const default_seat_name = "default";
const log = std.log.scoped(.input_manager);
server: *Server,
new_input: wl.Listener(*wlr.InputDevice) = wl.Listener(*wlr.InputDevice).init(handleNewInput),
idle: *wlr.Idle,
@ -60,12 +60,11 @@ new_virtual_keyboard: wl.Listener(*wlr.VirtualKeyboardV1) =
wl.Listener(*wlr.VirtualKeyboardV1).init(handleNewVirtualKeyboard),
// zig fmt: on
pub fn init(self: *Self, server: *Server) !void {
pub fn init(self: *Self) !void {
const seat_node = try util.gpa.create(std.TailQueue(Seat).Node);
errdefer util.gpa.destroy(seat_node);
self.* = .{
.server = server,
// These are automatically freed when the display is destroyed
.idle = try wlr.Idle.create(server.wl_server),
.input_inhibit_manager = try wlr.InputInhibitManager.create(server.wl_server),
@ -156,7 +155,7 @@ fn handleInhibitDeactivate(
// Calling arrangeLayers() like this ensures that any top or overlay,
// keyboard-interactive surfaces will re-grab focus.
var output_it = self.server.root.outputs.first;
var output_it = server.root.outputs.first;
while (output_it) |output_node| : (output_it = output_node.next) {
output_node.data.arrangeLayers();
}
@ -169,7 +168,7 @@ fn handleInhibitDeactivate(
seat_node.data.mode_id = seat_node.data.prev_mode_id;
}
self.server.root.startTransaction();
server.root.startTransaction();
}
/// This event is raised by the backend when a new input device becomes available.

View file

@ -22,6 +22,7 @@ const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
const xkb = @import("xkbcommon");
const server = &@import("main.zig").server;
const util = @import("util.zig");
const Seat = @import("Seat.zig");
@ -60,8 +61,7 @@ pub fn init(self: *Self, seat: *Seat, input_device: *wlr.InputDevice) !void {
if (!wlr_keyboard.setKeymap(keymap)) return error.SetKeymapFailed;
const config = &seat.input_manager.server.config;
wlr_keyboard.setRepeatInfo(config.repeat_rate, config.repeat_delay);
wlr_keyboard.setRepeatInfo(server.config.repeat_rate, server.config.repeat_delay);
wlr_keyboard.events.key.add(&self.key);
wlr_keyboard.events.modifiers.add(&self.modifiers);
@ -149,9 +149,8 @@ fn handleBuiltinMapping(self: Self, keysym: xkb.Keysym) bool {
switch (@enumToInt(keysym)) {
@enumToInt(xkb.Keysym.XF86Switch_VT_1)...@enumToInt(xkb.Keysym.XF86Switch_VT_12) => {
log.debug("switch VT keysym received", .{});
const backend = self.seat.input_manager.server.backend;
if (backend.isMulti()) {
if (backend.getSession()) |session| {
if (server.backend.isMulti()) {
if (server.backend.getSession()) |session| {
const vt = @enumToInt(keysym) - @enumToInt(xkb.Keysym.XF86Switch_VT_1) + 1;
const log_server = std.log.scoped(.server);
log_server.notice("switching to VT {}", .{vt});

View file

@ -24,6 +24,7 @@ const wl = @import("wayland").server.wl;
const xkb = @import("xkbcommon");
const command = @import("command.zig");
const server = &@import("main.zig").server;
const util = @import("util.zig");
const DragIcon = @import("DragIcon.zig");
@ -88,8 +89,8 @@ pub fn init(self: *Self, input_manager: *InputManager, name: [*:0]const u8) !voi
self.* = .{
.input_manager = input_manager,
// This will be automatically destroyed when the display is destroyed
.wlr_seat = try wlr.Seat.create(input_manager.server.wl_server, name),
.focused_output = &self.input_manager.server.root.noop_output,
.wlr_seat = try wlr.Seat.create(server.wl_server, name),
.focused_output = &server.root.noop_output,
};
self.wlr_seat.data = @ptrToInt(self);
@ -202,7 +203,7 @@ pub fn setFocusRaw(self: *Self, new_focus: FocusTarget) void {
if (build_options.xwayland and self.focused.view.impl == .xwayland_view)
self.focused.view.impl.xwayland_view.xwayland_surface.activate(false);
if (self.focused.view.pending.focus == 0 and !self.focused.view.pending.fullscreen) {
self.focused.view.pending.target_opacity = self.input_manager.server.config.opacity.unfocused;
self.focused.view.pending.target_opacity = server.config.opacity.unfocused;
}
}
@ -216,7 +217,7 @@ pub fn setFocusRaw(self: *Self, new_focus: FocusTarget) void {
if (build_options.xwayland and target_view.impl == .xwayland_view)
target_view.impl.xwayland_view.xwayland_surface.activate(true);
if (!target_view.pending.fullscreen) {
target_view.pending.target_opacity = self.input_manager.server.config.opacity.focused;
target_view.pending.target_opacity = server.config.opacity.focused;
}
},
.layer => |target_layer| std.debug.assert(self.focused_output == target_layer.output),
@ -264,8 +265,6 @@ pub fn setFocusRaw(self: *Self, new_focus: FocusTarget) void {
pub fn focusOutput(self: *Self, output: *Output) void {
if (self.focused_output == output) return;
const root = &self.input_manager.server.root;
var it = self.status_trackers.first;
while (it) |node| : (it = node.next) node.data.sendOutput(.unfocused);
@ -306,7 +305,7 @@ pub fn handleMapping(
modifiers: wlr.Keyboard.ModifierMask,
released: bool,
) bool {
const modes = &self.input_manager.server.config.modes;
const modes = &server.config.modes;
for (modes.items[self.mode_id].mappings.items) |mapping| {
if (std.meta.eql(modifiers, mapping.modifiers) and keysym == mapping.keysym and released == mapping.release) {
// Execute the bound command
@ -409,7 +408,7 @@ fn handleStartDrag(
return;
};
node.data.init(self, wlr_drag_icon);
self.input_manager.server.root.drag_icons.prepend(node);
server.root.drag_icons.prepend(node);
}
self.cursor.mode = .passthrough;
}

View file

@ -115,7 +115,7 @@ pub fn init(self: *Self) !void {
try self.decoration_manager.init(self);
try self.root.init();
// Must be called after root is initialized
try self.input_manager.init(self);
try self.input_manager.init();
try self.control.init(self);
try self.status_manager.init(self);
try self.layout_manager.init(self);

View file

@ -17,6 +17,8 @@
const std = @import("std");
const server = &@import("../main.zig").server;
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
@ -29,7 +31,6 @@ pub fn borderWidth(
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
const server = seat.input_manager.server;
server.config.border_width = try std.fmt.parseInt(u32, args[1], 10);
server.root.arrangeAll();
server.root.startTransaction();
@ -44,7 +45,7 @@ pub fn backgroundColor(
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
seat.input_manager.server.config.background_color = try parseRgba(args[1]);
server.config.background_color = try parseRgba(args[1]);
}
pub fn borderColorFocused(
@ -56,7 +57,7 @@ pub fn borderColorFocused(
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
seat.input_manager.server.config.border_color_focused = try parseRgba(args[1]);
server.config.border_color_focused = try parseRgba(args[1]);
}
pub fn borderColorUnfocused(
@ -68,7 +69,7 @@ pub fn borderColorUnfocused(
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
seat.input_manager.server.config.border_color_unfocused = try parseRgba(args[1]);
server.config.border_color_unfocused = try parseRgba(args[1]);
}
/// Parse a color in the format #RRGGBB or #RRGGBBAA

View file

@ -17,6 +17,7 @@
const std = @import("std");
const server = &@import("../main.zig").server;
const util = @import("../util.zig");
const Mode = @import("../Mode.zig");
@ -34,7 +35,7 @@ pub fn declareMode(
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
const config = &seat.input_manager.server.config;
const config = &server.config;
const new_mode_name = args[1];
if (config.mode_to_id.get(new_mode_name) != null) return;

View file

@ -17,6 +17,8 @@
const std = @import("std");
const server = &@import("../main.zig").server;
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
@ -39,9 +41,8 @@ pub fn enterMode(
return Error.Other;
}
const config = seat.input_manager.server.config;
const target_mode = args[1];
const mode_id = config.mode_to_id.get(target_mode) orelse {
const mode_id = server.config.mode_to_id.get(target_mode) orelse {
out.* = try std.fmt.allocPrint(
allocator,
"cannot enter non-existant mode '{}'",

View file

@ -17,6 +17,8 @@
const std = @import("std");
const server = &@import("../main.zig").server;
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
@ -28,5 +30,5 @@ pub fn exit(
out: *?[]const u8,
) Error!void {
if (args.len > 1) return Error.TooManyArguments;
seat.input_manager.server.wl_server.terminate();
server.wl_server.terminate();
}

View file

@ -17,6 +17,7 @@
const std = @import("std");
const server = &@import("../main.zig").server;
const util = @import("../util.zig");
const Error = @import("../command.zig").Error;
@ -40,7 +41,7 @@ pub fn floatFilterAdd(
) Error!void {
try appendFilter(
allocator,
&seat.input_manager.server.config.float_filter,
&server.config.float_filter,
args,
);
}
@ -53,7 +54,7 @@ pub fn csdFilterAdd(
) Error!void {
try appendFilter(
allocator,
&seat.input_manager.server.config.csd_filter,
&server.config.csd_filter,
args,
);
}

View file

@ -17,6 +17,7 @@
const std = @import("std");
const server = &@import("../main.zig").server;
const util = @import("../util.zig");
const Config = @import("../Config.zig");
@ -32,8 +33,6 @@ pub fn focusFollowsCursor(
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
const server = seat.input_manager.server;
server.config.focus_follows_cursor =
std.meta.stringToEnum(Config.FocusFollowsCursorMode, args[1]) orelse return Error.UnknownOption;
}

View file

@ -17,6 +17,8 @@
const std = @import("std");
const server = &@import("../main.zig").server;
const Direction = @import("../command.zig").Direction;
const Error = @import("../command.zig").Error;
const Output = @import("../Output.zig");
@ -34,21 +36,20 @@ pub fn focusOutput(
if (args.len > 2) return Error.TooManyArguments;
const direction = std.meta.stringToEnum(Direction, args[1]) orelse return Error.InvalidDirection;
const root = &seat.input_manager.server.root;
// If the noop output is focused, there are no other outputs to switch to
if (seat.focused_output == &root.noop_output) {
std.debug.assert(root.outputs.len == 0);
if (seat.focused_output == &server.root.noop_output) {
std.debug.assert(server.root.outputs.len == 0);
return;
}
// Focus the next/prev output in the list if there is one, else wrap
const focused_node = @fieldParentPtr(std.TailQueue(Output).Node, "data", seat.focused_output);
seat.focusOutput(switch (direction) {
.next => if (focused_node.next) |node| &node.data else &root.outputs.first.?.data,
.previous => if (focused_node.prev) |node| &node.data else &root.outputs.last.?.data,
.next => if (focused_node.next) |node| &node.data else &server.root.outputs.first.?.data,
.previous => if (focused_node.prev) |node| &node.data else &server.root.outputs.last.?.data,
});
seat.focus(null);
root.startTransaction();
server.root.startTransaction();
}

View file

@ -20,6 +20,8 @@ const mem = std.mem;
const wl = @import("wayland").server.wl;
const util = @import("../util.zig");
const server = &@import("../main.zig").server;
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
@ -46,7 +48,6 @@ pub fn defaultLayout(
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
const server = seat.input_manager.server;
server.config.default_layout_namespace = try util.gpa.dupe(u8, args[1]);
var it = server.root.all_outputs.first;
while (it) |node| : (it = node.next) {

View file

@ -21,6 +21,7 @@ const wlr = @import("wlroots");
const xkb = @import("xkbcommon");
const c = @import("../c.zig");
const server = &@import("../main.zig").server;
const util = @import("../util.zig");
const Error = @import("../command.zig").Error;
@ -47,7 +48,7 @@ pub fn map(
const modifiers = try parseModifiers(allocator, args[2 + offset], out);
const keysym = try parseKeysym(allocator, args[3 + offset], out);
const mode_mappings = &seat.input_manager.server.config.modes.items[mode_id].mappings;
const mode_mappings = &server.config.modes.items[mode_id].mappings;
const new = try Mapping.init(keysym, modifiers, optionals.release, args[4 + offset ..]);
errdefer new.deinit();
@ -96,7 +97,7 @@ pub fn mapPointer(
.action = action,
};
const mode_pointer_mappings = &seat.input_manager.server.config.modes.items[mode_id].pointer_mappings;
const mode_pointer_mappings = &server.config.modes.items[mode_id].pointer_mappings;
if (pointerMappingExists(mode_pointer_mappings, modifiers, event_code)) |current| {
mode_pointer_mappings.items[current] = new;
} else {
@ -105,7 +106,7 @@ pub fn mapPointer(
}
fn modeNameToId(allocator: *std.mem.Allocator, seat: *Seat, mode_name: []const u8, out: *?[]const u8) !usize {
const config = seat.input_manager.server.config;
const config = &server.config;
return config.mode_to_id.get(mode_name) orelse {
out.* = try std.fmt.allocPrint(
allocator,
@ -255,7 +256,7 @@ pub fn unmap(
const modifiers = try parseModifiers(allocator, args[2 + offset], out);
const keysym = try parseKeysym(allocator, args[3 + offset], out);
const mode_mappings = &seat.input_manager.server.config.modes.items[mode_id].mappings;
const mode_mappings = &server.config.modes.items[mode_id].mappings;
const mapping_idx = mappingExists(mode_mappings, modifiers, keysym, optionals.release) orelse return;
var mapping = mode_mappings.swapRemove(mapping_idx);
@ -279,7 +280,7 @@ pub fn unmapPointer(
const modifiers = try parseModifiers(allocator, args[2], out);
const event_code = try parseEventCode(allocator, args[3], out);
const mode_pointer_mappings = &seat.input_manager.server.config.modes.items[mode_id].pointer_mappings;
const mode_pointer_mappings = &server.config.modes.items[mode_id].pointer_mappings;
const mapping_idx = pointerMappingExists(mode_pointer_mappings, modifiers, event_code) orelse return;
_ = mode_pointer_mappings.swapRemove(mapping_idx);

View file

@ -17,6 +17,8 @@
const std = @import("std");
const server = &@import("../main.zig").server;
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
const View = @import("../View.zig");
@ -36,8 +38,6 @@ pub fn opacity(
if (args.len < 6) return Error.NotEnoughArguments;
if (args.len > 6) return Error.TooManyArguments;
const server = seat.input_manager.server;
// Focused opacity
server.config.opacity.focused = try std.fmt.parseFloat(f32, args[1]);
if (server.config.opacity.focused < 0.0 or server.config.opacity.focused > 1.0)

View file

@ -17,6 +17,8 @@
const std = @import("std");
const server = &@import("../main.zig").server;
const Direction = @import("../command.zig").Direction;
const Error = @import("../command.zig").Error;
const Output = @import("../Output.zig");
@ -34,20 +36,19 @@ pub fn sendToOutput(
if (args.len > 2) return Error.TooManyArguments;
const direction = std.meta.stringToEnum(Direction, args[1]) orelse return Error.InvalidDirection;
const root = &seat.input_manager.server.root;
if (seat.focused == .view) {
// If the noop output is focused, there is nowhere to send the view
if (seat.focused_output == &root.noop_output) {
std.debug.assert(root.outputs.len == 0);
if (seat.focused_output == &server.root.noop_output) {
std.debug.assert(server.root.outputs.len == 0);
return;
}
// Send to the next/prev output in the list if there is one, else wrap
const current_node = @fieldParentPtr(std.TailQueue(Output).Node, "data", seat.focused_output);
const destination_output = switch (direction) {
.next => if (current_node.next) |node| &node.data else &root.outputs.first.?.data,
.previous => if (current_node.prev) |node| &node.data else &root.outputs.last.?.data,
.next => if (current_node.next) |node| &node.data else &server.root.outputs.first.?.data,
.previous => if (current_node.prev) |node| &node.data else &server.root.outputs.last.?.data,
};
// Move the view to the target output
@ -57,6 +58,6 @@ pub fn sendToOutput(
seat.focus(null);
seat.focused_output.arrangeViews();
destination_output.arrangeViews();
root.startTransaction();
server.root.startTransaction();
}
}

View file

@ -17,6 +17,8 @@
const std = @import("std");
const server = &@import("../main.zig").server;
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
@ -33,9 +35,8 @@ pub fn setRepeat(
const rate = try std.fmt.parseInt(u31, args[1], 10);
const delay = try std.fmt.parseInt(u31, args[2], 10);
const config = &seat.input_manager.server.config;
config.repeat_rate = rate;
config.repeat_delay = delay;
server.config.repeat_rate = rate;
server.config.repeat_delay = delay;
var it = seat.keyboards.first;
while (it) |node| : (it = node.next) {