Track the focused output of seats

This commit is contained in:
Isaac Freund 2020-04-15 17:59:46 +02:00
parent a6eeb5bbba
commit 2283ee78b5
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
5 changed files with 38 additions and 26 deletions

View file

@ -24,7 +24,7 @@ pub fn exitCompositor(seat: *Seat, arg: Arg) void {
/// Focus either the next or the previous visible view, depending on the bool /// Focus either the next or the previous visible view, depending on the bool
/// passed. /// passed.
fn focusNextPrevView(seat: *Seat, next: bool) void { fn focusNextPrevView(seat: *Seat, next: bool) void {
const output = seat.input_manager.server.root.focusedOutput(); const output = seat.focused_output;
if (seat.focused_view) |current_focus| { if (seat.focused_view) |current_focus| {
// If there is a currently focused view, focus the next visible view in the stack. // If there is a currently focused view, focus the next visible view in the stack.
const focused_node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus); const focused_node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus);
@ -66,27 +66,25 @@ pub fn focusPrevView(seat: *Seat, arg: Arg) void {
/// Modify the number of master views /// Modify the number of master views
pub fn modifyMasterCount(seat: *Seat, arg: Arg) void { pub fn modifyMasterCount(seat: *Seat, arg: Arg) void {
const delta = arg.int; const delta = arg.int;
const root = &seat.input_manager.server.root; const output = seat.focused_output;
const output = root.focusedOutput();
output.master_count = @intCast( output.master_count = @intCast(
u32, u32,
std.math.max(0, @intCast(i32, output.master_count) + delta), std.math.max(0, @intCast(i32, output.master_count) + delta),
); );
root.arrange(); seat.input_manager.server.root.arrange();
} }
/// Modify the percent of the width of the screen that the master views occupy. /// Modify the percent of the width of the screen that the master views occupy.
pub fn modifyMasterFactor(seat: *Seat, arg: Arg) void { pub fn modifyMasterFactor(seat: *Seat, arg: Arg) void {
const delta = arg.float; const delta = arg.float;
const root = &seat.input_manager.server.root; const output = seat.focused_output;
const output = root.focusedOutput();
const new_master_factor = std.math.min( const new_master_factor = std.math.min(
std.math.max(output.master_factor + delta, 0.05), std.math.max(output.master_factor + delta, 0.05),
0.95, 0.95,
); );
if (new_master_factor != output.master_factor) { if (new_master_factor != output.master_factor) {
output.master_factor = new_master_factor; output.master_factor = new_master_factor;
root.arrange(); seat.input_manager.server.root.arrange();
} }
} }
@ -94,13 +92,12 @@ pub fn modifyMasterFactor(seat: *Seat, arg: Arg) void {
/// TODO: if the top of the stack is focused, bump the next visible view. /// TODO: if the top of the stack is focused, bump the next visible view.
pub fn zoom(seat: *Seat, arg: Arg) void { pub fn zoom(seat: *Seat, arg: Arg) void {
if (seat.focused_view) |current_focus| { if (seat.focused_view) |current_focus| {
const root = &seat.input_manager.server.root; const output = seat.focused_output;
const output = root.focusedOutput();
const node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus); const node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus);
if (node != output.views.first) { if (node != output.views.first) {
output.views.remove(node); output.views.remove(node);
output.views.push(node); output.views.push(node);
root.arrange(); seat.input_manager.server.root.arrange();
} }
} }
} }
@ -108,21 +105,18 @@ pub fn zoom(seat: *Seat, arg: Arg) void {
/// Switch focus to the passed tags. /// Switch focus to the passed tags.
pub fn focusTags(seat: *Seat, arg: Arg) void { pub fn focusTags(seat: *Seat, arg: Arg) void {
const tags = arg.uint; const tags = arg.uint;
const root = &seat.input_manager.server.root; seat.focused_output.pending_focused_tags = tags;
const output = root.focusedOutput(); seat.input_manager.server.root.arrange();
output.pending_focused_tags = tags;
root.arrange();
} }
/// Toggle focus of the passsed tags. /// Toggle focus of the passsed tags.
pub fn toggleTags(seat: *Seat, arg: Arg) void { pub fn toggleTags(seat: *Seat, arg: Arg) void {
const tags = arg.uint; const tags = arg.uint;
const root = &seat.input_manager.server.root; const output = seat.focused_output;
const output = root.focusedOutput();
const new_focused_tags = output.current_focused_tags ^ tags; const new_focused_tags = output.current_focused_tags ^ tags;
if (new_focused_tags != 0) { if (new_focused_tags != 0) {
output.pending_focused_tags = new_focused_tags; output.pending_focused_tags = new_focused_tags;
root.arrange(); seat.input_manager.server.root.arrange();
} }
} }

View file

@ -12,6 +12,7 @@ pub const InputManager = struct {
server: *Server, server: *Server,
seats: std.TailQueue(Seat), seats: std.TailQueue(Seat),
default_seat: *Seat,
listen_new_input: c.wl_listener, listen_new_input: c.wl_listener,
@ -22,6 +23,7 @@ pub const InputManager = struct {
const seat_node = try server.allocator.create(std.TailQueue(Seat).Node); const seat_node = try server.allocator.create(std.TailQueue(Seat).Node);
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);
// Set up handler for all new input devices made available. This // Set up handler for all new input devices made available. This

View file

@ -19,7 +19,8 @@ pub const Root = struct {
wlr_output_layout: *c.wlr_output_layout, wlr_output_layout: *c.wlr_output_layout,
outputs: std.TailQueue(Output), outputs: std.TailQueue(Output),
/// This output is used when no real outputs are available. /// This output is used internally when no real outputs are available.
/// It is not advertised to clients.
noop_output: Output, noop_output: Output,
/// Number of pending configures sent in the current transaction. /// Number of pending configures sent in the current transaction.
@ -58,11 +59,16 @@ pub const Root = struct {
const node = self.outputs.allocateNode(self.server.allocator) catch unreachable; const node = self.outputs.allocateNode(self.server.allocator) catch unreachable;
node.data.init(self, wlr_output) catch unreachable; node.data.init(self, wlr_output) catch unreachable;
self.outputs.append(node); self.outputs.append(node);
}
/// TODO: move this to seat, it's just a stop gap hack // if we previously had no real outputs, move focus from the noop output
pub fn focusedOutput(self: Self) *Output { // to the new one.
return &self.outputs.first.?.data; if (self.outputs.len == 1) {
// TODO: move views from the noop output to the new one and focus(null)
var it = self.server.input_manager.seats.first;
while (it) |seat_node| : (it = seat_node.next) {
seat_node.data.focused_output = &self.outputs.first.?.data;
}
}
} }
/// Finds the topmost view under the output layout coordinates lx, ly /// Finds the topmost view under the output layout coordinates lx, ly

View file

@ -2,9 +2,10 @@ const std = @import("std");
const c = @import("c.zig"); const c = @import("c.zig");
const Cursor = @import("cursor.zig").Cursor; const Cursor = @import("cursor.zig").Cursor;
const Log = @import("log.zig").Log;
const InputManager = @import("input_manager.zig").InputManager; const InputManager = @import("input_manager.zig").InputManager;
const Keyboard = @import("keyboard.zig").Keyboard; const Keyboard = @import("keyboard.zig").Keyboard;
const Log = @import("log.zig").Log;
const Output = @import("output.zig").Output;
const View = @import("view.zig").View; const View = @import("view.zig").View;
const ViewStack = @import("view_stack.zig").ViewStack; const ViewStack = @import("view_stack.zig").ViewStack;
@ -20,6 +21,9 @@ pub const Seat = struct {
/// Mulitple keyboards are handled separately /// Mulitple keyboards are handled separately
keyboards: std.TailQueue(Keyboard), keyboards: std.TailQueue(Keyboard),
/// Currently focused output, may be the noop output if no
focused_output: *Output,
/// Currently focused view if any /// Currently focused view if any
focused_view: ?*View, focused_view: ?*View,
@ -39,6 +43,8 @@ pub const Seat = struct {
self.keyboards = std.TailQueue(Keyboard).init(); self.keyboards = std.TailQueue(Keyboard).init();
self.focused_output = &self.input_manager.server.root.noop_output;
self.focused_view = null; self.focused_view = null;
self.focus_stack.init(); self.focus_stack.init();
@ -54,11 +60,15 @@ pub const Seat = struct {
var view = _view; var view = _view;
// If view is null or not currently visible // If view is null or not currently visible
if (if (view) |v| v.current_tags & v.output.current_focused_tags == 0 else true) { if (if (view) |v|
v.output != self.focused_output or
v.current_tags & self.focused_output.current_focused_tags == 0
else
true) {
// Set view to the first currently visible view in the focus stack if any // Set view to the first currently visible view in the focus stack if any
view = if (ViewStack(*View).iterator( view = if (ViewStack(*View).iterator(
self.focus_stack.first, self.focus_stack.first,
self.input_manager.server.root.focusedOutput().current_focused_tags, self.focused_output.current_focused_tags,
).next()) |node| node.view else null; ).next()) |node| node.view else null;
} }

View file

@ -145,7 +145,7 @@ pub const Server = struct {
return; return;
} }
server.root.focusedOutput().addView(wlr_xdg_surface); server.input_manager.default_seat.focused_output.addView(wlr_xdg_surface);
} }
/// This event is raised when the layer_shell recieves a new surface from a client. /// This event is raised when the layer_shell recieves a new surface from a client.