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

commit6fc1fcf7a08b380a05f4508afeb2148bab3eda71
parent4dc96ef17b
authorIsaac Freund <[email protected]>
date2021-06-14 22:37
view: ensure surface_box is initailized before use

 river/XdgToplevel.zig  |  5 +++--
 river/XwaylandView.zig | 13 ++++++++++---
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig
index 91664d8..bd05465 100644
--- a/river/XdgToplevel.zig
+++ b/river/XdgToplevel.zig
@@ -185,8 +185,6 @@ fn handleMap(listener: *wl.Listener(*wlr.XdgSurface), xdg_surface: *wlr.XdgSurfa
     toplevel.events.set_title.add(&self.set_title);
     toplevel.events.set_app_id.add(&self.set_app_id);
 
-    view.surface = self.xdg_surface.surface;
-
     // Use the view's initial size centered on the output as the default
     // floating dimensions
     var initial_box: wlr.Box = undefined;
@@ -203,6 +201,9 @@ fn handleMap(listener: *wl.Listener(*wlr.XdgSurface), xdg_surface: *wlr.XdgSurfa
     toplevel.server_pending.width = @intCast(u32, initial_box.width);
     toplevel.server_pending.height = @intCast(u32, initial_box.height);
 
+    view.surface = self.xdg_surface.surface;
+    view.surface_box = Box.fromWlrBox(initial_box);
+
     // Also use the view's  "natural" size as the initial regular dimensions,
     // for the case that it does not get arranged by a lyaout.
     view.pending.box = view.float_box;
diff --git a/river/XwaylandView.zig b/river/XwaylandView.zig
index c474be6..ecd1747 100644
--- a/river/XwaylandView.zig
+++ b/river/XwaylandView.zig
@@ -163,11 +163,18 @@ fn handleMap(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface: *wl
     const view = self.view;
 
     // Add listeners that are only active while mapped
-    xwayland_surface.surface.?.events.commit.add(&self.commit);
+    const surface = xwayland_surface.surface.?;
+    surface.events.commit.add(&self.commit);
     xwayland_surface.events.set_title.add(&self.set_title);
     xwayland_surface.events.set_class.add(&self.set_class);
 
-    view.surface = self.xwayland_surface.surface;
+    view.surface = surface;
+    self.view.surface_box = .{
+        .x = 0,
+        .y = 0,
+        .width = @intCast(u32, surface.current.width),
+        .height = @intCast(u32, surface.current.height),
+    };
 
     // Use the view's "natural" size centered on the output as the default
     // floating dimensions
@@ -240,7 +247,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), surface: *wlr.Surface) voi
 
     self.view.output.damage.addWhole();
 
-    self.view.surface_box = Box{
+    self.view.surface_box = .{
         .x = 0,
         .y = 0,
         .width = @intCast(u32, surface.current.width),