From ac1762567c059539762f0a6c481d5bca41369c51 Mon Sep 17 00:00:00 2001 From: Leon Henrik Plickat Date: Sun, 25 Oct 2020 14:54:31 +0100 Subject: [PATCH] Send zriver_seat_status_v1.focused_view when title of focused view changes --- river/XdgToplevel.zig | 21 +++++++++++++++++++++ river/XwaylandView.zig | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig index 32e8079..4af318a 100644 --- a/river/XdgToplevel.zig +++ b/river/XdgToplevel.zig @@ -46,6 +46,7 @@ listen_new_popup: c.wl_listener = undefined, listen_request_fullscreen: c.wl_listener = undefined, listen_request_move: c.wl_listener = undefined, listen_request_resize: c.wl_listener = undefined, +listen_set_title: c.wl_listener = undefined, pub fn init(self: *Self, view: *View, wlr_xdg_surface: *c.wlr_xdg_surface) void { self.* = .{ .view = view, .wlr_xdg_surface = wlr_xdg_surface }; @@ -177,6 +178,9 @@ fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { self.listen_request_resize.notify = handleRequestResize; c.wl_signal_add(&wlr_xdg_toplevel.events.request_resize, &self.listen_request_resize); + self.listen_set_title.notify = handleSetTitle; + c.wl_signal_add(&wlr_xdg_toplevel.events.set_title, &self.listen_set_title); + view.wlr_surface = self.wlr_xdg_surface.surface; // Use the view's "natural" size centered on the output as the default @@ -240,6 +244,7 @@ fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { c.wl_list_remove(&self.listen_request_fullscreen.link); c.wl_list_remove(&self.listen_request_move.link); c.wl_list_remove(&self.listen_request_resize.link); + c.wl_list_remove(&self.listen_set_title.link); } /// Called when the surface is comitted @@ -311,3 +316,19 @@ fn handleRequestResize(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) v const seat = util.voidCast(Seat, event.seat.*.seat.*.data.?); seat.cursor.enterMode(.resize, self.view); } + +/// Called when the client sets / updates its title +fn handleSetTitle(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { + const self = @fieldParentPtr(Self, "listen_set_title", listener.?); + + // Send title to all status listeners attached to a seat which focuses this view + var seat_it = self.view.output.root.server.input_manager.seats.first; + while (seat_it) |seat_node| : (seat_it = seat_node.next) { + if (seat_node.data.focused == .view and seat_node.data.focused.view == self.view) { + var client_it = seat_node.data.status_trackers.first; + while (client_it) |client_node| : (client_it = client_node.next) { + client_node.data.sendFocusedView(); + } + } + } +} diff --git a/river/XwaylandView.zig b/river/XwaylandView.zig index c64bd5e..7f723e5 100644 --- a/river/XwaylandView.zig +++ b/river/XwaylandView.zig @@ -36,6 +36,7 @@ wlr_xwayland_surface: *c.wlr_xwayland_surface, listen_destroy: c.wl_listener = undefined, listen_map: c.wl_listener = undefined, listen_unmap: c.wl_listener = undefined, +listen_title: c.wl_listener = undefined, // Listeners that are only active while the view is mapped listen_commit: c.wl_listener = undefined, @@ -53,6 +54,9 @@ pub fn init(self: *Self, view: *View, wlr_xwayland_surface: *c.wlr_xwayland_surf self.listen_unmap.notify = handleUnmap; c.wl_signal_add(&self.wlr_xwayland_surface.events.unmap, &self.listen_unmap); + + self.listen_title.notify = handleTitle; + c.wl_signal_add(&self.wlr_xwayland_surface.events.set_title, &self.listen_title); } pub fn deinit(self: *Self) void { @@ -61,6 +65,7 @@ pub fn deinit(self: *Self) void { c.wl_list_remove(&self.listen_destroy.link); c.wl_list_remove(&self.listen_map.link); c.wl_list_remove(&self.listen_unmap.link); + c.wl_list_remove(&self.listen_title.link); } } @@ -218,3 +223,19 @@ fn handleCommit(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { view.notifyConfiguredOrApplyPending(); } } + +/// Called then the window updates its title +fn handleTitle(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { + const self = @fieldParentPtr(Self, "listen_title", listener.?); + + // Send title to all status listeners attached to a seat which focuses this view + var seat_it = self.view.output.root.server.input_manager.seats.first; + while (seat_it) |seat_node| : (seat_it = seat_node.next) { + if (seat_node.data.focused == .view and seat_node.data.focused.view == self.view) { + var client_it = seat_node.data.status_trackers.first; + while (client_it) |client_node| : (client_it = client_node.next) { + client_node.data.sendFocusedView(); + } + } + } +}