layershell.lua
local wau = require("wau")
wau:require("protocol.xdg-shell") wau:require("protocol.wlr-layer-shell-unstable-v1")
local helpers = require("helpers") local lgi = require("lgi")
local cairo = lgi.cairo
local display = wau.wl_display.connect()
assert(display, "Couldn't connect to the wayland server")
local registry = display:get_registry()
local output, comp, shm, layershell
registry:add_listener {
["global"] = function(_, name, interface, version)
if interface == "wl_output" then
output = registry:bind(name, wau.wl_output, version)
elseif interface == "wl_compositor" then
comp = registry:bind(name, wau.wl_compositor, version)
elseif interface == "wl_shm" then
shm = registry:bind(name, wau.wl_shm, version)
elseif interface == "zwlr_layer_shell_v1" then
layershell = registry:bind(name, wau.zwlr_layer_shell_v1, version)
end
end
}
display:roundtrip()
assert(output and comp and shm, "Couldn't load wl_ output, compositor or shm")
assert(layershell, "Couldn't load layershell")
local width = 100
local height = 100
local stride = width * 4
local size = stride * height
local surface = comp:create_surface()
display:roundtrip()
local mywidget = layershell:get_layer_surface(surface, output,
wau.zwlr_layer_shell_v1.Layer.TOP, "epicwau")
local Anchor = wau.zwlr_layer_surface_v1.Anchor
mywidget:set_anchor(Anchor.RIGHT + Anchor.TOP)
:set_margin(10, 10, 10, 10)
:set_size(width, height)
:add_listener { ["configure"] = wau.zwlr_layer_surface_v1.ack_configure }
surface:commit()
display:roundtrip()
local fd, data = helpers.allocate_shm(size)
local mypool = shm:create_pool(fd, size)
local mybuffer = mypool:create_buffer(0, width, height, stride, 0)
surface:attach(mybuffer, 0, 0)
surface:commit()
local cairo_surface = cairo.ImageSurface.create_for_data(data,
cairo.Format.ARGB32, width, height, 4 * width)
local cr = cairo.Context(cairo_surface)
cr:set_source_rgba(1, 0, 0, 0.6)
cr:paint()
surface:damage(0, 0, width, height)
surface:commit()
display:roundtrip()
os.execute("sleep " .. tostring(1000 * 2))