Make Seat a toplevel struct
This commit is contained in:
parent
4c97531860
commit
7ddcebbbab
19 changed files with 236 additions and 238 deletions
|
@ -1,4 +1,4 @@
|
|||
const Seat = @import("seat.zig").Seat;
|
||||
const Seat = @import("seat.zig");
|
||||
|
||||
pub const Direction = enum {
|
||||
Next,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const c = @import("../c.zig");
|
||||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
|
||||
/// Close the focused view, if any.
|
||||
pub fn close_view(seat: *Seat, arg: Arg) void {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const c = @import("../c.zig");
|
||||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
|
||||
/// Exit the compositor, terminating the wayland session.
|
||||
pub fn exitCompositor(seat: *Seat, arg: Arg) void {
|
||||
|
|
|
@ -3,7 +3,7 @@ const std = @import("std");
|
|||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Output = @import("../output.zig").Output;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
|
||||
/// Focus either the next or the previous output, depending on the bool passed.
|
||||
/// Does nothing if there is only one output.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const c = @import("../c.zig");
|
||||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
|
||||
/// Switch focus to the passed tags.
|
||||
pub fn focusTags(seat: *Seat, arg: Arg) void {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const c = @import("../c.zig");
|
||||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
const View = @import("../view.zig").View;
|
||||
const ViewStack = @import("../view_stack.zig").ViewStack;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ const c = @import("../c.zig");
|
|||
const std = @import("std");
|
||||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
|
||||
/// Modify the number of master views
|
||||
pub fn modifyMasterCount(seat: *Seat, arg: Arg) void {
|
||||
|
|
|
@ -2,7 +2,7 @@ const c = @import("../c.zig");
|
|||
const std = @import("std");
|
||||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
|
||||
/// Modify the percent of the width of the screen that the master views occupy.
|
||||
pub fn modifyMasterFactor(seat: *Seat, arg: Arg) void {
|
||||
|
|
|
@ -3,7 +3,7 @@ const std = @import("std");
|
|||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Output = @import("../output.zig").Output;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
|
||||
/// Send the focused view to the the next or the previous output, depending on
|
||||
/// the bool passed. Does nothing if there is only one output.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const c = @import("../c.zig");
|
||||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
|
||||
/// Set the tags of the focused view.
|
||||
pub fn setViewTags(seat: *Seat, arg: Arg) void {
|
||||
|
|
|
@ -3,7 +3,7 @@ const std = @import("std");
|
|||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Log = @import("../log.zig").Log;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
|
||||
/// Spawn a program.
|
||||
pub fn spawn(seat: *Seat, arg: Arg) void {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const c = @import("../c.zig");
|
||||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
|
||||
/// Make the focused view float or stop floating, depending on its current
|
||||
/// state.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const c = @import("../c.zig");
|
||||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
|
||||
/// Toggle focus of the passsed tags.
|
||||
pub fn toggleTags(seat: *Seat, arg: Arg) void {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const c = @import("../c.zig");
|
||||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
|
||||
/// Toggle the passed tags of the focused view
|
||||
pub fn toggleViewTags(seat: *Seat, arg: Arg) void {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const c = @import("../c.zig");
|
||||
|
||||
const Arg = @import("../command.zig").Arg;
|
||||
const Seat = @import("../seat.zig").Seat;
|
||||
const Seat = @import("../seat.zig");
|
||||
const View = @import("../view.zig").View;
|
||||
const ViewStack = @import("../view_stack.zig").ViewStack;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ const c = @import("c.zig");
|
|||
const LayerSurface = @import("layer_surface.zig").LayerSurface;
|
||||
const Log = @import("log.zig").Log;
|
||||
const Output = @import("output.zig").Output;
|
||||
const Seat = @import("seat.zig").Seat;
|
||||
const Seat = @import("seat.zig");
|
||||
const View = @import("view.zig").View;
|
||||
const ViewStack = @import("view_stack.zig").ViewStack;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ const std = @import("std");
|
|||
const c = @import("c.zig");
|
||||
|
||||
const Log = @import("log.zig").Log;
|
||||
const Seat = @import("seat.zig").Seat;
|
||||
const Seat = @import("seat.zig");
|
||||
const Server = @import("server.zig");
|
||||
|
||||
const default_seat_name = "default";
|
||||
|
|
|
@ -2,7 +2,7 @@ const std = @import("std");
|
|||
const c = @import("c.zig");
|
||||
|
||||
const Log = @import("log.zig").Log;
|
||||
const Seat = @import("seat.zig").Seat;
|
||||
const Seat = @import("seat.zig");
|
||||
|
||||
pub const Keyboard = struct {
|
||||
const Self = @This();
|
||||
|
|
100
src/seat.zig
100
src/seat.zig
|
@ -1,3 +1,5 @@
|
|||
const Self = @This();
|
||||
|
||||
const c = @import("c.zig");
|
||||
const std = @import("std");
|
||||
|
||||
|
@ -15,35 +17,32 @@ const FocusTarget = union(enum) {
|
|||
none: void,
|
||||
};
|
||||
|
||||
pub const Seat = struct {
|
||||
const Self = @This();
|
||||
input_manager: *InputManager,
|
||||
wlr_seat: *c.wlr_seat,
|
||||
|
||||
input_manager: *InputManager,
|
||||
wlr_seat: *c.wlr_seat,
|
||||
/// Multiple mice are handled by the same Cursor
|
||||
cursor: Cursor,
|
||||
|
||||
/// Multiple mice are handled by the same Cursor
|
||||
cursor: Cursor,
|
||||
/// Mulitple keyboards are handled separately
|
||||
keyboards: std.TailQueue(Keyboard),
|
||||
|
||||
/// Mulitple keyboards are handled separately
|
||||
keyboards: std.TailQueue(Keyboard),
|
||||
/// Currently focused output, may be the noop output if no
|
||||
focused_output: *Output,
|
||||
|
||||
/// Currently focused output, may be the noop output if no
|
||||
focused_output: *Output,
|
||||
/// Currently focused view if any
|
||||
focused_view: ?*View,
|
||||
|
||||
/// Currently focused view if any
|
||||
focused_view: ?*View,
|
||||
/// Stack of views in most recently focused order
|
||||
/// If there is a currently focused view, it is on top.
|
||||
focus_stack: ViewStack(*View),
|
||||
|
||||
/// Stack of views in most recently focused order
|
||||
/// If there is a currently focused view, it is on top.
|
||||
focus_stack: ViewStack(*View),
|
||||
/// Currently focused layer, if any. While this is non-null, no views may
|
||||
/// recieve focus.
|
||||
focused_layer: ?*LayerSurface,
|
||||
|
||||
/// Currently focused layer, if any. While this is non-null, no views may
|
||||
/// recieve focus.
|
||||
focused_layer: ?*LayerSurface,
|
||||
listen_request_set_selection: c.wl_listener,
|
||||
|
||||
listen_request_set_selection: c.wl_listener,
|
||||
|
||||
pub fn init(self: *Self, input_manager: *InputManager, name: []const u8) !void {
|
||||
pub fn init(self: *Self, input_manager: *InputManager, name: []const u8) !void {
|
||||
self.input_manager = input_manager;
|
||||
|
||||
// This will be automatically destroyed when the display is destroyed
|
||||
|
@ -65,9 +64,9 @@ pub const Seat = struct {
|
|||
|
||||
self.listen_request_set_selection.notify = handleRequestSetSelection;
|
||||
c.wl_signal_add(&self.wlr_seat.events.request_set_selection, &self.listen_request_set_selection);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
pub fn deinit(self: *Self) void {
|
||||
self.cursor.deinit();
|
||||
|
||||
while (self.keyboards.pop()) |node| {
|
||||
|
@ -78,11 +77,11 @@ pub const Seat = struct {
|
|||
self.focus_stack.remove(node);
|
||||
self.input_manager.server.allocator.destroy(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the current focus. If a visible view is passed it will be focused.
|
||||
/// If null is passed, the first visible view in the focus stack will be focused.
|
||||
pub fn focus(self: *Self, _view: ?*View) void {
|
||||
/// Set the current focus. If a visible view is passed it will be focused.
|
||||
/// If null is passed, the first visible view in the focus stack will be focused.
|
||||
pub fn focus(self: *Self, _view: ?*View) void {
|
||||
var view = _view;
|
||||
|
||||
// While a layer surface is focused, views may not recieve focus
|
||||
|
@ -134,11 +133,11 @@ pub const Seat = struct {
|
|||
// Otherwise clear the focus
|
||||
self.setFocusRaw(.{ .none = {} });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Switch focus to the target, handling unfocus and input inhibition
|
||||
/// properly. This should only be called directly if dealing with layers.
|
||||
pub fn setFocusRaw(self: *Self, focus_target: FocusTarget) void {
|
||||
/// Switch focus to the target, handling unfocus and input inhibition
|
||||
/// properly. This should only be called directly if dealing with layers.
|
||||
pub fn setFocusRaw(self: *Self, focus_target: FocusTarget) void {
|
||||
// If the target is already focused, do nothing
|
||||
if (switch (focus_target) {
|
||||
.view => |target_view| target_view == self.focused_view,
|
||||
|
@ -200,11 +199,11 @@ pub const Seat = struct {
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle the unmapping of a view, removing it from the focus stack and
|
||||
/// setting the focus if needed.
|
||||
pub fn handleViewUnmap(self: *Self, view: *View) void {
|
||||
/// Handle the unmapping of a view, removing it from the focus stack and
|
||||
/// setting the focus if needed.
|
||||
pub fn handleViewUnmap(self: *Self, view: *View) void {
|
||||
// Remove the node from the focus stack and destroy it.
|
||||
var it = self.focus_stack.first;
|
||||
while (it) |node| : (it = node.next) {
|
||||
|
@ -221,11 +220,11 @@ pub const Seat = struct {
|
|||
self.focus(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle any user-defined keybinding for the passed keysym and modifiers
|
||||
/// Returns true if the key was handled
|
||||
pub fn handleKeybinding(self: *Self, keysym: c.xkb_keysym_t, modifiers: u32) bool {
|
||||
/// Handle any user-defined keybinding for the passed keysym and modifiers
|
||||
/// Returns true if the key was handled
|
||||
pub fn handleKeybinding(self: *Self, keysym: c.xkb_keysym_t, modifiers: u32) bool {
|
||||
for (self.input_manager.server.config.keybinds.items) |keybind| {
|
||||
if (modifiers == keybind.modifiers and keysym == keybind.keysym) {
|
||||
// Execute the bound command
|
||||
|
@ -234,11 +233,11 @@ pub const Seat = struct {
|
|||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Add a newly created input device to the seat and update the reported
|
||||
/// capabilities.
|
||||
pub fn addDevice(self: *Self, device: *c.wlr_input_device) !void {
|
||||
/// Add a newly created input device to the seat and update the reported
|
||||
/// capabilities.
|
||||
pub fn addDevice(self: *Self, device: *c.wlr_input_device) !void {
|
||||
switch (device.type) {
|
||||
.WLR_INPUT_DEVICE_KEYBOARD => self.addKeyboard(device) catch unreachable,
|
||||
.WLR_INPUT_DEVICE_POINTER => self.addPointer(device),
|
||||
|
@ -254,30 +253,29 @@ pub const Seat = struct {
|
|||
caps |= @intCast(u32, c.WL_SEAT_CAPABILITY_KEYBOARD);
|
||||
}
|
||||
c.wlr_seat_set_capabilities(self.wlr_seat, caps);
|
||||
}
|
||||
}
|
||||
|
||||
fn addKeyboard(self: *Self, device: *c.wlr_input_device) !void {
|
||||
fn addKeyboard(self: *Self, device: *c.wlr_input_device) !void {
|
||||
c.wlr_seat_set_keyboard(self.wlr_seat, device);
|
||||
|
||||
const node = try self.keyboards.allocateNode(self.input_manager.server.allocator);
|
||||
try node.data.init(self, device);
|
||||
self.keyboards.append(node);
|
||||
}
|
||||
}
|
||||
|
||||
fn addPointer(self: Self, device: *c.struct_wlr_input_device) void {
|
||||
fn addPointer(self: Self, device: *c.struct_wlr_input_device) void {
|
||||
// We don't do anything special with pointers. All of our pointer handling
|
||||
// is proxied through wlr_cursor. On another compositor, you might take this
|
||||
// opportunity to do libinput configuration on the device to set
|
||||
// acceleration, etc.
|
||||
c.wlr_cursor_attach_input_device(self.cursor.wlr_cursor, device);
|
||||
}
|
||||
}
|
||||
|
||||
fn handleRequestSetSelection(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||
fn handleRequestSetSelection(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||
const self = @fieldParentPtr(Self, "listen_request_set_selection", listener.?);
|
||||
const event = @ptrCast(
|
||||
*c.wlr_seat_request_set_selection_event,
|
||||
@alignCast(@alignOf(*c.wlr_seat_request_set_selection_event), data),
|
||||
);
|
||||
c.wlr_seat_set_selection(self.wlr_seat, event.source, event.serial);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue