Skip to content

Commit

Permalink
Merge 1f6c141 into 36c3f76
Browse files Browse the repository at this point in the history
  • Loading branch information
jwijenbergh committed Apr 28, 2024
2 parents 36c3f76 + 1f6c141 commit 46feae7
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions libqtile/backend/wayland/wlrq.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,26 @@ def paint(self, screen: Screen, image_path: str, mode: str | None = None) -> Non
image_w = image.get_width()
image_h = image.get_height()

stride = image.get_stride()
data = cairocffi.cairo.cairo_image_surface_get_data(image._pointer)
wlr_buffer = lib.cairo_buffer_create(image_w, image_h, stride, data)
# the dimensions of cairo are the full screen if the mode is not specified
# otherwise they are the image dimensions for fill and stretch mode
# the actual scaling of the image is then done with wlroots functions
# so that the GPU is used
cairo_w = image_w if mode in ["fill", "stretch"] else screen.width
cairo_h = image_h if mode in ["fill", "stretch"] else screen.height
surface = cairocffi.ImageSurface(cairocffi.FORMAT_ARGB32, cairo_w, cairo_h)
with cairocffi.Context(surface) as context:
context.save()
context.set_operator(cairocffi.OPERATOR_SOURCE)
context.set_source_rgb(0, 0, 0)
context.rectangle(0, 0, cairo_w, cairo_h)
context.fill()
context.restore()
context.set_source_surface(image)
context.paint()
surface.flush()
stride = surface.get_stride()
data = cairocffi.cairo.cairo_image_surface_get_data(surface._pointer)
wlr_buffer = lib.cairo_buffer_create(cairo_w, cairo_h, stride, data)
if wlr_buffer == ffi.NULL:
raise RuntimeError("Couldn't allocate cairo buffer.")

Expand All @@ -143,7 +160,7 @@ def paint(self, screen: Screen, image_path: str, mode: str | None = None) -> Non
# We need to keep a reference to the surface so its data persists
if scene_buffer := SceneBuffer.create(self.core.wallpaper_tree, Buffer(wlr_buffer)):
scene_buffer.node.set_position(screen.x, screen.y)
self.core.wallpapers[screen] = (scene_buffer, image)
self.core.wallpapers[screen] = (scene_buffer, surface)
else:
logger.warning("Failed to create wlr_scene_buffer.")
return
Expand Down

0 comments on commit 46feae7

Please sign in to comment.