protocols: honor wlr-gamma-control for night-light tools
Advertise zwlr_gamma_control_manager_v1 and commit client ramps to the single output (reset when the control goes away); other outputs and failed commits fail the control so clients retry. Outputs with no LUT (headless/nested) are failed by wlroots itself. wltest gains a --gamma mode reporting gamma_size/failed; smoke tests cover the global and the clean headless failure path.
This commit is contained in:
parent
b9194addf4
commit
42853dcc18
6 changed files with 310 additions and 1 deletions
|
|
@ -1307,6 +1307,52 @@ def test_standalone_headless_content_type_logged(tmp_path):
|
|||
s.close()
|
||||
|
||||
|
||||
def test_standalone_headless_gamma_globals(tmp_path):
|
||||
"""The standalone compositor advertises zwlr_gamma_control_manager_v1
|
||||
so night-light tools can bind it."""
|
||||
out = tmp_path / "globals.txt"
|
||||
s = _spawn_standalone({}, "%s --globals-out '%s' '#112233'" % (WL, out))
|
||||
try:
|
||||
deadline = time.monotonic() + 15.0
|
||||
while time.monotonic() < deadline:
|
||||
if out.exists():
|
||||
break
|
||||
time.sleep(0.1)
|
||||
assert out.exists(), "wltest --globals-out never wrote its file"
|
||||
names = {line.split()[0] for line in out.read_text().splitlines()}
|
||||
assert "zwlr_gamma_control_manager_v1" in names, \
|
||||
f"missing gamma global; advertised: {sorted(names)}"
|
||||
finally:
|
||||
s.close()
|
||||
|
||||
|
||||
def test_standalone_headless_gamma_headless_fails_clean(tmp_path):
|
||||
"""On the headless output (no gamma LUT) a gamma-control request is
|
||||
cleanly failed by wlroots: the client learns `failed` and the
|
||||
compositor stays up with no crash indicators."""
|
||||
out = tmp_path / "gamma.out"
|
||||
s = _spawn_standalone(
|
||||
{}, "%s --gamma --gamma-out '%s'" % (WL, out),
|
||||
"%s '#ff0000'" % WL)
|
||||
try:
|
||||
s.wait_any_active()
|
||||
deadline = time.monotonic() + 15.0
|
||||
while time.monotonic() < deadline:
|
||||
if out.exists():
|
||||
break
|
||||
time.sleep(0.1)
|
||||
assert out.exists(), "gamma client never got a reply"
|
||||
assert out.read_text() == "failed", \
|
||||
f"expected headless gamma failure, got: {out.read_text()!r}"
|
||||
assert s.proc.poll() is None, f"log tail:\n{s.read_log()[-400:]}"
|
||||
log = s.read_log()
|
||||
for marker in ("Segfault", "Aborted", "Assertion", "BACKTRACE"):
|
||||
assert marker not in log, \
|
||||
f"crash indicator {marker!r} in log:\n{log[-2000:]}"
|
||||
finally:
|
||||
s.close()
|
||||
|
||||
|
||||
def test_nested_primary_selection_bridged(tmp_path):
|
||||
"""Nested mode: a tab's primary selection is fanned out to a second tab
|
||||
exactly as standalone, and the host-side bridge publishes it over
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include "content-type-v1-client.h"
|
||||
#include "single-pixel-buffer-v1-client.h"
|
||||
#include "viewporter-client.h"
|
||||
#include "wlr-gamma-control-unstable-v1-client.h"
|
||||
|
||||
/* Minimal deterministic xdg toplevel test client: shows a solid-color shm
|
||||
buffer and runs until killed. Used by test.sh to give the smoke test two
|
||||
|
|
@ -148,6 +149,7 @@ static struct wp_content_type_manager_v1 *content_type_mgr;
|
|||
static struct wp_single_pixel_buffer_manager_v1 *single_pixel_mgr;
|
||||
static struct wp_viewporter *viewporter;
|
||||
static struct wp_viewport *viewport;
|
||||
static struct zwlr_gamma_control_manager_v1 *gamma_mgr;
|
||||
static struct wl_output *wl_output;
|
||||
|
||||
struct foreign_state {
|
||||
|
|
@ -822,6 +824,11 @@ static void registry_global(void *data, struct wl_registry *reg, uint32_t name,
|
|||
} else if (strcmp(interface, wp_viewporter_interface.name) == 0) {
|
||||
viewporter = wl_registry_bind(reg, name, &wp_viewporter_interface,
|
||||
version < 1 ? version : 1);
|
||||
} else if (strcmp(interface,
|
||||
zwlr_gamma_control_manager_v1_interface.name) == 0) {
|
||||
gamma_mgr = wl_registry_bind(reg, name,
|
||||
&zwlr_gamma_control_manager_v1_interface,
|
||||
version < 1 ? version : 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1518,6 +1525,57 @@ static void inhibit_run(void) {
|
|||
}
|
||||
}
|
||||
|
||||
/* --- Gamma control (wlr-gamma-control-unstable-v1) ---
|
||||
--gamma --gamma-out <file>: ask for the output's gamma control. The
|
||||
compositor answers gamma_size (a LUT exists, e.g. DRM) or failed (no
|
||||
LUT, e.g. headless); either line is written to <file> and the client
|
||||
exits. The smoke test asserts the headless failure path stays clean. */
|
||||
static bool gamma_mode;
|
||||
static const char *gamma_out;
|
||||
|
||||
static void gamma_size(void *data, struct zwlr_gamma_control_v1 *gc,
|
||||
uint32_t size) {
|
||||
(void)data; (void)gc;
|
||||
char s[32];
|
||||
snprintf(s, sizeof(s), "size=%u", size);
|
||||
if (gamma_out) write_outfile(gamma_out, s, strlen(s));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void gamma_failed(void *data, struct zwlr_gamma_control_v1 *gc) {
|
||||
(void)data; (void)gc;
|
||||
if (gamma_out) write_outfile(gamma_out, "failed", 6);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static const struct zwlr_gamma_control_v1_listener gamma_listener = {
|
||||
.gamma_size = gamma_size,
|
||||
.failed = gamma_failed,
|
||||
};
|
||||
|
||||
static void gamma_run(void) {
|
||||
display = wl_display_connect(NULL);
|
||||
if (!display) {
|
||||
fprintf(stderr, "wltest: gamma: cannot connect\n");
|
||||
exit(1);
|
||||
}
|
||||
struct wl_registry *reg = wl_display_get_registry(display);
|
||||
wl_registry_add_listener(reg, ®istry_listener, NULL);
|
||||
wl_display_roundtrip(display);
|
||||
if (!gamma_mgr || !wl_output) {
|
||||
fprintf(stderr, "wltest: gamma: manager or output missing\n");
|
||||
exit(1);
|
||||
}
|
||||
struct zwlr_gamma_control_v1 *gc =
|
||||
zwlr_gamma_control_manager_v1_get_gamma_control(gamma_mgr, wl_output);
|
||||
zwlr_gamma_control_v1_add_listener(gc, &gamma_listener, NULL);
|
||||
wl_display_roundtrip(display);
|
||||
for (;;) {
|
||||
if (wl_display_dispatch(display) < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* --- Output power management (zwlr_output_power_management_v1) ---
|
||||
--power <on|off>: ask the compositor to blank (off) or unblank (on) the
|
||||
single output, then exit. The smoke test pairs this with --screencopy to
|
||||
|
|
@ -2160,6 +2218,7 @@ static void print_usage(const char *argv0) {
|
|||
"[--text-input [--text-input-out <file>]] "
|
||||
"[--input-method [--im-commit <text>] [--im-out <file>]] "
|
||||
"[--content-type <none|photo|video|game>] [--single-pixel] "
|
||||
"[--power <on|off>] [--gamma [--gamma-out <file>]] "
|
||||
"#RRGGBB [WIDTHxHEIGHT]\n"
|
||||
" %s shows a solid-color xdg_toplevel, e.g. #ff0000\n"
|
||||
" --extra also opens a second toplevel from the same client\n"
|
||||
|
|
@ -2191,7 +2250,9 @@ static void print_usage(const char *argv0) {
|
|||
" --content-type tags the toplevel surface (photo/video/\n"
|
||||
" game) via wp_content_type_v1\n"
|
||||
" --single-pixel backs the toplevel with a 1x1\n"
|
||||
" single-pixel buffer instead of shm",
|
||||
" single-pixel buffer instead of shm\n"
|
||||
" --gamma asks for gamma control, writing gamma_size or\n"
|
||||
" failed to --gamma-out and exiting",
|
||||
argv0, argv0);
|
||||
}
|
||||
|
||||
|
|
@ -2454,6 +2515,16 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
power_arg = argv[i + 1];
|
||||
i += 2;
|
||||
} else if (strcmp(argv[i], "--gamma") == 0) {
|
||||
gamma_mode = true;
|
||||
i += 1;
|
||||
} else if (strcmp(argv[i], "--gamma-out") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
fprintf(stderr, "wltest: --gamma-out needs a path\n");
|
||||
return 1;
|
||||
}
|
||||
gamma_out = argv[i + 1];
|
||||
i += 2;
|
||||
} else if (strcmp(argv[i], "--virtual-key") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
fprintf(stderr, "wltest: --virtual-key needs code:state,...\n");
|
||||
|
|
@ -2578,6 +2649,12 @@ int main(int argc, char **argv) {
|
|||
power_run();
|
||||
return 0;
|
||||
}
|
||||
/* Gamma mode: no color/size argument. Ask for gamma control and
|
||||
report gamma_size/failed, then exit. */
|
||||
if (gamma_mode) {
|
||||
gamma_run();
|
||||
return 0;
|
||||
}
|
||||
/* Shortcuts-inhibit mode: act as a game window that grabs the
|
||||
compositor's shortcuts. Creates its own focused window. */
|
||||
if (inhibit_mode) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue