commit a96a4eb5eff64a073c38221e96809bdc2a3d5266
parent 76db2025bb3db863dfef221cfb9869a7790c5836
Author: uint <abhinav.prsai@gmail.com>
Date: Wed, 18 Feb 2026 06:07:03 +0000
add wallpaper protocol with separate screen buffers support
add wallpaper protocol
> swc just uses a buffer, processing is done on client
removed STB
Diffstat:
11 files changed, 197 insertions(+), 71 deletions(-)
diff --git a/Makefile b/Makefile
@@ -97,6 +97,7 @@ PROTO_EXTENSIONS= \
protocol/server-decoration.xml \
protocol/swc.xml \
protocol/swc_snap.xml \
+ protocol/swc_wallpaper.xml \
protocol/wayland-drm.xml \
${WAYLAND_PROTOCOLS_DATADIR}/stable/xdg-shell/xdg-shell.xml \
${WAYLAND_PROTOCOLS_DATADIR}/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml \
@@ -124,6 +125,7 @@ PROTO_GEN_C= \
protocol/server-decoration-protocol.c \
protocol/swc-protocol.c \
protocol/swc_snap-protocol.c \
+ protocol/swc_wallpaper-protocol.c \
protocol/wayland-drm-protocol.c \
protocol/xdg-decoration-unstable-v1-protocol.c \
protocol/xdg-shell-protocol.c
@@ -137,6 +139,8 @@ PROTO_GEN_H= \
protocol/swc-client-protocol.h \
protocol/swc_snap-server-protocol.h \
protocol/swc_snap-client-protocol.h \
+ protocol/swc_wallpaper-server-protocol.h \
+ protocol/swc_wallpaper-client-protocol.h \
protocol/wayland-drm-server-protocol.h \
protocol/wayland-drm-client-protocol.h \
protocol/xdg-decoration-unstable-v1-server-protocol.h \
@@ -213,6 +217,7 @@ SWC_SOURCES= \
protocol/server-decoration-protocol.c \
protocol/swc-protocol.c \
protocol/swc_snap-protocol.c \
+ protocol/swc_wallpaper-protocol.c \
protocol/wayland-drm-protocol.c \
protocol/xdg-decoration-unstable-v1-protocol.c \
protocol/xdg-shell-protocol.c
@@ -275,11 +280,13 @@ install: build
install -d ${DESTDIR}${BINDIR}
install -d ${DESTDIR}${LIBDIR}
install -d ${DESTDIR}${INCLUDEDIR}
+ install -d ${DESTDIR}${DATADIR}/swc
install -d ${DESTDIR}${PKGCONFIGDIR}
install -m 4755 launch/swc-launch ${DESTDIR}${BINDIR}/
install -m 644 libswc/libswc.a ${DESTDIR}${LIBDIR}/
install -m 644 libswc/swc.h ${DESTDIR}${INCLUDEDIR}/
install -m 644 ${PROTO_GEN_H} ${DESTDIR}${INCLUDEDIR}/
+ install -m 644 protocol/swc.xml protocol/swc_snap.xml protocol/swc_wallpaper.xml ${DESTDIR}${DATADIR}/swc/
install -m 644 swc.pc ${DESTDIR}${PKGCONFIGDIR}/
clean:
diff --git a/libswc/compositor.c b/libswc/compositor.c
@@ -44,6 +44,7 @@
#include "subsurface.h"
#include "util.h"
#include "view.h"
+#include "wallpaper.h"
#include "window.h"
#include <errno.h>
@@ -109,6 +110,7 @@ static struct {
bool updating;
struct wl_global *global;
+ bool initialized;
/* zoom level (1.0 = normal, >1 = zoomed in, <1 = zoomed out) */
float zoom;
@@ -302,7 +304,7 @@ repaint_view(struct target *target, struct compositor_view *view, pixman_region3
}
static void
-renderer_repaint(struct target *target, pixman_region32_t *damage, pixman_region32_t *base_damage, struct wl_list *views)
+renderer_repaint(struct target *target, pixman_region32_t *damage, pixman_region32_t *base_damage, struct wl_list *views, struct screen *screen)
{
struct compositor_view *view;
const struct swc_rectangle *target_geom = &target->view->geometry;
@@ -314,10 +316,12 @@ renderer_repaint(struct target *target, pixman_region32_t *damage, pixman_region
wld_set_target_surface(swc.drm->renderer, target->surface);
if (pixman_region32_not_empty(base_damage)) {
+ struct wld_buffer *background = swc_wallpaper_buffer_for_screen(screen);
+
pixman_region32_translate(base_damage, -target->view->geometry.x, -target->view->geometry.y);
- if(wallbuf)
- wld_copy_region(swc.drm->renderer, wallbuf, 0, 0, base_damage);
+ if (background)
+ wld_copy_region(swc.drm->renderer, background, 0, 0, base_damage);
else
wld_fill_region(swc.drm->renderer, bgcolor, base_damage);
@@ -508,6 +512,23 @@ schedule_updates(uint32_t screens)
compositor.scheduled_updates |= screens;
}
+void
+compositor_damage_all(void)
+{
+ struct screen *screen;
+
+ if (!compositor.initialized)
+ return;
+
+ wl_list_for_each (screen, &swc.screens, link) {
+ pixman_region32_union_rect(&compositor.damage, &compositor.damage,
+ screen->base.geometry.x, screen->base.geometry.y,
+ screen->base.geometry.width, screen->base.geometry.height);
+ }
+
+ schedule_updates(-1);
+}
+
static void
overlay_damage_region(int32_t x, int32_t y, uint32_t width, uint32_t height, uint32_t border_width)
{
@@ -597,6 +618,7 @@ render_zoomed_to_shm(struct screen *screen, float zoom)
int32_t cx = screen_x + width / 2;
int32_t cy = screen_y + height / 2;
struct compositor_view *view;
+ struct wld_buffer *background;
struct wld_buffer *buffer = wld_create_buffer(swc.shm->context,
width, height, WLD_FORMAT_XRGB8888, WLD_FLAG_MAP);
@@ -610,8 +632,9 @@ render_zoomed_to_shm(struct screen *screen, float zoom)
pixman_region32_t full;
pixman_region32_init_rect(&full, 0, 0, width, height);
- if (wallbuf)
- wld_copy_region(swc.shm->renderer, wallbuf, 0, 0, &full);
+ background = swc_wallpaper_buffer_for_screen(screen);
+ if (background)
+ wld_copy_region(swc.shm->renderer, background, 0, 0, &full);
else
wld_fill_region(swc.shm->renderer, bgcolor, &full);
pixman_region32_fini(&full);
@@ -1327,7 +1350,7 @@ update_screen(struct screen *screen)
pixman_region32_translate(&damage, geom->x, geom->y);
pixman_region32_init(&base_damage);
pixman_region32_subtract(&base_damage, &damage, &compositor.opaque);
- renderer_repaint(target, &damage, &base_damage, &compositor.views);
+ renderer_repaint(target, &damage, &base_damage, &compositor.views, screen);
pixman_region32_fini(&damage);
pixman_region32_fini(&base_damage);
}
@@ -1508,12 +1531,16 @@ compositor_initialize(void)
for (keysym = XKB_KEY_XF86Switch_VT_1; keysym <= XKB_KEY_XF86Switch_VT_12; ++keysym)
swc_add_binding(SWC_BINDING_KEY, SWC_MOD_ANY, keysym, &handle_switch_vt, NULL);
+ compositor.initialized = true;
+
return true;
}
void
compositor_finalize(void)
{
+ compositor.initialized = false;
+
if (compositor.zoom_buffer)
wld_buffer_unreference(compositor.zoom_buffer);
pixman_region32_fini(&compositor.damage);
@@ -1540,6 +1567,7 @@ compositor_render_to_shm(struct screen *screen)
pixman_region32_t region;
pixman_region32_t damage;
uint32_t caps;
+ struct wld_buffer *background;
/* create shm buf */
buffer = wld_create_buffer(swc.shm->context, width, height,
@@ -1559,8 +1587,9 @@ compositor_render_to_shm(struct screen *screen)
pixman_region32_init_rect(&damage, screen->base.geometry.x, screen->base.geometry.y, width, height);
/* background */
- if (wallbuf)
- wld_copy_region(swc.shm->renderer, wallbuf, 0, 0, ®ion);
+ background = swc_wallpaper_buffer_for_screen(screen);
+ if (background)
+ wld_copy_region(swc.shm->renderer, background, 0, 0, ®ion);
else
wld_fill_region(swc.shm->renderer, bgcolor, ®ion);
diff --git a/libswc/compositor.h b/libswc/compositor.h
@@ -48,6 +48,7 @@ struct swc_compositor {
bool compositor_initialize(void);
void compositor_finalize(void);
+void compositor_damage_all(void);
struct compositor_view {
struct view base;
diff --git a/libswc/internal.h b/libswc/internal.h
@@ -51,6 +51,7 @@ struct swc {
struct wl_global *shell;
struct wl_global *snap_manager;
struct wl_global *subcompositor;
+ struct wl_global *wallpaper_manager;
struct wl_global *xdg_decoration_manager;
struct wl_global *xdg_shell;
diff --git a/libswc/local.mk b/libswc/local.mk
@@ -61,6 +61,7 @@ SWC_SOURCES = \
protocol/server-decoration-protocol.c \
protocol/swc-protocol.c \
protocol/swc_snap-protocol.c \
+ protocol/swc_wallpaper-protocol.c \
protocol/wayland-drm-protocol.c \
protocol/xdg-decoration-unstable-v1-protocol.c \
protocol/xdg-shell-protocol.c
@@ -113,6 +114,7 @@ $(call objects,dmabuf): protocol/linux-dmabuf-unstable-v1-server-protocol.h
$(call objects,drm drm_buffer): protocol/wayland-drm-server-protocol.h
$(call objects,kde_decoration): protocol/server-decoration-server-protocol.h
$(call objects,snap): protocol/swc_snap-server-protocol.h
+$(call objects,wallpaper): protocol/swc_wallpaper-server-protocol.h
$(call objects,xdg_decoration): protocol/xdg-decoration-unstable-v1-server-protocol.h
$(call objects,xdg_shell): protocol/xdg-shell-server-protocol.h
$(call objects,pointer): cursor/cursor_data.h
diff --git a/libswc/swc.c b/libswc/swc.c
@@ -40,6 +40,7 @@
#include "snap.h"
#include "subcompositor.h"
#include "util.h"
+#include "wallpaper.h"
#include "window.h"
#include "xdg_decoration.h"
#include "xdg_shell.h"
@@ -222,10 +223,16 @@ swc_initialize(struct wl_display *display, struct wl_event_loop *event_loop, con
goto error14;
}
+ swc.wallpaper_manager = swc_wallpaper_manager_create(display);
+ if (!swc.wallpaper_manager) {
+ ERROR("Could not initialize wallpaper manager\n");
+ goto error15;
+ }
+
#ifdef ENABLE_XWAYLAND
if (!xserver_initialize()) {
ERROR("Could not initialize xwayland\n");
- goto error15;
+ goto error16;
}
#endif
@@ -234,9 +241,11 @@ swc_initialize(struct wl_display *display, struct wl_event_loop *event_loop, con
return true;
#ifdef ENABLE_XWAYLAND
+error16:
+ wl_global_destroy(swc.wallpaper_manager);
+#endif
error15:
wl_global_destroy(swc.snap_manager);
-#endif
error14:
wl_global_destroy(swc.panel_manager);
error13:
@@ -275,6 +284,7 @@ swc_finalize(void)
#ifdef ENABLE_XWAYLAND
xserver_finalize();
#endif
+ wl_global_destroy(swc.wallpaper_manager);
wl_global_destroy(swc.snap_manager);
wl_global_destroy(swc.panel_manager);
wl_global_destroy(swc.xdg_decoration_manager);
diff --git a/libswc/swc.h b/libswc/swc.h
@@ -35,6 +35,7 @@ extern "C" {
struct libinput_device;
struct wl_display;
struct wl_event_loop;
+struct wld_buffer;
/**
* gett the current cursor position
@@ -438,19 +439,21 @@ int swc_add_axis_binding(uint32_t modifiers, uint32_t axis, swc_axis_binding_han
/* Wallpaper {{{ */
-extern unsigned char *wallpaper;
-extern struct wld_buffer *wallbuf;
-
/**
- * Set wallpaper to image from fs path.
- * TODO: tiling, maybe diff image for each screen
+ * Set fallback wallpaper buffer for all screens that dom't have an override.
*/
+void swc_wallpaper_set_buffer(struct wld_buffer *buffer);
-void swc_wallpaper_set(char* path);
+/**
+ * Set wallpaper buffer for specified screen id.
+ *
+ * Passing NULL clears the override for that screen.
+ */
+void swc_wallpaper_set_buffer_for_screen(uint8_t screen_id, struct wld_buffer *buffer);
/**
* Set wallpaper to a single color
- * pretty much ignored if wallpaper is set to image
+ * used when no wallpaper buffer is set
* defaults to black
*/
diff --git a/libswc/wallpaper.c b/libswc/wallpaper.c
@@ -1,77 +1,116 @@
-#include <pixman.h>
#include <wld/wld.h>
-#define STB_IMAGE_IMPLEMENTATION
-#define STBI_NO_HDR
-#include "../stb/stb_image.h"
-
-#define STB_IMAGE_RESIZE_IMPLEMENTATION
-#include "../stb/stb_image_resize2.h"
-
#include "swc.h"
-#include "internal.h"
-#include "drm.h"
-#include "util.h"
-#include "shm.h"
+#include "compositor.h"
#include "screen.h"
+#include "util.h"
+#include "wayland_buffer.h"
+#include "wallpaper.h"
+#include "swc_wallpaper-server-protocol.h"
-unsigned char *wallpaper = NULL;
-struct wld_buffer *wallbuf = NULL;
+#define MAX_WALLPAPER_SCREENS 32
+static struct wld_buffer *wallbuf = NULL;
+static struct wld_buffer *screen_wallbuf[MAX_WALLPAPER_SCREENS];
uint32_t bgcolor = 0xff000000;
+static void
+set_buffer_slot(struct wld_buffer **slot, struct wld_buffer *buffer)
+{
+ if (buffer)
+ wld_buffer_reference(buffer);
+ if (*slot)
+ wld_buffer_unreference(*slot);
+
+ *slot = buffer;
+}
+
+struct wld_buffer *
+swc_wallpaper_buffer_for_screen(struct screen *screen)
+{
+ if (screen
+ && screen->id < ARRAY_LENGTH(screen_wallbuf)
+ && screen_wallbuf[screen->id])
+ return screen_wallbuf[screen->id];
+
+ return wallbuf;
+}
+
EXPORT void
-swc_wallpaper_set(char* path)
+swc_wallpaper_set_buffer(struct wld_buffer *buffer)
{
- int width, height, chan;
- unsigned char *loaded;
- struct screen *screen;
- int target_width = 0, target_height = 0;
+ set_buffer_slot(&wallbuf, buffer);
+ compositor_damage_all();
+}
- loaded = stbi_load(path, &width, &height, &chan, 4);
- if (!loaded)
+EXPORT void
+swc_wallpaper_set_buffer_for_screen(uint8_t screen_id, struct wld_buffer *buffer)
+{
+ if (screen_id >= ARRAY_LENGTH(screen_wallbuf))
return;
- /* get screen dimensions */
- wl_list_for_each(screen, &swc.screens, link) {
- target_width = screen->base.geometry.width;
- target_height = screen->base.geometry.height;
- break;
- }
+ set_buffer_slot(&screen_wallbuf[screen_id], buffer);
+ compositor_damage_all();
+}
+
+EXPORT void
+swc_wallpaper_color_set(uint32_t color)
+{
+ bgcolor = color;
+ compositor_damage_all();
+}
+
+static void
+set_buffer(struct wl_client *client, struct wl_resource *resource,
+ int32_t screen_id, struct wl_resource *buffer_resource)
+{
+ struct wld_buffer *buffer = NULL;
- /* If we have a screen and dimensions wrong scale */
- if (target_width > 0 && target_height > 0 &&
- (width != target_width || height != target_height)) {
- wallpaper = stbir_resize_uint8_srgb(loaded, width, height, 0,
- NULL, target_width, target_height, 0,
- STBIR_RGBA);
- stbi_image_free(loaded);
- width = target_width;
- height = target_height;
- } else {
- wallpaper = loaded;
+ (void)client;
+
+ if (buffer_resource) {
+ buffer = wayland_buffer_get(buffer_resource);
+ if (!buffer) {
+ wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
+ "buffer is not a wl_buffer");
+ return;
+ }
}
- /* swap color channels to be compatible */
- for(int i = 0; i < width * height; i++) {
- unsigned char r = wallpaper[i*4];
- wallpaper[i*4] = wallpaper[(i*4)+2];
- wallpaper[(i*4)+2] = r;
+ if (screen_id == -1) {
+ swc_wallpaper_set_buffer(buffer);
+ return;
}
- union wld_object obj;
- obj.ptr = (uint32_t*)wallpaper;
+ if (screen_id < 0 || screen_id >= ARRAY_LENGTH(screen_wallbuf))
+ return;
- wallbuf = wld_import_buffer(swc.shm->context,
- WLD_OBJECT_DATA,
- obj,
- width, height,
- WLD_FORMAT_ARGB8888,
- width * 4);
+ swc_wallpaper_set_buffer_for_screen((uint8_t)screen_id, buffer);
}
-EXPORT void
-swc_wallpaper_color_set(uint32_t color)
+static const struct swc_wallpaper_interface wallpaper_impl = {
+ .destroy = destroy_resource,
+ .set_buffer = set_buffer,
+};
+
+static void
+bind_wallpaper(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
- bgcolor = color;
+ (void)data;
+
+ struct wl_resource *resource;
+
+ resource = wl_resource_create(client, &swc_wallpaper_interface, version, id);
+ if (!resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
+
+ wl_resource_set_implementation(resource, &wallpaper_impl, NULL, NULL);
+}
+
+struct wl_global *
+swc_wallpaper_manager_create(struct wl_display *display)
+{
+ return wl_global_create(display, &swc_wallpaper_interface, 1, NULL, bind_wallpaper);
}
diff --git a/libswc/wallpaper.h b/libswc/wallpaper.h
@@ -0,0 +1,12 @@
+#ifndef SWC_WALLPAPER_H
+#define SWC_WALLPAPER_H
+
+struct wl_display;
+struct wl_global;
+struct wld_buffer;
+struct screen;
+
+struct wl_global *swc_wallpaper_manager_create(struct wl_display *display);
+struct wld_buffer *swc_wallpaper_buffer_for_screen(struct screen *screen);
+
+#endif
diff --git a/protocol/local.mk b/protocol/local.mk
@@ -7,6 +7,7 @@ PROTOCOL_EXTENSIONS = \
$(dir)/server-decoration.xml\
$(dir)/swc.xml \
$(dir)/swc_snap.xml \
+ $(dir)/swc_wallpaper.xml \
$(dir)/wayland-drm.xml \
$(wayland_protocols)/stable/xdg-shell/xdg-shell.xml \
$(wayland_protocols)/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml \
@@ -29,5 +30,7 @@ CLEAN_FILES += ${dir}/${proto_base}-protocol.c \
install-$(dir): | $(DESTDIR)$(DATADIR)/swc
install -m 644 protocol/swc.xml $(DESTDIR)$(DATADIR)/swc
+ install -m 644 protocol/swc_snap.xml $(DESTDIR)$(DATADIR)/swc
+ install -m 644 protocol/swc_wallpaper.xml $(DESTDIR)$(DATADIR)/swc
include common.mk
diff --git a/protocol/swc_wallpaper.xml b/protocol/swc_wallpaper.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="swc_wallpaper">
+ <interface name="swc_wallpaper" version="1">
+ <description summary="set compositor wallpaper">
+ Allows clients to set wallpaper buffers.
+ </description>
+
+ <request name="destroy" type="destructor" />
+
+ <request name="set_buffer">
+ <description summary="set or clear wallpaper buffer">
+ screen_id=-1 targets global fallback wallpaper.
+ Any other screen_id targets that id.
+ </description>
+ <arg name="screen_id" type="int" />
+ <arg name="buffer" type="object" interface="wl_buffer" allow-null="true" />
+ </request>
+ </interface>
+</protocol>