From 35cde045b685e8667f0ddabd855fe041781d6e6a Mon Sep 17 00:00:00 2001 From: Andrea Feletto Date: Thu, 13 Apr 2023 13:24:14 +0200 Subject: [PATCH] use single pixel buffer protocol for background --- build.zig | 2 ++ src/Bar.zig | 22 ++++++++-------------- src/Wayland.zig | 13 ++++++++----- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/build.zig b/build.zig index 8a7767d..a5a3439 100644 --- a/build.zig +++ b/build.zig @@ -14,6 +14,7 @@ pub fn build(b: *std.build.Builder) void { const scanner = ScanProtocolsStep.create(b); scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml"); scanner.addSystemProtocol("stable/viewporter/viewporter.xml"); + scanner.addSystemProtocol("staging/single-pixel-buffer/single-pixel-buffer-v1.xml"); scanner.addProtocolPath("protocol/wlr-layer-shell-unstable-v1.xml"); scanner.addProtocolPath("protocol/river-status-unstable-v1.xml"); scanner.addProtocolPath("protocol/river-control-unstable-v1.xml"); @@ -23,6 +24,7 @@ pub fn build(b: *std.build.Builder) void { scanner.generate("wl_shm", 1); scanner.generate("wl_output", 3); scanner.generate("wl_seat", 5); + scanner.generate("wp_single_pixel_buffer_manager_v1", 1); scanner.generate("wp_viewporter", 1); scanner.generate("zwlr_layer_shell_v1", 1); scanner.generate("zriver_status_manager_v1", 1); diff --git a/src/Bar.zig b/src/Bar.zig index e42672d..05ece34 100644 --- a/src/Bar.zig +++ b/src/Bar.zig @@ -19,7 +19,7 @@ layer_surface: *zwlr.LayerSurfaceV1, background: struct { surface: *wl.Surface, viewport: *wp.Viewport, - buffer: Buffer, + buffer: *wl.Buffer, }, tags: Widget, @@ -37,21 +37,14 @@ pub fn create(monitor: *Monitor) !*Bar { const compositor = state.wayland.compositor.?; const viewporter = state.wayland.viewporter.?; - const shm = state.wayland.shm.?; + const spb_manager = state.wayland.single_pixel_buffer_manager.?; const layer_shell = state.wayland.layer_shell.?; self.background.surface = try compositor.createSurface(); self.background.viewport = try viewporter.getViewport(self.background.surface); + self.background.buffer = try spb_manager.createU32RgbaBuffer(0, 0, 0, 0xffffffff); - try self.background.buffer.resize(shm, 1, 1); - self.background.buffer.data.?[0] = 0xff000000; - - self.layer_surface = try layer_shell.getLayerSurface( - self.background.surface, - monitor.output, - .top, - "levee", - ); + self.layer_surface = try layer_shell.getLayerSurface(self.background.surface, monitor.output, .top, "levee"); self.tags = try Widget.init(self.background.surface); self.clock = try Widget.init(self.background.surface); @@ -76,10 +69,11 @@ pub fn create(monitor: *Monitor) !*Bar { pub fn destroy(self: *Bar) void { self.monitor.bar = null; + self.layer_surface.destroy(); self.background.surface.destroy(); - self.layer_surface.destroy(); - self.background.buffer.deinit(); + self.background.viewport.destroy(); + self.background.buffer.destroy(); self.tags.deinit(); self.clock.deinit(); @@ -102,7 +96,7 @@ fn layerSurfaceListener( layerSurface.ackConfigure(data.serial); const bg = &bar.background; - bg.surface.attach(bg.buffer.buffer, 0, 0); + bg.surface.attach(bg.buffer, 0, 0); bg.surface.damageBuffer(0, 0, bar.width, bar.height); bg.viewport.setDestination(bar.width, bar.height); diff --git a/src/Wayland.zig b/src/Wayland.zig index 3c87f6f..0532816 100644 --- a/src/Wayland.zig +++ b/src/Wayland.zig @@ -4,7 +4,6 @@ const mem = std.mem; const meta = std.meta; const os = std.os; const strcmp = std.cstr.cmp; -const ArrayList = std.ArrayList; const wl = @import("wayland").client.wl; const wp = @import("wayland").client.wp; @@ -26,13 +25,14 @@ fd: os.fd_t, compositor: ?*wl.Compositor = null, subcompositor: ?*wl.Subcompositor = null, shm: ?*wl.Shm = null, +single_pixel_buffer_manager: ?*wp.SinglePixelBufferManagerV1 = null, viewporter: ?*wp.Viewporter = null, layer_shell: ?*zwlr.LayerShellV1 = null, status_manager: ?*zriver.StatusManagerV1 = null, control: ?*zriver.ControlV1 = null, -monitors: ArrayList(*Monitor), -inputs: ArrayList(*Input), +monitors: std.ArrayList(*Monitor), +inputs: std.ArrayList(*Input), pub fn init() !Wayland { const display = try wl.Display.connect(null); @@ -41,8 +41,8 @@ pub fn init() !Wayland { return Wayland{ .display = display, .fd = wfd, - .monitors = ArrayList(*Monitor).init(state.gpa), - .inputs = ArrayList(*Input).init(state.gpa), + .monitors = std.ArrayList(*Monitor).init(state.gpa), + .inputs = std.ArrayList(*Input).init(state.gpa), }; } @@ -57,6 +57,7 @@ pub fn deinit(self: *Wayland) void { if (self.subcompositor) |global| global.destroy(); if (self.shm) |global| global.destroy(); if (self.viewporter) |global| global.destroy(); + if (self.single_pixel_buffer_manager) |global| global.destroy(); if (self.layer_shell) |global| global.destroy(); if (self.status_manager) |global| global.destroy(); if (self.control) |global| global.destroy(); @@ -122,6 +123,8 @@ fn bindGlobal(self: *Wayland, registry: *wl.Registry, name: u32, iface: [*:0]con self.shm = try registry.bind(name, wl.Shm, 1); } else if (strcmp(iface, wp.Viewporter.getInterface().name) == 0) { self.viewporter = try registry.bind(name, wp.Viewporter, 1); + } else if (strcmp(iface, wp.SinglePixelBufferManagerV1.getInterface().name) == 0) { + self.single_pixel_buffer_manager = try registry.bind(name, wp.SinglePixelBufferManagerV1, 1); } else if (strcmp(iface, zwlr.LayerShellV1.getInterface().name) == 0) { self.layer_shell = try registry.bind(name, zwlr.LayerShellV1, 1); } else if (strcmp(iface, zriver.StatusManagerV1.getInterface().name) == 0) { -- 2.45.2