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

commitffca1f0377acf8ad76a6f0cb38ce4523f97cf169
parentd25a4db2e4
authorIsaac Freund <[email protected]>
date2023-03-09 23:14
river-status: only send layout name if changed

 river/Layout.zig | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/river/Layout.zig b/river/Layout.zig
index 351c116..34a96c0 100644
--- a/river/Layout.zig
+++ b/river/Layout.zig
@@ -159,13 +159,18 @@ fn handleRequest(layout: *river.LayoutV3, request: river.LayoutV3.Request, self:
                 if (layout_demand.serial == req.serial) layout_demand.apply(self);
             }
 
-            const new_name = util.gpa.dupeZ(u8, mem.sliceTo(req.layout_name, 0)) catch {
-                log.err("out of memory", .{});
-                return;
-            };
-            if (self.output.layout_name) |name| util.gpa.free(name);
-            self.output.layout_name = new_name;
-            self.output.status.sendLayoutName(self.output);
+            const new_name = mem.sliceTo(req.layout_name, 0);
+            if (self.output.layout_name == null or
+                !mem.eql(u8, self.output.layout_name.?, new_name))
+            {
+                const owned = util.gpa.dupeZ(u8, new_name) catch {
+                    log.err("out of memory", .{});
+                    return;
+                };
+                if (self.output.layout_name) |name| util.gpa.free(name);
+                self.output.layout_name = owned;
+                self.output.status.sendLayoutName(self.output);
+            }
         },
     }
 }