commit 15c43863c7882fe0e5976136be3ac2dbb0532c9c
parent 83c909e224feb1eaf60e35c7bf7b0cdafd92ed76
Author: Andrea Feletto <andrea@andreafeletto.com>
Date: Sat, 11 Jun 2022 23:17:02 +0200
use viewporter for background
Diffstat:
6 files changed, 30 insertions(+), 32 deletions(-)
diff --git a/build.zig b/build.zig
@@ -13,6 +13,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.addProtocolPath("protocol/wlr-layer-shell-unstable-v1.xml");
scanner.addProtocolPath("protocol/river-status-unstable-v1.xml");
scanner.addProtocolPath("protocol/river-control-unstable-v1.xml");
@@ -22,6 +23,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_viewporter", 1);
scanner.generate("zwlr_layer_shell_v1", 1);
scanner.generate("zriver_status_manager_v1", 1);
scanner.generate("zriver_control_v1", 1);
diff --git a/src/Bar.zig b/src/Bar.zig
@@ -2,6 +2,7 @@ const std = @import("std");
const mem = std.mem;
const wl = @import("wayland").client.wl;
+const wp = @import("wayland").client.wp;
const zwlr = @import("wayland").client.zwlr;
const Buffer = @import("Buffer.zig");
@@ -15,6 +16,7 @@ monitor: *Monitor,
layerSurface: *zwlr.LayerSurfaceV1,
background: struct {
surface: *wl.Surface,
+ viewport: *wp.Viewport,
buffer: Buffer,
},
@@ -35,13 +37,16 @@ pub fn create(monitor: *Monitor) !*Bar {
self.configured = false;
self.background.surface = try globals.compositor.createSurface();
+ self.background.viewport = try globals.viewporter.getViewport(self.background.surface);
+ try self.background.buffer.resize(globals.shm, 1, 1);
+ if (self.background.buffer.data) |data| data[0] = 0xff000000 else unreachable;
+
self.layerSurface = try globals.layerShell.getLayerSurface(
self.background.surface,
monitor.output,
.top,
"levee",
);
- self.background.buffer = mem.zeroes(Buffer);
self.tags = try Widget.init(state, self.background.surface);
self.clock = try Widget.init(state, self.background.surface);
@@ -91,7 +96,11 @@ fn layerSurfaceListener(
layerSurface.ackConfigure(data.serial);
- render.renderBackground(bar) catch return;
+ const bg = &bar.background;
+ bg.surface.attach(bg.buffer.buffer, 0, 0);
+ bg.surface.damageBuffer(0, 0, bar.width, bar.height);
+ bg.viewport.setDestination(bar.width, bar.height);
+
render.renderTags(bar) catch return;
render.renderClock(bar) catch return;
render.renderModules(bar) catch return;
diff --git a/src/Buffer.zig b/src/Buffer.zig
@@ -7,16 +7,17 @@ const wl = @import("wayland").client.wl;
const Buffer = @This();
-mmap: ?[]align(4096) u8,
-data: ?[]u32,
-buffer: ?*wl.Buffer,
-pix: ?*pixman.Image,
-busy: bool,
-width: u31,
-height: u31,
-size: u31,
+mmap: ?[]align(4096) u8 = null,
+data: ?[]u32 = null,
+buffer: ?*wl.Buffer = null,
+pix: ?*pixman.Image = null,
-pub fn init(self: *Buffer, shm: *wl.Shm, width: u31, height: u31) !void {
+busy: bool = false,
+width: u31 = 0,
+height: u31 = 0,
+size: u31 = 0,
+
+pub fn resize(self: *Buffer, shm: *wl.Shm, width: u31, height: u31) !void {
self.busy = true;
self.width = width;
self.height = height;
@@ -61,7 +62,7 @@ pub fn nextBuffer(pool: *[2]Buffer, shm: *wl.Shm, width: u16, height: u16) !*Buf
if (buffer.width != width or buffer.height != height) {
buffer.deinit();
- try buffer.init(shm, width, height);
+ try buffer.resize(shm, width, height);
}
return buffer;
}
diff --git a/src/Wayland.zig b/src/Wayland.zig
@@ -7,6 +7,7 @@ const strcmp = std.cstr.cmp;
const ArrayList = std.ArrayList;
const wl = @import("wayland").client.wl;
+const wp = @import("wayland").client.wp;
const zwlr = @import("wayland").client.zwlr;
const zriver = @import("wayland").client.zriver;
@@ -30,6 +31,7 @@ const Globals = struct {
compositor: *wl.Compositor,
subcompositor: *wl.Subcompositor,
shm: *wl.Shm,
+ viewporter: *wp.Viewporter,
layerShell: *zwlr.LayerShellV1,
statusManager: *zriver.StatusManagerV1,
control: *zriver.ControlV1,
@@ -151,6 +153,9 @@ fn bindGlobal(self: *Wayland, registry: *wl.Registry, name: u32, iface: [*:0]con
} else if (strcmp(iface, wl.Shm.getInterface().name) == 0) {
const global = try registry.bind(name, wl.Shm, 1);
self.setGlobal(global);
+ } else if (strcmp(iface, wp.Viewporter.getInterface().name) == 0) {
+ const global = try registry.bind(name, wp.Viewporter, 1);
+ self.setGlobal(global);
} else if (strcmp(iface, zwlr.LayerShellV1.getInterface().name) == 0) {
const global = try registry.bind(name, zwlr.LayerShellV1, 1);
self.setGlobal(global);
diff --git a/src/Widget.zig b/src/Widget.zig
@@ -23,7 +23,7 @@ pub fn init(state: *State, background: *wl.Surface) !Widget {
return Widget{
.surface = surface,
.subsurface = subsurface,
- .buffers = mem.zeroes([2]Buffer),
+ .buffers = .{ .{}, .{} },
};
}
diff --git a/src/render.zig b/src/render.zig
@@ -13,25 +13,6 @@ const utils = @import("utils.zig");
pub const RenderFn = fn (*Bar) anyerror!void;
-pub fn renderBackground(bar: *Bar) !void {
- const state = bar.monitor.state;
- const wlSurface = bar.background.surface;
-
- const buffer = &bar.background.buffer;
- if (buffer.width == bar.width and buffer.height == bar.height) return;
- try buffer.init(state.wayland.globals.shm, bar.width, bar.height);
-
- const area = [_]pixman.Rectangle16{
- .{ .x = 0, .y = 0, .width = bar.width, .height = bar.height },
- };
- const color = &state.config.backgroundColor;
- _ = pixman.Image.fillRectangles(.src, buffer.pix.?, color, 1, &area);
-
- wlSurface.setBufferScale(bar.monitor.scale);
- wlSurface.damageBuffer(0, 0, bar.width, bar.height);
- wlSurface.attach(buffer.buffer, 0, 0);
-}
-
pub fn renderTags(bar: *Bar) !void {
const state = bar.monitor.state;
const surface = bar.tags.surface;