SeatStatus: eliminate "self" naming convention

This commit is contained in:
Isaac Freund 2024-03-14 12:55:54 +01:00
parent 4a259d322b
commit 1d8bca24ae
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
const Self = @This(); const SeatStatus = @This();
const std = @import("std"); const std = @import("std");
const wayland = @import("wayland"); const wayland = @import("wayland");
@ -29,52 +29,52 @@ const Output = @import("Output.zig");
const View = @import("View.zig"); const View = @import("View.zig");
seat: *Seat, seat: *Seat,
seat_status: *zriver.SeatStatusV1, seat_status_v1: *zriver.SeatStatusV1,
pub fn init(self: *Self, seat: *Seat, seat_status: *zriver.SeatStatusV1) void { pub fn init(seat_status: *SeatStatus, seat: *Seat, seat_status_v1: *zriver.SeatStatusV1) void {
self.* = .{ .seat = seat, .seat_status = seat_status }; seat_status.* = .{ .seat = seat, .seat_status_v1 = seat_status_v1 };
seat_status.setHandler(*Self, handleRequest, handleDestroy, self); seat_status_v1.setHandler(*SeatStatus, handleRequest, handleDestroy, seat_status);
// Send all info once on bind // Send all info once on bind
self.sendMode(server.config.modes.items[seat.mode_id].name); seat_status.sendMode(server.config.modes.items[seat.mode_id].name);
if (seat.focused_output) |output| self.sendOutput(output, .focused); if (seat.focused_output) |output| seat_status.sendOutput(output, .focused);
self.sendFocusedView(); seat_status.sendFocusedView();
} }
fn handleRequest(seat_status: *zriver.SeatStatusV1, request: zriver.SeatStatusV1.Request, _: *Self) void { fn handleRequest(seat_status_v1: *zriver.SeatStatusV1, request: zriver.SeatStatusV1.Request, _: *SeatStatus) void {
switch (request) { switch (request) {
.destroy => seat_status.destroy(), .destroy => seat_status_v1.destroy(),
} }
} }
fn handleDestroy(_: *zriver.SeatStatusV1, self: *Self) void { fn handleDestroy(_: *zriver.SeatStatusV1, seat_status: *SeatStatus) void {
const node = @fieldParentPtr(std.SinglyLinkedList(Self).Node, "data", self); const node = @fieldParentPtr(std.SinglyLinkedList(SeatStatus).Node, "data", seat_status);
self.seat.status_trackers.remove(node); seat_status.seat.status_trackers.remove(node);
util.gpa.destroy(node); util.gpa.destroy(node);
} }
pub fn sendOutput(self: Self, output: *Output, state: enum { focused, unfocused }) void { pub fn sendOutput(seat_status: SeatStatus, output: *Output, state: enum { focused, unfocused }) void {
const client = self.seat_status.getClient(); const client = seat_status.seat_status_v1.getClient();
var it = output.wlr_output.resources.iterator(.forward); var it = output.wlr_output.resources.iterator(.forward);
while (it.next()) |wl_output| { while (it.next()) |wl_output| {
if (wl_output.getClient() == client) switch (state) { if (wl_output.getClient() == client) switch (state) {
.focused => self.seat_status.sendFocusedOutput(wl_output), .focused => seat_status.seat_status_v1.sendFocusedOutput(wl_output),
.unfocused => self.seat_status.sendUnfocusedOutput(wl_output), .unfocused => seat_status.seat_status_v1.sendUnfocusedOutput(wl_output),
}; };
} }
} }
pub fn sendFocusedView(self: Self) void { pub fn sendFocusedView(seat_status: SeatStatus) void {
const title: [*:0]const u8 = if (self.seat.focused == .view) const title: [*:0]const u8 = if (seat_status.seat.focused == .view)
self.seat.focused.view.getTitle() orelse "" seat_status.seat.focused.view.getTitle() orelse ""
else else
""; "";
self.seat_status.sendFocusedView(title); seat_status.seat_status_v1.sendFocusedView(title);
} }
pub fn sendMode(self: Self, mode: [*:0]const u8) void { pub fn sendMode(seat_status: SeatStatus, mode: [*:0]const u8) void {
if (self.seat_status.getVersion() >= 3) { if (seat_status.seat_status_v1.getVersion() >= 3) {
self.seat_status.sendMode(mode); seat_status.seat_status_v1.sendMode(mode);
} }
} }