seat: clean up initialization

This commit is contained in:
Isaac Freund 2020-08-21 19:08:52 +02:00
parent 37ea1bac36
commit 71a751f1ad
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
3 changed files with 50 additions and 70 deletions

View file

@ -212,34 +212,35 @@ wlr_cursor: *c.wlr_cursor,
wlr_xcursor_manager: *c.wlr_xcursor_manager, wlr_xcursor_manager: *c.wlr_xcursor_manager,
/// Number of distinct buttons currently pressed /// Number of distinct buttons currently pressed
pressed_count: u32, pressed_count: u32 = 0,
/// Current cursor mode as well as any state needed to implement that mode /// Current cursor mode as well as any state needed to implement that mode
mode: Mode, mode: Mode = .passthrough,
listen_axis: c.wl_listener, listen_axis: c.wl_listener = undefined,
listen_button: c.wl_listener, listen_button: c.wl_listener = undefined,
listen_frame: c.wl_listener, listen_frame: c.wl_listener = undefined,
listen_motion_absolute: c.wl_listener, listen_motion_absolute: c.wl_listener = undefined,
listen_motion: c.wl_listener, listen_motion: c.wl_listener = undefined,
listen_request_set_cursor: c.wl_listener, listen_request_set_cursor: c.wl_listener = undefined,
pub fn init(self: *Self, seat: *Seat) !void { pub fn init(self: *Self, seat: *Seat) !void {
self.seat = seat; const wlr_cursor = c.wlr_cursor_create() orelse return error.OutOfMemory;
errdefer c.wlr_cursor_destroy(wlr_cursor);
// Creates a wlroots utility for tracking the cursor image shown on screen. c.wlr_cursor_attach_output_layout(wlr_cursor, seat.input_manager.server.root.wlr_output_layout);
self.wlr_cursor = c.wlr_cursor_create() orelse return error.OutOfMemory;
c.wlr_cursor_attach_output_layout(self.wlr_cursor, seat.input_manager.server.root.wlr_output_layout);
// This is here so that self.wlr_xcursor_manager doesn't need to be an // This is here so that self.wlr_xcursor_manager doesn't need to be an
// optional pointer. This isn't optimal as it does a needless allocation, // optional pointer. This isn't optimal as it does a needless allocation,
// but this is not a hot path. // but this is not a hot path.
self.wlr_xcursor_manager = c.wlr_xcursor_manager_create(null, default_size) orelse const wlr_xcursor_manager = c.wlr_xcursor_manager_create(null, default_size) orelse return error.OutOfMemory;
return error.OutOfMemory; errdefer c.wlr_xcursor_manager_destroy(wlr_xcursor_manager);
try self.setTheme(null, null);
self.pressed_count = 0; self.* = .{
self.mode = .passthrough; .seat = seat,
.wlr_cursor = wlr_cursor,
.wlr_xcursor_manager = wlr_xcursor_manager,
};
try self.setTheme(null, null);
// wlr_cursor *only* displays an image on screen. It does not move around // wlr_cursor *only* displays an image on screen. It does not move around
// when the pointer moves. However, we can attach input devices to it, and // when the pointer moves. However, we can attach input devices to it, and

View file

@ -35,46 +35,38 @@ server: *Server,
wlr_idle: *c.wlr_idle, wlr_idle: *c.wlr_idle,
wlr_input_inhibit_manager: *c.wlr_input_inhibit_manager, wlr_input_inhibit_manager: *c.wlr_input_inhibit_manager,
seats: std.TailQueue(Seat), seats: std.TailQueue(Seat) = std.TailQueue(Seat).init(),
default_seat: *Seat, default_seat: *Seat,
exclusive_client: ?*c.wl_client, exclusive_client: ?*c.wl_client = null,
listen_inhibit_activate: c.wl_listener, listen_inhibit_activate: c.wl_listener = undefined,
listen_inhibit_deactivate: c.wl_listener, listen_inhibit_deactivate: c.wl_listener = undefined,
listen_new_input: c.wl_listener, listen_new_input: c.wl_listener = undefined,
pub fn init(self: *Self, server: *Server) !void { pub fn init(self: *Self, server: *Server) !void {
self.server = server;
// These are automatically freed when the display is destroyed
self.wlr_idle = c.wlr_idle_create(server.wl_display) orelse return error.OutOfMemory;
self.wlr_input_inhibit_manager = c.wlr_input_inhibit_manager_create(server.wl_display) orelse
return error.OutOfMemory;
self.seats = std.TailQueue(Seat).init();
const seat_node = try util.gpa.create(std.TailQueue(Seat).Node); const seat_node = try util.gpa.create(std.TailQueue(Seat).Node);
self.* = .{
.server = server,
// These are automatically freed when the display is destroyed
.wlr_idle = c.wlr_idle_create(server.wl_display) orelse return error.OutOfMemory,
.wlr_input_inhibit_manager = c.wlr_input_inhibit_manager_create(server.wl_display) orelse
return error.OutOfMemory,
.default_seat = &seat_node.data,
};
try seat_node.data.init(self, default_seat_name); try seat_node.data.init(self, default_seat_name);
self.default_seat = &seat_node.data;
self.seats.prepend(seat_node); self.seats.prepend(seat_node);
if (build_options.xwayland) c.wlr_xwayland_set_seat(server.wlr_xwayland, self.default_seat.wlr_seat); if (build_options.xwayland) c.wlr_xwayland_set_seat(server.wlr_xwayland, self.default_seat.wlr_seat);
self.exclusive_client = null;
// Set up all listeners // Set up all listeners
self.listen_inhibit_activate.notify = handleInhibitActivate; self.listen_inhibit_activate.notify = handleInhibitActivate;
c.wl_signal_add( c.wl_signal_add(&self.wlr_input_inhibit_manager.events.activate, &self.listen_inhibit_activate);
&self.wlr_input_inhibit_manager.events.activate,
&self.listen_inhibit_activate,
);
self.listen_inhibit_deactivate.notify = handleInhibitDeactivate; self.listen_inhibit_deactivate.notify = handleInhibitDeactivate;
c.wl_signal_add( c.wl_signal_add(&self.wlr_input_inhibit_manager.events.deactivate, &self.listen_inhibit_deactivate);
&self.wlr_input_inhibit_manager.events.deactivate,
&self.listen_inhibit_deactivate,
);
self.listen_new_input.notify = handleNewInput; self.listen_new_input.notify = handleNewInput;
c.wl_signal_add(&self.server.wlr_backend.events.new_input, &self.listen_new_input); c.wl_signal_add(&self.server.wlr_backend.events.new_input, &self.listen_new_input);

View file

@ -44,55 +44,42 @@ input_manager: *InputManager,
wlr_seat: *c.wlr_seat, wlr_seat: *c.wlr_seat,
/// Multiple mice are handled by the same Cursor /// Multiple mice are handled by the same Cursor
cursor: Cursor, cursor: Cursor = undefined,
/// Mulitple keyboards are handled separately /// Mulitple keyboards are handled separately
keyboards: std.TailQueue(Keyboard), keyboards: std.TailQueue(Keyboard) = std.TailQueue(Keyboard).init(),
/// ID of the current keymap mode /// ID of the current keymap mode
mode_id: usize, mode_id: usize = 0,
/// Currently focused output, may be the noop output if no /// Currently focused output, may be the noop output if no
focused_output: *Output, focused_output: *Output,
/// Currently focused view/layer surface if any /// Currently focused view/layer surface if any
focused: FocusTarget, focused: FocusTarget = .none,
/// Stack of views in most recently focused order /// Stack of views in most recently focused order
/// If there is a currently focused view, it is on top. /// If there is a currently focused view, it is on top.
focus_stack: ViewStack(*View), focus_stack: ViewStack(*View) = ViewStack(*View){},
/// List of status tracking objects relaying changes to this seat to clients. /// List of status tracking objects relaying changes to this seat to clients.
status_trackers: std.SinglyLinkedList(SeatStatus), status_trackers: std.SinglyLinkedList(SeatStatus) = std.SinglyLinkedList(SeatStatus).init(),
/// State of pointer modifier; Used for pointer operations such as move ans resize. /// State of pointer modifier; Used for pointer operations such as move ans resize.
pointer_modifier: bool, pointer_modifier: bool = false,
listen_request_set_selection: c.wl_listener, listen_request_set_selection: c.wl_listener = undefined,
pub fn init(self: *Self, input_manager: *InputManager, name: [*:0]const u8) !void { pub fn init(self: *Self, input_manager: *InputManager, name: [*:0]const u8) !void {
self.input_manager = input_manager; self.* = .{
.input_manager = input_manager,
// This will be automatically destroyed when the display is destroyed // This will be automatically destroyed when the display is destroyed
self.wlr_seat = c.wlr_seat_create(input_manager.server.wl_display, name) orelse return error.OutOfMemory; .wlr_seat = c.wlr_seat_create(input_manager.server.wl_display, name) orelse return error.OutOfMemory,
.focused_output = &self.input_manager.server.root.noop_output,
};
self.wlr_seat.data = self; self.wlr_seat.data = self;
try self.cursor.init(self); try self.cursor.init(self);
errdefer self.cursor.deinit();
self.keyboards = std.TailQueue(Keyboard).init();
self.mode_id = 0;
self.focused_output = &self.input_manager.server.root.noop_output;
self.focused = .none;
self.focus_stack = ViewStack(*View){};
self.status_trackers = std.SinglyLinkedList(SeatStatus).init();
self.pointer_modifier = false;
self.listen_request_set_selection.notify = handleRequestSetSelection; self.listen_request_set_selection.notify = handleRequestSetSelection;
c.wl_signal_add(&self.wlr_seat.events.request_set_selection, &self.listen_request_set_selection); c.wl_signal_add(&self.wlr_seat.events.request_set_selection, &self.listen_request_set_selection);