aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/command.zig28
-rw-r--r--src/input_manager.zig2
-rw-r--r--src/root.zig16
-rw-r--r--src/seat.zig16
-rw-r--r--src/server.zig2
5 files changed, 38 insertions, 26 deletions
diff --git a/src/command.zig b/src/command.zig
index 347a1d7..1062d4a 100644
--- a/src/command.zig
+++ b/src/command.zig
@@ -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
/// passed.
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 there is a currently focused view, focus the next visible view in the stack.
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
pub fn modifyMasterCount(seat: *Seat, arg: Arg) void {
const delta = arg.int;
- const root = &seat.input_manager.server.root;
- const output = root.focusedOutput();
+ const output = seat.focused_output;
output.master_count = @intCast(
u32,
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.
pub fn modifyMasterFactor(seat: *Seat, arg: Arg) void {
const delta = arg.float;
- const root = &seat.input_manager.server.root;
- const output = root.focusedOutput();
+ const output = seat.focused_output;
const new_master_factor = std.math.min(
std.math.max(output.master_factor + delta, 0.05),
0.95,
);
if (new_master_factor != output.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.
pub fn zoom(seat: *Seat, arg: Arg) void {
if (seat.focused_view) |current_focus| {
- const root = &seat.input_manager.server.root;
- const output = root.focusedOutput();
+ const output = seat.focused_output;
const node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus);
if (node != output.views.first) {
output.views.remove(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.
pub fn focusTags(seat: *Seat, arg: Arg) void {
const tags = arg.uint;
- const root = &seat.input_manager.server.root;
- const output = root.focusedOutput();
- output.pending_focused_tags = tags;
- root.arrange();
+ seat.focused_output.pending_focused_tags = tags;
+ seat.input_manager.server.root.arrange();
}
/// Toggle focus of the passsed tags.
pub fn toggleTags(seat: *Seat, arg: Arg) void {
const tags = arg.uint;
- const root = &seat.input_manager.server.root;
- const output = root.focusedOutput();
+ const output = seat.focused_output;
const new_focused_tags = output.current_focused_tags ^ tags;
if (new_focused_tags != 0) {
output.pending_focused_tags = new_focused_tags;
- root.arrange();
+ seat.input_manager.server.root.arrange();
}
}
diff --git a/src/input_manager.zig b/src/input_manager.zig
index 5021538..6f4d7ae 100644
--- a/src/input_manager.zig
+++ b/src/input_manager.zig
@@ -12,6 +12,7 @@ pub const InputManager = struct {
server: *Server,
seats: std.TailQueue(Seat),
+ default_seat: *Seat,
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);
try seat_node.data.init(self, default_seat_name);
+ self.default_seat = &seat_node.data;
self.seats.prepend(seat_node);
// Set up handler for all new input devices made available. This
diff --git a/src/root.zig b/src/root.zig
index bbda4b9..8a101fa 100644
--- a/src/root.zig
+++ b/src/root.zig
@@ -19,7 +19,8 @@ pub const Root = struct {
wlr_output_layout: *c.wlr_output_layout,
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,
/// 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;
node.data.init(self, wlr_output) catch unreachable;
self.outputs.append(node);
- }
- /// TODO: move this to seat, it's just a stop gap hack
- pub fn focusedOutput(self: Self) *Output {
- return &self.outputs.first.?.data;
+ // if we previously had no real outputs, move focus from the noop output
+ // to the new one.
+ 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
diff --git a/src/seat.zig b/src/seat.zig
index 34cdbfa..d694970 100644
--- a/src/seat.zig
+++ b/src/seat.zig
@@ -2,9 +2,10 @@ const std = @import("std");
const c = @import("c.zig");
const Cursor = @import("cursor.zig").Cursor;
-const Log = @import("log.zig").Log;
const InputManager = @import("input_manager.zig").InputManager;
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 ViewStack = @import("view_stack.zig").ViewStack;
@@ -20,6 +21,9 @@ pub const Seat = struct {
/// Mulitple keyboards are handled separately
keyboards: std.TailQueue(Keyboard),
+ /// Currently focused output, may be the noop output if no
+ focused_output: *Output,
+
/// Currently focused view if any
focused_view: ?*View,
@@ -39,6 +43,8 @@ pub const Seat = struct {
self.keyboards = std.TailQueue(Keyboard).init();
+ self.focused_output = &self.input_manager.server.root.noop_output;
+
self.focused_view = null;
self.focus_stack.init();
@@ -54,11 +60,15 @@ pub const Seat = struct {
var view = _view;
// 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
view = if (ViewStack(*View).iterator(
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;
}
diff --git a/src/server.zig b/src/server.zig
index 0bb2118..a165b5d 100644
--- a/src/server.zig
+++ b/src/server.zig
@@ -145,7 +145,7 @@ pub const Server = struct {
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.