river: remove Output.root

The server is now global so this is no longer needed.
This commit is contained in:
Isaac Freund 2021-05-13 14:35:36 +02:00
parent 89e0d4c083
commit ac27db236a
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
13 changed files with 48 additions and 45 deletions

View file

@ -26,6 +26,7 @@ const wl = wayland.server.wl;
const zwlr = wayland.server.zwlr; const zwlr = wayland.server.zwlr;
const c = @import("c.zig"); const c = @import("c.zig");
const server = &@import("main.zig").server;
const util = @import("util.zig"); const util = @import("util.zig");
const Box = @import("Box.zig"); const Box = @import("Box.zig");
@ -138,7 +139,6 @@ pub fn deinit(self: *Self) void {
/// this is the default seat. Either argument may be null, in which case a /// this is the default seat. Either argument may be null, in which case a
/// default will be used. /// default will be used.
pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void { pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void {
const server = self.seat.input_manager.server;
const size = _size orelse default_size; const size = _size orelse default_size;
self.xcursor_manager.destroy(); self.xcursor_manager.destroy();
@ -536,7 +536,7 @@ pub fn enterMode(self: *Self, mode: @TagType(Mode), view: *View) void {
.passthrough => unreachable, .passthrough => unreachable,
.down => { .down => {
self.mode = .{ .down = view }; self.mode = .{ .down = view };
view.output.root.startTransaction(); server.root.startTransaction();
}, },
.move, .resize => { .move, .resize => {
const cur_box = &view.current.box; const cur_box = &view.current.box;
@ -626,7 +626,7 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64,
.down => |view| { .down => |view| {
self.wlr_cursor.move(device, dx, dy); self.wlr_cursor.move(device, dx, dy);
// This takes surface-local coordinates // This takes surface-local coordinates
const output_box = view.output.root.output_layout.getBox(view.output.wlr_output).?; const output_box = server.root.output_layout.getBox(view.output.wlr_output).?;
self.seat.wlr_seat.pointerNotifyMotion( self.seat.wlr_seat.pointerNotifyMotion(
time, time,
self.wlr_cursor.x - @intToFloat(f64, output_box.x + view.current.box.x - view.surface_box.x), self.wlr_cursor.x - @intToFloat(f64, output_box.x + view.current.box.x - view.surface_box.x),

View file

@ -129,7 +129,7 @@ fn handleUnmap(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *
seat.focus(null); seat.focus(null);
} }
self.output.root.startTransaction(); server.root.startTransaction();
} }
fn handleCommit(listener: *wl.Listener(*wlr.Surface), wlr_surface: *wlr.Surface) void { fn handleCommit(listener: *wl.Listener(*wlr.Surface), wlr_surface: *wlr.Surface) void {
@ -152,7 +152,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), wlr_surface: *wlr.Surface)
self.state = new_state.*; self.state = new_state.*;
self.output.arrangeLayers(); self.output.arrangeLayers();
self.output.root.startTransaction(); server.root.startTransaction();
} }
} }

View file

@ -24,6 +24,7 @@ const wayland = @import("wayland");
const wl = wayland.server.wl; const wl = wayland.server.wl;
const river = wayland.server.river; const river = wayland.server.river;
const server = &@import("main.zig").server;
const util = @import("util.zig"); const util = @import("util.zig");
const Box = @import("Box.zig"); const Box = @import("Box.zig");
@ -70,7 +71,7 @@ pub fn create(client: *wl.Client, version: u32, id: u32, output: *Output, namesp
/// Returns true if the given namespace is already in use on the given output /// Returns true if the given namespace is already in use on the given output
/// or on another output by a different client. /// or on another output by a different client.
fn namespaceInUse(namespace: []const u8, output: *Output, client: *wl.Client) bool { fn namespaceInUse(namespace: []const u8, output: *Output, client: *wl.Client) bool {
var output_it = output.root.outputs.first; var output_it = server.root.outputs.first;
while (output_it) |output_node| : (output_it = output_node.next) { while (output_it) |output_node| : (output_it = output_node.next) {
var layout_it = output_node.data.layouts.first; var layout_it = output_node.data.layouts.first;
if (output_node.data.wlr_output == output.wlr_output) { if (output_node.data.wlr_output == output.wlr_output) {
@ -125,7 +126,7 @@ pub fn startLayoutDemand(self: *Self, views: u32) void {
} }
self.layout.sendAdvertiseDone(serial); self.layout.sendAdvertiseDone(serial);
self.output.root.trackLayoutDemands(); server.root.trackLayoutDemands();
} }
fn handleRequest(layout: *river.LayoutV2, request: river.LayoutV2.Request, self: *Self) void { fn handleRequest(layout: *river.LayoutV2, request: river.LayoutV2.Request, self: *Self) void {
@ -183,7 +184,7 @@ fn handleDestroy(layout: *river.LayoutV2, self: *Self) void {
if (self == self.output.pending.layout) { if (self == self.output.pending.layout) {
self.output.pending.layout = null; self.output.pending.layout = null;
self.output.arrangeViews(); self.output.arrangeViews();
self.output.root.startTransaction(); server.root.startTransaction();
} }
util.gpa.free(self.namespace); util.gpa.free(self.namespace);

View file

@ -75,7 +75,7 @@ fn handleTimeout(layout: *Layout) callconv(.C) c_int {
layout.output.layout_demand.?.deinit(); layout.output.layout_demand.?.deinit();
layout.output.layout_demand = null; layout.output.layout_demand = null;
layout.output.root.notifyLayoutDemandDone(); server.root.notifyLayoutDemandDone();
return 0; return 0;
} }
@ -107,7 +107,7 @@ pub fn apply(self: *Self, layout: *Layout) void {
defer { defer {
output.layout_demand.?.deinit(); output.layout_demand.?.deinit();
output.layout_demand = null; output.layout_demand = null;
output.root.notifyLayoutDemandDone(); server.root.notifyLayoutDemandDone();
} }
// Check that the number of proposed dimensions is correct. // Check that the number of proposed dimensions is correct.

View file

@ -55,7 +55,6 @@ const State = struct {
layout: ?*Layout = null, layout: ?*Layout = null,
}; };
root: *Root,
wlr_output: *wlr.Output, wlr_output: *wlr.Output,
/// All layer surfaces on the output, indexed by the layer enum. /// All layer surfaces on the output, indexed by the layer enum.
@ -98,7 +97,7 @@ enable: wl.Listener(*wlr.Output) = wl.Listener(*wlr.Output).init(handleEnable),
frame: wl.Listener(*wlr.Output) = wl.Listener(*wlr.Output).init(handleFrame), frame: wl.Listener(*wlr.Output) = wl.Listener(*wlr.Output).init(handleFrame),
mode: wl.Listener(*wlr.Output) = wl.Listener(*wlr.Output).init(handleMode), mode: wl.Listener(*wlr.Output) = wl.Listener(*wlr.Output).init(handleMode),
pub fn init(self: *Self, root: *Root, wlr_output: *wlr.Output) !void { pub fn init(self: *Self, wlr_output: *wlr.Output) !void {
// Some backends don't have modes. DRM+KMS does, and we need to set a mode // Some backends don't have modes. DRM+KMS does, and we need to set a mode
// before we can use the output. The mode is a tuple of (width, height, // before we can use the output. The mode is a tuple of (width, height,
// refresh rate), and each monitor supports only a specific set of modes. We // refresh rate), and each monitor supports only a specific set of modes. We
@ -111,7 +110,6 @@ pub fn init(self: *Self, root: *Root, wlr_output: *wlr.Output) !void {
} }
self.* = .{ self.* = .{
.root = root,
.wlr_output = wlr_output, .wlr_output = wlr_output,
.usable_box = undefined, .usable_box = undefined,
}; };
@ -179,7 +177,7 @@ pub fn arrangeFilter(view: *View, filter_tags: u32) bool {
/// blocked until the layout demand has either finished or was aborted. Both /// blocked until the layout demand has either finished or was aborted. Both
/// cases will start a transaction. /// cases will start a transaction.
pub fn arrangeViews(self: *Self) void { pub fn arrangeViews(self: *Self) void {
if (self == &self.root.noop_output) return; if (self == &server.root.noop_output) return;
// If there is already an active layout demand, discard it. // If there is already an active layout demand, discard it.
if (self.layout_demand) |demand| { if (self.layout_demand) |demand| {
@ -418,17 +416,16 @@ fn arrangeLayer(
/// and then remove it from the list of outputs. /// and then remove it from the list of outputs.
fn handleDestroy(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void { fn handleDestroy(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
const self = @fieldParentPtr(Self, "destroy", listener); const self = @fieldParentPtr(Self, "destroy", listener);
const root = self.root;
std.log.scoped(.server).debug("output '{}' destroyed", .{self.wlr_output.name}); std.log.scoped(.server).debug("output '{}' destroyed", .{self.wlr_output.name});
// Remove the destroyed output from root if it wasn't already removed // Remove the destroyed output from root if it wasn't already removed
root.removeOutput(self); server.root.removeOutput(self);
var it = root.all_outputs.first; var it = server.root.all_outputs.first;
while (it) |all_node| : (it = all_node.next) { while (it) |all_node| : (it = all_node.next) {
if (all_node.data == self) { if (all_node.data == self) {
root.all_outputs.remove(all_node); server.root.all_outputs.remove(all_node);
break; break;
} }
} }
@ -454,7 +451,7 @@ fn handleEnable(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) vo
// Add the output to root.outputs and the output layout if it has not // Add the output to root.outputs and the output layout if it has not
// already been added. // already been added.
if (wlr_output.enabled) self.root.addOutput(self); if (wlr_output.enabled) server.root.addOutput(self);
} }
fn handleFrame(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void { fn handleFrame(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
@ -468,7 +465,7 @@ fn handleMode(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void
const self = @fieldParentPtr(Self, "mode", listener); const self = @fieldParentPtr(Self, "mode", listener);
self.arrangeLayers(); self.arrangeLayers();
self.arrangeViews(); self.arrangeViews();
self.root.startTransaction(); server.root.startTransaction();
} }
pub fn getEffectiveResolution(self: *Self) struct { width: u32, height: u32 } { pub fn getEffectiveResolution(self: *Self) struct { width: u32, height: u32 } {
@ -499,7 +496,7 @@ pub fn handleLayoutNamespaceChange(self: *Self) void {
if (mem.eql(u8, self.layoutNamespace(), node.data.namespace)) break &node.data; if (mem.eql(u8, self.layoutNamespace(), node.data.namespace)) break &node.data;
} else null; } else null;
self.arrangeViews(); self.arrangeViews();
self.root.startTransaction(); server.root.startTransaction();
} }
pub fn layoutNamespace(self: Self) []const u8 { pub fn layoutNamespace(self: Self) []const u8 {

View file

@ -104,7 +104,7 @@ pub fn init(self: *Self) !void {
}; };
const noop_wlr_output = try server.noop_backend.noopAddOutput(); const noop_wlr_output = try server.noop_backend.noopAddOutput();
try self.noop_output.init(self, noop_wlr_output); try self.noop_output.init(noop_wlr_output);
server.backend.events.new_output.add(&self.new_output); server.backend.events.new_output.add(&self.new_output);
self.output_manager.events.apply.add(&self.manager_apply); self.output_manager.events.apply.add(&self.manager_apply);
@ -134,7 +134,7 @@ fn handleNewOutput(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output)
wlr_output.destroy(); wlr_output.destroy();
return; return;
}; };
node.data.init(self, wlr_output) catch { node.data.init(wlr_output) catch {
wlr_output.destroy(); wlr_output.destroy();
util.gpa.destroy(node); util.gpa.destroy(node);
return; return;

View file

@ -215,7 +215,7 @@ pub fn applyPending(self: *Self) void {
self.post_fullscreen_box = self.current.box; self.post_fullscreen_box = self.current.box;
self.pending.target_opacity = 1.0; self.pending.target_opacity = 1.0;
const layout_box = self.output.root.output_layout.getBox(self.output.wlr_output).?; const layout_box = server.root.output_layout.getBox(self.output.wlr_output).?;
self.pending.box = .{ self.pending.box = .{
.x = 0, .x = 0,
.y = 0, .y = 0,
@ -236,7 +236,7 @@ pub fn applyPending(self: *Self) void {
if (arrange_output) self.output.arrangeViews(); if (arrange_output) self.output.arrangeViews();
self.output.root.startTransaction(); server.root.startTransaction();
} }
pub fn needsConfigure(self: Self) bool { pub fn needsConfigure(self: Self) bool {
@ -280,7 +280,7 @@ pub fn saveBuffers(self: *Self) void {
pub fn notifyConfiguredOrApplyPending(self: *Self) void { pub fn notifyConfiguredOrApplyPending(self: *Self) void {
self.pending_serial = null; self.pending_serial = null;
if (self.shouldTrackConfigure()) if (self.shouldTrackConfigure())
self.output.root.notifyConfigured() server.root.notifyConfigured()
else { else {
const self_tags_changed = self.pending.tags != self.current.tags; const self_tags_changed = self.pending.tags != self.current.tags;
self.current = self.pending; self.current = self.pending;
@ -482,13 +482,11 @@ pub fn map(self: *Self) void {
if (!self.current.float) self.output.arrangeViews(); if (!self.current.float) self.output.arrangeViews();
self.output.root.startTransaction(); server.root.startTransaction();
} }
/// Called by the impl when the surface will no longer be displayed /// Called by the impl when the surface will no longer be displayed
pub fn unmap(self: *Self) void { pub fn unmap(self: *Self) void {
const root = self.output.root;
log.debug("view '{}' unmapped", .{self.getTitle()}); log.debug("view '{}' unmapped", .{self.getTitle()});
self.destroying = true; self.destroying = true;
@ -510,7 +508,7 @@ pub fn unmap(self: *Self) void {
// Still need to arrange if fullscreened from the layout // Still need to arrange if fullscreened from the layout
if (!self.current.float) self.output.arrangeViews(); if (!self.current.float) self.output.arrangeViews();
root.startTransaction(); server.root.startTransaction();
} }
pub fn notifyTitle(self: Self) void { pub fn notifyTitle(self: Self) void {
@ -608,7 +606,7 @@ fn handleForeignActivate(
const self = @fieldParentPtr(Self, "foreign_activate", listener); const self = @fieldParentPtr(Self, "foreign_activate", listener);
const seat = @intToPtr(*Seat, event.seat.data); const seat = @intToPtr(*Seat, event.seat.data);
seat.focus(self); seat.focus(self);
self.output.root.startTransaction(); server.root.startTransaction();
} }
fn handleForeignFullscreen( fn handleForeignFullscreen(

View file

@ -72,7 +72,7 @@ pub fn deinit(self: *Self) void {
pub fn needsConfigure(self: Self) bool { pub fn needsConfigure(self: Self) bool {
const output = self.view.output; const output = self.view.output;
const output_box = output.root.output_layout.getBox(output.wlr_output).?; const output_box = server.root.output_layout.getBox(output.wlr_output).?;
return self.xwayland_surface.x != self.view.pending.box.x + output_box.x or return self.xwayland_surface.x != self.view.pending.box.x + output_box.x or
self.xwayland_surface.y != self.view.pending.box.y + output_box.y or self.xwayland_surface.y != self.view.pending.box.y + output_box.y or
self.xwayland_surface.width != self.view.pending.box.width or self.xwayland_surface.width != self.view.pending.box.width or
@ -83,7 +83,7 @@ pub fn needsConfigure(self: Self) bool {
/// shouldTrackConfigure() is always false for xwayland views. /// shouldTrackConfigure() is always false for xwayland views.
pub fn configure(self: Self) void { pub fn configure(self: Self) void {
const output = self.view.output; const output = self.view.output;
const output_box = output.root.output_layout.getBox(output.wlr_output).?; const output_box = server.root.output_layout.getBox(output.wlr_output).?;
const state = &self.view.pending; const state = &self.view.pending;
self.xwayland_surface.setFullscreen(state.fullscreen); self.xwayland_surface.setFullscreen(state.fullscreen);
@ -156,7 +156,6 @@ fn handleDestroy(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface:
fn handleMap(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface: *wlr.XwaylandSurface) void { fn handleMap(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface: *wlr.XwaylandSurface) void {
const self = @fieldParentPtr(Self, "map", listener); const self = @fieldParentPtr(Self, "map", listener);
const view = self.view; const view = self.view;
const root = view.output.root;
// Add listeners that are only active while mapped // Add listeners that are only active while mapped
xwayland_surface.surface.?.events.commit.add(&self.commit); xwayland_surface.surface.?.events.commit.add(&self.commit);

View file

@ -17,6 +17,8 @@
const std = @import("std"); const std = @import("std");
const server = &@import("../main.zig").server;
const Direction = @import("../command.zig").Direction; const Direction = @import("../command.zig").Direction;
const Error = @import("../command.zig").Error; const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig"); const Seat = @import("../Seat.zig");
@ -53,7 +55,7 @@ pub fn focusView(
// Focus the next visible node if there is one // Focus the next visible node if there is one
if (it.next()) |view| { if (it.next()) |view| {
seat.focus(view); seat.focus(view);
output.root.startTransaction(); server.root.startTransaction();
return; return;
} }
} }
@ -66,7 +68,7 @@ pub fn focusView(
}; };
seat.focus(it.next()); seat.focus(it.next());
output.root.startTransaction(); server.root.startTransaction();
} }
fn filter(view: *View, filter_tags: u32) bool { fn filter(view: *View, filter_tags: u32) bool {

View file

@ -17,6 +17,8 @@
const std = @import("std"); const std = @import("std");
const server = &@import("../main.zig").server;
const Error = @import("../command.zig").Error; const Error = @import("../command.zig").Error;
const Direction = @import("../command.zig").Direction; const Direction = @import("../command.zig").Direction;
const Seat = @import("../Seat.zig"); const Seat = @import("../Seat.zig");
@ -74,7 +76,7 @@ pub fn swap(
output.views.swap(focused_node, to_swap); output.views.swap(focused_node, to_swap);
output.arrangeViews(); output.arrangeViews();
output.root.startTransaction(); server.root.startTransaction();
} }
fn filter(view: *View, filter_tags: u32) bool { fn filter(view: *View, filter_tags: u32) bool {

View file

@ -17,6 +17,8 @@
const std = @import("std"); const std = @import("std");
const server = &@import("../main.zig").server;
const Error = @import("../command.zig").Error; const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig"); const Seat = @import("../Seat.zig");
@ -32,7 +34,7 @@ pub fn setFocusedTags(
seat.focused_output.pending.tags = tags; seat.focused_output.pending.tags = tags;
seat.focused_output.arrangeViews(); seat.focused_output.arrangeViews();
seat.focus(null); seat.focus(null);
seat.focused_output.root.startTransaction(); server.root.startTransaction();
} }
} }
@ -77,7 +79,7 @@ pub fn toggleFocusedTags(
output.pending.tags = new_focused_tags; output.pending.tags = new_focused_tags;
output.arrangeViews(); output.arrangeViews();
seat.focus(null); seat.focus(null);
output.root.startTransaction(); server.root.startTransaction();
} }
} }

View file

@ -17,6 +17,8 @@
const std = @import("std"); const std = @import("std");
const server = &@import("../main.zig").server;
const Error = @import("../command.zig").Error; const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig"); const Seat = @import("../Seat.zig");
const View = @import("../View.zig"); const View = @import("../View.zig");
@ -53,7 +55,7 @@ pub fn zoom(
output.views.push(to_bump); output.views.push(to_bump);
seat.focus(&to_bump.view); seat.focus(&to_bump.view);
output.arrangeViews(); output.arrangeViews();
output.root.startTransaction(); server.root.startTransaction();
} }
} }
} }

View file

@ -234,9 +234,9 @@ fn renderViewPopups(output: *const Output, view: *View, now: *os.timespec) void
} }
fn renderDragIcons(output: *const Output, now: *os.timespec) void { fn renderDragIcons(output: *const Output, now: *os.timespec) void {
const output_box = output.root.output_layout.getBox(output.wlr_output).?; const output_box = server.root.output_layout.getBox(output.wlr_output).?;
var it = output.root.drag_icons.first; var it = server.root.drag_icons.first;
while (it) |node| : (it = node.next) { while (it) |node| : (it = node.next) {
const drag_icon = &node.data; const drag_icon = &node.data;
@ -255,9 +255,9 @@ fn renderDragIcons(output: *const Output, now: *os.timespec) void {
/// Render all xwayland unmanaged windows that appear on the output /// Render all xwayland unmanaged windows that appear on the output
fn renderXwaylandUnmanaged(output: *const Output, now: *os.timespec) void { fn renderXwaylandUnmanaged(output: *const Output, now: *os.timespec) void {
const output_box = output.root.output_layout.getBox(output.wlr_output).?; const output_box = server.root.output_layout.getBox(output.wlr_output).?;
var it = output.root.xwayland_unmanaged_views.first; var it = server.root.xwayland_unmanaged_views.first;
while (it) |node| : (it = node.next) { while (it) |node| : (it = node.next) {
const xwayland_surface = node.data.xwayland_surface; const xwayland_surface = node.data.xwayland_surface;