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

commit127d5d9cfbfeb6f2ac732e714d3c2152b792d57a
parentc87c7ac0e7
authorIsaac Freund <[email protected]>
date2020-04-26 18:15
Properly set initial usable box of outputs

 src/output.zig | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/src/output.zig b/src/output.zig
index be762c6..91c2b89 100644
--- a/src/output.zig
+++ b/src/output.zig
@@ -66,13 +66,6 @@ pub const Output = struct {
             layer.* = std.TailQueue(LayerSurface).init();
         }
 
-        self.usable_box = .{
-            .x = 0,
-            .y = 0,
-            .width = 1920,
-            .height = 1080,
-        };
-
         self.views.init();
 
         self.current_focused_tags = 1 << 0;
@@ -92,12 +85,30 @@ pub const Output = struct {
         self.listen_mode.notify = handleMode;
         c.wl_signal_add(&wlr_output.events.mode, &self.listen_mode);
 
-        if (!c.river_wlr_output_is_noop(wlr_output)) {
+        if (c.river_wlr_output_is_noop(wlr_output)) {
+            // A noop output is always 0 x 0
+            self.usable_box = .{
+                .x = 0,
+                .y = 0,
+                .width = 0,
+                .height = 0,
+            };
+        } else {
             // Add the new output to the layout. The add_auto function arranges outputs
             // from left-to-right in the order they appear. A more sophisticated
             // compositor would let the user configure the arrangement of outputs in the
             // layout. This automatically creates an output global on the wl_display.
             c.wlr_output_layout_add_auto(root.wlr_output_layout, wlr_output);
+
+            var width: c_int = undefined;
+            var height: c_int = undefined;
+            c.wlr_output_effective_resolution(wlr_output, &width, &height);
+            self.usable_box = .{
+                .x = 0,
+                .y = 0,
+                .width = @intCast(u32, width),
+                .height = @intCast(u32, height),
+            };
         }
     }
 
@@ -140,6 +151,12 @@ pub const Output = struct {
     /// pending state, the changes are not appplied until a transaction is started
     /// and completed.
     fn arrangeViews(self: *Self) void {
+        // If the output has a zero dimension, trying to arrange would cause
+        // underflow and is pointless anyway
+        if (self.usable_box.width == 0 or self.usable_box.height == 0) {
+            return;
+        }
+
         const output_tags = if (self.pending_focused_tags) |tags|
             tags
         else