def _reset_texture(self): clear = cairocffi.ImageSurface(cairocffi.FORMAT_ARGB32, self.width, self.height) with cairocffi.Context(clear) as context: context.set_source_rgba(*utils.rgb("#000000")) context.paint() self.texture = Texture.from_pixels( self.core.renderer, DRM_FORMAT_ARGB8888, cairocffi.ImageSurface.format_stride_for_width(cairocffi.FORMAT_ARGB32, self.width), self.width, self.height, cairocffi.cairo.cairo_image_surface_get_data(clear._pointer), )
def paint(self, screen, image_path, mode=None): try: with open(image_path, "rb") as f: image, _ = cairocffi.pixbuf.decode_to_image_surface(f.read()) except IOError as e: logger.error("Wallpaper: %s" % e) return surface = cairocffi.ImageSurface(cairocffi.FORMAT_ARGB32, screen.width, screen.height) with cairocffi.Context(surface) as context: if mode == "fill": context.rectangle(0, 0, screen.width, screen.height) context.clip() image_w = image.get_width() image_h = image.get_height() width_ratio = screen.width / image_w if width_ratio * image_h >= screen.height: context.scale(width_ratio) else: height_ratio = screen.height / image_h context.translate( -(image_w * height_ratio - screen.width) // 2, 0) context.scale(height_ratio) elif mode == "stretch": context.scale( sx=screen.width / image.get_width(), sy=screen.height / image.get_height(), ) context.set_source_surface(image) context.paint() stride = surface.format_stride_for_width(cairocffi.FORMAT_ARGB32, screen.width) surface.flush() texture = Texture.from_pixels( self.core.renderer, DRM_FORMAT_ARGB8888, stride, screen.width, screen.height, cairocffi.cairo.cairo_image_surface_get_data(surface._pointer), ) outputs = [ output for output in self.core.outputs if output.wlr_output.enabled ] outputs[screen.index].wallpaper = texture
def paint(self, screen, image_path, mode=None): try: with open(image_path, 'rb') as f: image, _ = cairocffi.pixbuf.decode_to_image_surface(f.read()) except IOError as e: logger.error('Wallpaper: %s' % e) return surface = cairocffi.ImageSurface( cairocffi.FORMAT_ARGB32, screen.width, screen.height ) with cairocffi.Context(surface) as context: context.translate(screen.x, screen.y) if mode == 'fill': context.rectangle(0, 0, screen.width, screen.height) context.clip() image_w = image.get_width() image_h = image.get_height() width_ratio = screen.width / image_w if width_ratio * image_h >= screen.height: context.scale(width_ratio) else: height_ratio = screen.height / image_h context.translate( - (image_w * height_ratio - screen.width) // 2, 0 ) context.scale(height_ratio) elif mode == 'stretch': context.scale( sx=screen.width / image.get_width(), sy=screen.height / image.get_height(), ) context.set_source_surface(image) context.paint() stride = surface.format_stride_for_width(cairocffi.FORMAT_ARGB32, screen.width) surface.flush() texture = Texture.from_pixels( self.core.renderer, DRM_FORMAT_ARGB8888, stride, screen.width, screen.height, cairocffi.cairo.cairo_image_surface_get_data(surface._pointer) ) # TODO: how to map screens to outputs? self.core.outputs[0].wallpaper = texture