git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commitc221501343db78b72dd8a60426fcb5091306cf28
parent3c3d84cd13
authorIsaac Freund <[email protected]>
date2024-12-20 21:30
Root: rename to OutputManager

 river/Cursor.zig                      |  2 +-
 river/InputConfig.zig                 |  2 +-
 river/InputPopup.zig                  |  2 +-
 river/LockManager.zig                 |  2 +-
 river/Output.zig                      |  4 +--
 river/{Root.zig => OutputManager.zig} | 66 +++++++++++++++++------------------
 river/Server.zig                      | 20 +++++------
 river/TabletTool.zig                  |  2 +-
 river/WindowManager.zig               |  2 +-
 river/XdgPopup.zig                    |  2 +-
 10 files changed, 52 insertions(+), 52 deletions(-)

diff --git a/river/Cursor.zig b/river/Cursor.zig
index 1fff6ab..dadb308 100644
--- a/river/Cursor.zig
+++ b/river/Cursor.zig
@@ -184,7 +184,7 @@ tablet_tool_button: wl.Listener(*wlr.Tablet.event.Button) =
 pub fn init(cursor: *Cursor, seat: *Seat) !void {
     const wlr_cursor = try wlr.Cursor.create();
     errdefer wlr_cursor.destroy();
-    wlr_cursor.attachOutputLayout(server.root.output_layout);
+    wlr_cursor.attachOutputLayout(server.om.output_layout);
 
     // This is here so that cursor.xcursor_manager doesn't need to be an
     // optional pointer. This isn't optimal as it does a needless allocation,
diff --git a/river/InputConfig.zig b/river/InputConfig.zig
index a0288cf..c3d4533 100644
--- a/river/InputConfig.zig
+++ b/river/InputConfig.zig
@@ -221,7 +221,7 @@ pub const MapToOutput = struct {
     fn apply(map_to_output: MapToOutput, device: *InputDevice) void {
         const wlr_output = blk: {
             if (map_to_output.output_name) |name| {
-                var it = server.root.output_layout.outputs.iterator(.forward);
+                var it = server.om.output_layout.outputs.iterator(.forward);
                 while (it.next()) |layout_output| {
                     if (mem.eql(u8, mem.span(layout_output.output.name), name)) {
                         break :blk layout_output.output;
diff --git a/river/InputPopup.zig b/river/InputPopup.zig
index 067ddc5..84975a2 100644
--- a/river/InputPopup.zig
+++ b/river/InputPopup.zig
@@ -137,7 +137,7 @@ pub fn update(input_popup: *InputPopup) void {
     _ = focused.node.coords(&focused_x, &focused_y);
 
     var output_box: wlr.Box = undefined;
-    server.root.output_layout.getBox(output.wlr_output, &output_box);
+    server.om.output_layout.getBox(output.wlr_output, &output_box);
 
     // Relative to the surface with the active text input
     var cursor_box = text_input.wlr_text_input.current.cursor_rectangle;
diff --git a/river/LockManager.zig b/river/LockManager.zig
index 7389a5a..466fa6b 100644
--- a/river/LockManager.zig
+++ b/river/LockManager.zig
@@ -147,7 +147,7 @@ pub fn maybeLock(manager: *LockManager) void {
     var all_outputs_blanked = true;
     var all_outputs_rendered_lock_surface = true;
     {
-        var it = server.root.outputs.iterator(.forward);
+        var it = server.om.outputs.iterator(.forward);
         while (it.next()) |output| {
             if (!output.wlr_output.?.enabled) continue;
 
diff --git a/river/Output.zig b/river/Output.zig
index d9254d5..91296f1 100644
--- a/river/Output.zig
+++ b/river/Output.zig
@@ -201,7 +201,7 @@ pub fn create(wlr_output: *wlr.Output) !void {
     };
     wlr_output.data = @intFromPtr(output);
 
-    server.root.outputs.append(output);
+    server.om.outputs.append(output);
     server.wm.pending.outputs.append(output);
     output.link_sent.init();
 
@@ -355,7 +355,7 @@ fn renderAndCommit(output: *Output) !void {
     output.current.apply(&state);
 
     if (output.gamma_dirty) {
-        const control = server.root.gamma_control_manager.getControl(wlr_output);
+        const control = server.om.gamma_control_manager.getControl(wlr_output);
         if (!wlr.GammaControlV1.apply(control, &state)) return error.OutOfMemory;
 
         if (!wlr_output.testState(&state)) {
diff --git a/river/Root.zig b/river/OutputManager.zig
similarity index 88%
rename from river/Root.zig
rename to river/OutputManager.zig
index e427c09..22cfe0e 100644
--- a/river/Root.zig
+++ b/river/OutputManager.zig
@@ -14,7 +14,7 @@
 // You should have received a copy of the GNU General Public License
 // along with this program. If not, see <https://www.gnu.org/licenses/>.
 
-const Root = @This();
+const OutputManager = @This();
 
 const build_options = @import("build_options");
 const std = @import("std");
@@ -34,6 +34,8 @@ const SceneNodeData = @import("SceneNodeData.zig");
 const Window = @import("Window.zig");
 const XwaylandOverrideRedirect = @import("XwaylandOverrideRedirect.zig");
 
+const log = std.log.scoped(.output_manager);
+
 new_output: wl.Listener(*wlr.Output) = wl.Listener(*wlr.Output).init(handleNewOutput),
 
 output_layout: *wlr.OutputLayout,
@@ -41,7 +43,7 @@ output_layout: *wlr.OutputLayout,
 presentation: *wlr.Presentation,
 xdg_output_manager: *wlr.XdgOutputManagerV1,
 
-output_manager: *wlr.OutputManagerV1,
+wlr_output_manager: *wlr.OutputManagerV1,
 manager_apply: wl.Listener(*wlr.OutputConfigurationV1) =
     wl.Listener(*wlr.OutputConfigurationV1).init(handleManagerApply),
 manager_test: wl.Listener(*wlr.OutputConfigurationV1) =
@@ -58,37 +60,35 @@ gamma_control_set_gamma: wl.Listener(*wlr.GammaControlManagerV1.event.SetGamma)
 /// All Outputs that have a corresponding wlr_output.
 outputs: wl.list.Head(Output, .link),
 
-pub fn init(root: *Root) !void {
+pub fn init(om: *OutputManager) !void {
     const output_layout = try wlr.OutputLayout.create(server.wl_server);
     errdefer output_layout.destroy();
 
-    root.* = .{
+    om.* = .{
         .output_layout = output_layout,
         .outputs = undefined,
 
         .presentation = try wlr.Presentation.create(server.wl_server, server.backend),
         .xdg_output_manager = try wlr.XdgOutputManagerV1.create(server.wl_server, output_layout),
-        .output_manager = try wlr.OutputManagerV1.create(server.wl_server),
+        .wlr_output_manager = try wlr.OutputManagerV1.create(server.wl_server),
         .power_manager = try wlr.OutputPowerManagerV1.create(server.wl_server),
         .gamma_control_manager = try wlr.GammaControlManagerV1.create(server.wl_server),
     };
 
-    root.outputs.init();
+    om.outputs.init();
 
-    server.backend.events.new_output.add(&root.new_output);
-    root.output_manager.events.apply.add(&root.manager_apply);
-    root.output_manager.events.@"test".add(&root.manager_test);
-    root.power_manager.events.set_mode.add(&root.power_manager_set_mode);
-    root.gamma_control_manager.events.set_gamma.add(&root.gamma_control_set_gamma);
+    server.backend.events.new_output.add(&om.new_output);
+    om.wlr_output_manager.events.apply.add(&om.manager_apply);
+    om.wlr_output_manager.events.@"test".add(&om.manager_test);
+    om.power_manager.events.set_mode.add(&om.power_manager_set_mode);
+    om.gamma_control_manager.events.set_gamma.add(&om.gamma_control_set_gamma);
 }
 
-pub fn deinit(root: *Root) void {
-    root.output_layout.destroy();
+pub fn deinit(om: *OutputManager) void {
+    om.output_layout.destroy();
 }
 
 fn handleNewOutput(_: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
-    const log = std.log.scoped(.output_manager);
-
     log.debug("new output {s}", .{wlr_output.name});
 
     Output.create(wlr_output) catch |err| {
@@ -110,7 +110,7 @@ fn handleManagerTest(_: *wl.Listener(*wlr.OutputConfigurationV1), config: *wlr.O
     }
 
     const states = config.buildState() catch {
-        std.log.err("out of memory", .{});
+        log.err("out of memory", .{});
         config.sendFailed();
         return;
     };
@@ -128,7 +128,7 @@ fn handleManagerTest(_: *wl.Listener(*wlr.OutputConfigurationV1), config: *wlr.O
 }
 
 fn handleManagerApply(_: *wl.Listener(*wlr.OutputConfigurationV1), config: *wlr.OutputConfigurationV1) void {
-    std.log.scoped(.output_manager).info("applying output configuration", .{});
+    log.info("applying output configuration", .{});
 
     if (!validateConfigCoordinates(config)) {
         config.sendFailed();
@@ -184,7 +184,7 @@ fn validateConfigCoordinates(config: *wlr.OutputConfigurationV1) bool {
         if (build_options.xwayland and server.xwayland != null and
             (head.state.x < 0 or head.state.y < 0))
         {
-            std.log.scoped(.output_manager).err(
+            log.err(
                 \\Attempted to set negative coordinates for output {s}.
                 \\Negative output coordinates are disallowed if Xwayland is enabled due to a limitation of Xwayland.
             , .{head.state.output.name});
@@ -201,7 +201,7 @@ fn handlePowerManagerSetMode(
     // The output may have been destroyed, in which case there is nothing to do
     const output = @as(?*Output, @ptrFromInt(event.output.data)) orelse return;
 
-    std.log.debug("client requested dpms {s} for output {s}", .{
+    log.debug("client requested dpms {s} for output {s}", .{
         @tagName(event.mode),
         event.output.name,
     });
@@ -226,13 +226,13 @@ fn handleSetGamma(
     // The output may have been destroyed, in which case there is nothing to do
     const output = @as(?*Output, @ptrFromInt(event.output.data)) orelse return;
 
-    std.log.debug("client requested to set gamma", .{});
+    log.debug("client requested to set gamma", .{});
 
     output.gamma_dirty = true;
     event.output.scheduleFrame();
 }
 
-pub fn commitOutputState(root: *Root) void {
+pub fn commitOutputState(om: *OutputManager) void {
     const wm = &server.wm;
 
     {
@@ -242,13 +242,13 @@ pub fn commitOutputState(root: *Root) void {
             switch (output.sent.state) {
                 .enabled, .disabled_soft => {
                     output.scene_output.?.setPosition(output.sent.x, output.sent.y);
-                    _ = root.output_layout.add(wlr_output, output.sent.x, output.sent.y) catch {
-                        std.log.err("out of memory", .{});
+                    _ = om.output_layout.add(wlr_output, output.sent.x, output.sent.y) catch {
+                        log.err("out of memory", .{});
                         continue; // Try again next time
                     };
                 },
                 .disabled_hard, .destroying => {
-                    root.output_layout.remove(wlr_output);
+                    om.output_layout.remove(wlr_output);
                 },
             }
         }
@@ -295,7 +295,7 @@ pub fn commitOutputState(root: *Root) void {
             while (it.next()) |output| {
                 const wlr_output = output.wlr_output orelse continue;
                 const state = states.addOne() catch {
-                    std.log.err("out of memory", .{});
+                    log.err("out of memory", .{});
                     return;
                 };
 
@@ -311,7 +311,7 @@ pub fn commitOutputState(root: *Root) void {
         defer swapchain_manager.finish();
 
         if (!swapchain_manager.prepare(states.items)) {
-            std.log.err("failed to prepare new output configuration", .{});
+            log.err("failed to prepare new output configuration", .{});
             // TODO search for a working fallback
 
             if (wm.sent.output_config) |config| {
@@ -337,12 +337,12 @@ pub fn commitOutputState(root: *Root) void {
             if (!output.scene_output.?.buildState(&state.base, &.{
                 .swapchain = swapchain_manager.getSwapchain(state.output),
             })) {
-                std.log.err("failed to render scene for {s}", .{state.output.name});
+                log.err("failed to render scene for {s}", .{state.output.name});
             }
         }
 
         if (!server.backend.commit(states.items)) {
-            std.log.err("failed to commit new output configuration", .{});
+            log.err("failed to commit new output configuration", .{});
 
             if (wm.sent.output_config) |config| {
                 config.sendFailed();
@@ -383,18 +383,18 @@ pub fn commitOutputState(root: *Root) void {
     }
 
     // XXX sending this every transaction is too noisy
-    root.sendManagerConfig() catch {
-        std.log.err("out of memory", .{});
+    om.sendConfig() catch {
+        log.err("out of memory", .{});
     };
 }
 
 /// Send the current output state to all wlr-output-manager clients.
-fn sendManagerConfig(root: *Root) !void {
+fn sendConfig(om: *OutputManager) !void {
     const config = try wlr.OutputConfigurationV1.create();
     // this destroys all associated config heads as well
     errdefer config.destroy();
 
-    var it = root.outputs.iterator(.forward);
+    var it = om.outputs.iterator(.forward);
     while (it.next()) |output| {
         const head = try wlr.OutputConfigurationV1.Head.create(config, output.wlr_output.?);
 
@@ -411,5 +411,5 @@ fn sendManagerConfig(root: *Root) !void {
         head.state.y = output.current.y;
     }
 
-    root.output_manager.setConfiguration(config);
+    om.wlr_output_manager.setConfiguration(config);
 }
diff --git a/river/Server.zig b/river/Server.zig
index e323cd3..76347bb 100644
--- a/river/Server.zig
+++ b/river/Server.zig
@@ -31,7 +31,7 @@ const IdleInhibitManager = @import("IdleInhibitManager.zig");
 const InputManager = @import("InputManager.zig");
 const LockManager = @import("LockManager.zig");
 const Output = @import("Output.zig");
-const Root = @import("Root.zig");
+const OutputManager = @import("OutputManager.zig");
 const Scene = @import("Scene.zig");
 const SceneNodeData = @import("SceneNodeData.zig");
 const Seat = @import("Seat.zig");
@@ -83,7 +83,7 @@ foreign_toplevel_manager: *wlr.ForeignToplevelManagerV1,
 
 scene: Scene,
 input_manager: InputManager,
-root: Root,
+om: OutputManager,
 config: Config,
 idle_inhibit_manager: IdleInhibitManager,
 lock_manager: LockManager,
@@ -153,7 +153,7 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
         .config = try Config.init(),
 
         .scene = undefined,
-        .root = undefined,
+        .om = undefined,
         .input_manager = undefined,
         .idle_inhibit_manager = undefined,
         .lock_manager = undefined,
@@ -176,7 +176,7 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
     }
 
     try server.scene.init();
-    try server.root.init();
+    try server.om.init();
     try server.input_manager.init();
     try server.idle_inhibit_manager.init();
     try server.lock_manager.init();
@@ -219,7 +219,7 @@ pub fn deinit(server: *Server) void {
     server.renderer.destroy();
     server.allocator.destroy();
 
-    server.root.deinit();
+    server.om.deinit();
     server.input_manager.deinit();
     server.idle_inhibit_manager.deinit();
     server.lock_manager.deinit();
@@ -294,8 +294,8 @@ fn allowlist(server: *Server, global: *const wl.Global) bool {
         global == server.xdg_activation.global or
         global == server.data_device_manager.global or
         global == server.primary_selection_manager.global or
-        global == server.root.presentation.global or
-        global == server.root.xdg_output_manager.global or
+        global == server.om.presentation.global or
+        global == server.om.xdg_output_manager.global or
         global == server.input_manager.relative_pointer_manager.global or
         global == server.input_manager.pointer_constraints.global or
         global == server.input_manager.text_input_manager.global or
@@ -311,9 +311,9 @@ fn blocklist(server: *Server, global: *const wl.Global) bool {
         global == server.screencopy_manager.global or
         global == server.export_dmabuf_manager.global or
         global == server.data_control_manager.global or
-        global == server.root.output_manager.global or
-        global == server.root.power_manager.global or
-        global == server.root.gamma_control_manager.global or
+        global == server.om.wlr_output_manager.global or
+        global == server.om.power_manager.global or
+        global == server.om.gamma_control_manager.global or
         global == server.input_manager.idle_notifier.global or
         global == server.input_manager.virtual_pointer_manager.global or
         global == server.input_manager.virtual_keyboard_manager.global or
diff --git a/river/TabletTool.zig b/river/TabletTool.zig
index 9c6c291..5802929 100644
--- a/river/TabletTool.zig
+++ b/river/TabletTool.zig
@@ -73,7 +73,7 @@ fn create(wlr_seat: *wlr.Seat, wlr_tool: *wlr.TabletTool) error{OutOfMemory}!*Ta
     const wlr_cursor = try wlr.Cursor.create();
     errdefer wlr_cursor.destroy();
 
-    wlr_cursor.attachOutputLayout(server.root.output_layout);
+    wlr_cursor.attachOutputLayout(server.om.output_layout);
 
     const tablet_manager = server.input_manager.tablet_manager;
     tool.* = .{
diff --git a/river/WindowManager.zig b/river/WindowManager.zig
index 8b8dda4..0ad7693 100644
--- a/river/WindowManager.zig
+++ b/river/WindowManager.zig
@@ -389,7 +389,7 @@ fn commitTransaction(wm: *WindowManager) void {
         }
     }
 
-    server.root.commitOutputState();
+    server.om.commitOutputState();
 
     {
         var it = server.input_manager.seats.first;
diff --git a/river/XdgPopup.zig b/river/XdgPopup.zig
index 07bc363..29019fe 100644
--- a/river/XdgPopup.zig
+++ b/river/XdgPopup.zig
@@ -101,7 +101,7 @@ fn handleReposition(listener: *wl.Listener(void)) void {
     };
 
     var box: wlr.Box = undefined;
-    server.root.output_layout.getBox(output.wlr_output, &box);
+    server.om.output_layout.getBox(output.wlr_output, &box);
 
     var root_lx: c_int = undefined;
     var root_ly: c_int = undefined;