From b8e2ee2a0c1d3573626ecaac925424d718c7f39a Mon Sep 17 00:00:00 2001 From: Leon Henrik Plickat Date: Sun, 14 Aug 2022 17:16:38 +0200 Subject: [PATCH] river-status: expose current layout name --- protocol/river-status-unstable-v1.xml | 19 +++++++++++++++++-- river/Layout.zig | 12 ++++++++++++ river/Output.zig | 15 +++++++++++++++ river/OutputStatus.zig | 16 ++++++++++++++++ 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/protocol/river-status-unstable-v1.xml b/protocol/river-status-unstable-v1.xml index 6a74256..f6bc091 100644 --- a/protocol/river-status-unstable-v1.xml +++ b/protocol/river-status-unstable-v1.xml @@ -16,7 +16,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - + A global factory for objects that receive status information specific to river. It could be used to implement, for example, a status bar. @@ -47,7 +47,7 @@ - + This interface allows clients to receive information about the current windowing state of an output. @@ -83,6 +83,21 @@ + + + + Sent once on binding the interface should a layout name exist and again + whenever the name changes. + + + + + + + Sent when the current layout name has been removed without a new one + being set, for example whent the active layout generator disconnects. + + diff --git a/river/Layout.zig b/river/Layout.zig index 1dfc136..35b726f 100644 --- a/river/Layout.zig +++ b/river/Layout.zig @@ -161,6 +161,12 @@ fn handleRequest(layout: *river.LayoutV3, request: river.LayoutV3.Request, self: // Therefore, simply ignore requests with old/wrong serials. if (layout_demand.serial == req.serial) layout_demand.apply(self); } + + if (self.output.layout_name) |name| { + util.gpa.free(name); + } + self.output.layout_name = util.gpa.dupeZ(u8, mem.span(req.layout_name)) catch null; + self.output.sendLayoutName(); }, } } @@ -187,6 +193,12 @@ pub fn destroy(self: *Self) void { self.output.layout_demand = null; server.root.notifyLayoutDemandDone(); } + + if (self.output.layout_name) |name| { + util.gpa.free(name); + self.output.layout_name = null; + self.output.sendLayoutNameClear(); + } } self.layout.setHandler(?*anyopaque, handleRequestInert, null, null); diff --git a/river/Output.zig b/river/Output.zig index 59edff7..3cb6879 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -88,6 +88,9 @@ layouts: std.TailQueue(Layout) = .{}, /// Call handleLayoutNamespaceChange() after setting this. layout_namespace: ?[]const u8 = null, +/// The last set layout name. +layout_name: ?[:0]const u8 = null, + /// Bitmask that whitelists tags for newly spawned views spawn_tagmask: u32 = math.maxInt(u32), @@ -180,6 +183,18 @@ pub fn sendUrgentTags(self: Self) void { while (it) |node| : (it = node.next) node.data.sendUrgentTags(urgent_tags); } +pub fn sendLayoutName(self: Self) void { + std.debug.assert(self.layout_name != null); + var it = self.status_trackers.first; + while (it) |node| : (it = node.next) node.data.sendLayoutName(self.layout_name.?); +} + +pub fn sendLayoutNameClear(self: Self) void { + std.debug.assert(self.layout_name == null); + var it = self.status_trackers.first; + while (it) |node| : (it = node.next) node.data.sendLayoutNameClear(); +} + pub fn arrangeFilter(view: *View, filter_tags: u32) bool { return view.surface != null and !view.pending.float and !view.pending.fullscreen and view.pending.tags & filter_tags != 0; diff --git a/river/OutputStatus.zig b/river/OutputStatus.zig index baf4d01..fc5b67e 100644 --- a/river/OutputStatus.zig +++ b/river/OutputStatus.zig @@ -47,6 +47,10 @@ pub fn init(self: *Self, output: *Output, output_status: *zriver.OutputStatusV1) if (node.view.current.urgent) urgent_tags |= node.view.current.tags; } self.sendUrgentTags(urgent_tags); + + if (output.layout_name) |name| { + self.sendLayoutName(name); + } } pub fn destroy(self: *Self) void { @@ -94,3 +98,15 @@ pub fn sendUrgentTags(self: Self, tags: u32) void { self.output_status.sendUrgentTags(tags); } } + +pub fn sendLayoutName(self: Self, name: [:0]const u8) void { + if (self.output_status.getVersion() >= 4) { + self.output_status.sendLayoutName(name); + } +} + +pub fn sendLayoutNameClear(self: Self) void { + if (self.output_status.getVersion() >= 4) { + self.output_status.sendLayoutNameClear(); + } +}