Compare commits

...

1 Commits

Author SHA1 Message Date
Alex Denes
a3672f8e09
Add color_manager patch 2025-07-28 13:06:30 +00:00
2 changed files with 244 additions and 0 deletions

View File

@ -0,0 +1,10 @@
### Description
Adds simple support for color management using `wp_color_manager_v1`.
### Download
- [git branch](/caskd/dwl/src/branch/patches/color-management)
- [main 2025-06-18](/dwl/dwl-patches/raw/branch/main/patches/color_manager/color_manager.patch)
### Authors
- [caskd](https://codeberg.org/caskd)
caskd@redxen.eu
caskd at [Libera IRC dwl channel](https://web.libera.chat/?channels=#dwl)

View File

@ -0,0 +1,234 @@
From 33362c38839e4c042567264ae2701388303486a4 Mon Sep 17 00:00:00 2001
From: Alex Denes <caskd@redxen.eu>
Date: Thu, 10 Jul 2025 12:01:29 +0000
Subject: [PATCH 1/3] Initial WIP for color_mgr
---
Makefile | 6 +++++-
dwl.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 578194f..570d5f5 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,8 @@ dwl: dwl.o util.o
$(CC) dwl.o util.o $(DWLCFLAGS) $(LDFLAGS) $(LDLIBS) -o $@
dwl.o: dwl.c client.h config.h config.mk cursor-shape-v1-protocol.h \
pointer-constraints-unstable-v1-protocol.h wlr-layer-shell-unstable-v1-protocol.h \
- wlr-output-power-management-unstable-v1-protocol.h xdg-shell-protocol.h
+ wlr-output-power-management-unstable-v1-protocol.h xdg-shell-protocol.h \
+ color-management-v1-protocol.h
util.o: util.c util.h
# wayland-scanner is a tool which generates C headers and rigging for Wayland
@@ -39,6 +40,9 @@ pointer-constraints-unstable-v1-protocol.h:
wlr-layer-shell-unstable-v1-protocol.h:
$(WAYLAND_SCANNER) enum-header \
protocols/wlr-layer-shell-unstable-v1.xml $@
+color-management-v1-protocol.h:
+ $(WAYLAND_SCANNER) enum-header \
+ $(WAYLAND_PROTOCOLS)/staging/color-management/color-management-v1.xml $@
wlr-output-power-management-unstable-v1-protocol.h:
$(WAYLAND_SCANNER) server-header \
protocols/wlr-output-power-management-unstable-v1.xml $@
diff --git a/dwl.c b/dwl.c
index 12f441e..87621ff 100644
--- a/dwl.c
+++ b/dwl.c
@@ -18,6 +18,7 @@
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_alpha_modifier_v1.h>
#include <wlr/types/wlr_compositor.h>
+#include <wlr/types/wlr_color_management_v1.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_cursor_shape_v1.h>
#include <wlr/types/wlr_data_control_v1.h>
@@ -382,6 +383,7 @@ static struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard_mgr;
static struct wlr_virtual_pointer_manager_v1 *virtual_pointer_mgr;
static struct wlr_cursor_shape_manager_v1 *cursor_shape_mgr;
static struct wlr_output_power_manager_v1 *power_mgr;
+static struct wlr_color_manager_v1 *color_mgr;
static struct wlr_pointer_constraints_v1 *pointer_constraints;
static struct wlr_relative_pointer_manager_v1 *relative_pointer_mgr;
@@ -2645,6 +2647,35 @@ setup(void)
wl_signal_add(&output_mgr->events.apply, &output_mgr_apply);
wl_signal_add(&output_mgr->events.test, &output_mgr_test);
+ struct wlr_color_manager_v1_options *color_mgr_options;
+ color_mgr_options = ecalloc(1, sizeof(*color_mgr_options));
+
+ // Enable only supported wlroots features
+ color_mgr_options->features = (struct wlr_color_manager_v1_features){
+ .parametric = true,
+ .set_mastering_display_primaries = true,
+ };
+
+ color_mgr_options->render_intents_len = 2;
+ enum wp_color_manager_v1_render_intent *render_intents = ecalloc(color_mgr_options->render_intents_len, sizeof(*render_intents));
+ render_intents[0] = WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL;
+ render_intents[1] = WP_COLOR_MANAGER_V1_RENDER_INTENT_ABSOLUTE;
+ color_mgr_options->render_intents = render_intents;
+
+ enum wp_color_manager_v1_primaries *primaries = ecalloc(color_mgr_options->primaries_len, sizeof(*primaries));
+ primaries[0] = WP_COLOR_MANAGER_V1_PRIMARIES_SRGB;
+ primaries[1] = WP_COLOR_MANAGER_V1_PRIMARIES_BT2020;
+ color_mgr_options->primaries = primaries;
+
+ color_mgr_options->transfer_functions_len = 3;
+ enum wp_color_manager_v1_transfer_function *transfer_functions = ecalloc(color_mgr_options->transfer_functions_len, sizeof(*transfer_functions));
+ transfer_functions[0] = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB;
+ transfer_functions[1] = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ;
+ transfer_functions[2] = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR;
+ color_mgr_options->transfer_functions = transfer_functions;
+
+ color_mgr = wlr_color_manager_v1_create(dpy, 1, color_mgr_options);
+
/* Make sure XWayland clients don't connect to the parent X server,
* e.g when running in the x11 backend or the wayland backend and the
* compositor has Xwayland support */
--
2.49.1
From b31ba12a4b090bb5f183e4b12ca750b1fc284957 Mon Sep 17 00:00:00 2001
From: Alex Denes <caskd@redxen.eu>
Date: Mon, 28 Jul 2025 12:48:22 +0000
Subject: [PATCH 2/3] Enable HDR on all displays that support it by default
---
config.mk | 4 ++--
dwl.c | 10 ++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/config.mk b/config.mk
index eb08a05..f641d04 100644
--- a/config.mk
+++ b/config.mk
@@ -8,8 +8,8 @@ PREFIX = /usr/local
MANDIR = $(PREFIX)/share/man
DATADIR = $(PREFIX)/share
-WLR_INCS = `$(PKG_CONFIG) --cflags wlroots-0.19`
-WLR_LIBS = `$(PKG_CONFIG) --libs wlroots-0.19`
+WLR_INCS = `$(PKG_CONFIG) --cflags wlroots-0.20`
+WLR_LIBS = `$(PKG_CONFIG) --libs wlroots-0.20`
# Allow using an alternative wlroots installation
# This has to have all the includes required by wlroots, e.g:
diff --git a/dwl.c b/dwl.c
index 87621ff..b59a5a8 100644
--- a/dwl.c
+++ b/dwl.c
@@ -1116,6 +1116,16 @@ createmon(struct wl_listener *listener, void *data)
wlr_output_layout_add_auto(output_layout, wlr_output);
else
wlr_output_layout_add(output_layout, wlr_output, m->m.x, m->m.y);
+
+ // Enable HDR if supported
+ if ((wlr_output->supported_primaries & WLR_COLOR_NAMED_PRIMARIES_BT2020) &&
+ (wlr_output->supported_transfer_functions & WLR_COLOR_TRANSFER_FUNCTION_ST2084_PQ)) {
+ const struct wlr_output_image_description image_desc = {
+ .primaries = WLR_COLOR_NAMED_PRIMARIES_BT2020,
+ .transfer_function = WLR_COLOR_TRANSFER_FUNCTION_ST2084_PQ,
+ };
+ wlr_output_state_set_image_description(&state, &image_desc);
+ }
}
void
--
2.49.1
From e0dff1f15044b500fbebcb67d40dbc527556b6c8 Mon Sep 17 00:00:00 2001
From: Alex Denes <caskd@redxen.eu>
Date: Mon, 28 Jul 2025 12:58:16 +0000
Subject: [PATCH 3/3] Conditionally enable color transformation functions and
the manager
---
dwl.c | 57 ++++++++++++++++++++++++++++++---------------------------
1 file changed, 30 insertions(+), 27 deletions(-)
diff --git a/dwl.c b/dwl.c
index b59a5a8..d8a07cc 100644
--- a/dwl.c
+++ b/dwl.c
@@ -1119,7 +1119,8 @@ createmon(struct wl_listener *listener, void *data)
// Enable HDR if supported
if ((wlr_output->supported_primaries & WLR_COLOR_NAMED_PRIMARIES_BT2020) &&
- (wlr_output->supported_transfer_functions & WLR_COLOR_TRANSFER_FUNCTION_ST2084_PQ)) {
+ (wlr_output->supported_transfer_functions & WLR_COLOR_TRANSFER_FUNCTION_ST2084_PQ) &&
+ (drw->features.output_color_transform)) {
const struct wlr_output_image_description image_desc = {
.primaries = WLR_COLOR_NAMED_PRIMARIES_BT2020,
.transfer_function = WLR_COLOR_TRANSFER_FUNCTION_ST2084_PQ,
@@ -2657,34 +2658,36 @@ setup(void)
wl_signal_add(&output_mgr->events.apply, &output_mgr_apply);
wl_signal_add(&output_mgr->events.test, &output_mgr_test);
- struct wlr_color_manager_v1_options *color_mgr_options;
- color_mgr_options = ecalloc(1, sizeof(*color_mgr_options));
+ if (drw->features.input_color_transform) {
+ struct wlr_color_manager_v1_options *color_mgr_options;
+ color_mgr_options = ecalloc(1, sizeof(*color_mgr_options));
- // Enable only supported wlroots features
- color_mgr_options->features = (struct wlr_color_manager_v1_features){
- .parametric = true,
- .set_mastering_display_primaries = true,
- };
+ // Enable only supported wlroots features
+ color_mgr_options->features = (struct wlr_color_manager_v1_features){
+ .parametric = true,
+ .set_mastering_display_primaries = true,
+ };
+
+ color_mgr_options->render_intents_len = 2;
+ enum wp_color_manager_v1_render_intent *render_intents = ecalloc(color_mgr_options->render_intents_len, sizeof(*render_intents));
+ render_intents[0] = WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL;
+ render_intents[1] = WP_COLOR_MANAGER_V1_RENDER_INTENT_ABSOLUTE;
+ color_mgr_options->render_intents = render_intents;
- color_mgr_options->render_intents_len = 2;
- enum wp_color_manager_v1_render_intent *render_intents = ecalloc(color_mgr_options->render_intents_len, sizeof(*render_intents));
- render_intents[0] = WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL;
- render_intents[1] = WP_COLOR_MANAGER_V1_RENDER_INTENT_ABSOLUTE;
- color_mgr_options->render_intents = render_intents;
-
- enum wp_color_manager_v1_primaries *primaries = ecalloc(color_mgr_options->primaries_len, sizeof(*primaries));
- primaries[0] = WP_COLOR_MANAGER_V1_PRIMARIES_SRGB;
- primaries[1] = WP_COLOR_MANAGER_V1_PRIMARIES_BT2020;
- color_mgr_options->primaries = primaries;
-
- color_mgr_options->transfer_functions_len = 3;
- enum wp_color_manager_v1_transfer_function *transfer_functions = ecalloc(color_mgr_options->transfer_functions_len, sizeof(*transfer_functions));
- transfer_functions[0] = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB;
- transfer_functions[1] = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ;
- transfer_functions[2] = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR;
- color_mgr_options->transfer_functions = transfer_functions;
-
- color_mgr = wlr_color_manager_v1_create(dpy, 1, color_mgr_options);
+ enum wp_color_manager_v1_primaries *primaries = ecalloc(color_mgr_options->primaries_len, sizeof(*primaries));
+ primaries[0] = WP_COLOR_MANAGER_V1_PRIMARIES_SRGB;
+ primaries[1] = WP_COLOR_MANAGER_V1_PRIMARIES_BT2020;
+ color_mgr_options->primaries = primaries;
+
+ color_mgr_options->transfer_functions_len = 3;
+ enum wp_color_manager_v1_transfer_function *transfer_functions = ecalloc(color_mgr_options->transfer_functions_len, sizeof(*transfer_functions));
+ transfer_functions[0] = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB;
+ transfer_functions[1] = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ;
+ transfer_functions[2] = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR;
+ color_mgr_options->transfer_functions = transfer_functions;
+
+ color_mgr = wlr_color_manager_v1_create(dpy, 1, color_mgr_options);
+ }
/* Make sure XWayland clients don't connect to the parent X server,
* e.g when running in the x11 backend or the wayland backend and the
--
2.49.1