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
10
README.md
10
README.md
|
|
@ -370,6 +370,16 @@ tag their surfaces (`photo`/`video`/`game`; the type is recorded in the
|
|||
surface with a 1×1 buffer (scaled up via `wp_viewporter`, which kick also
|
||||
advertises) instead of a shared-memory pool.
|
||||
|
||||
## Gamma control (`wlr-gamma-control`)
|
||||
|
||||
Kick advertises `zwlr_gamma_control_manager_v1`, so night-light tools
|
||||
(wlsunset, gammastep) can set the output's gamma ramp. Ramps are committed
|
||||
to the single output via the standard wlroots apply path (a departing
|
||||
client resets it); outputs with no gamma LUT report `failed` instead, so
|
||||
on headless/nested outputs such tools learn the output is unsupported
|
||||
rather than hanging. Like all hardware LUTs, this only takes visible
|
||||
effect on DRM in standalone mode.
|
||||
|
||||
## Logging (`KICK_LOG`)
|
||||
|
||||
Quiet by default: a plain launch prints nothing to the launching terminal
|
||||
|
|
|
|||
42
kick.c
42
kick.c
|
|
@ -85,6 +85,7 @@
|
|||
#include <wlr/types/wlr_ext_foreign_toplevel_list_v1.h>
|
||||
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
|
||||
#include <wlr/types/wlr_fractional_scale_v1.h>
|
||||
#include <wlr/types/wlr_gamma_control_v1.h>
|
||||
#include <wlr/types/wlr_idle_inhibit_v1.h>
|
||||
#include <wlr/types/wlr_idle_notify_v1.h>
|
||||
#include <wlr/types/wlr_input_device.h>
|
||||
|
|
@ -373,6 +374,12 @@ struct kick_server {
|
|||
struct wlr_output_power_manager_v1 *output_power_mgr;
|
||||
struct wl_listener output_power_set_mode;
|
||||
bool output_powered;
|
||||
/* Gamma control (night-light tools like wlsunset/gammastep): a client
|
||||
sets a per-output ramp; wlroots rejects outputs with no LUT (e.g.
|
||||
the headless output) itself, so the handler only commits ramps for
|
||||
the single server output. Only takes visible effect on DRM. */
|
||||
struct wlr_gamma_control_manager_v1 *gamma_mgr;
|
||||
struct wl_listener gamma_set;
|
||||
/* Keyboard shortcuts inhibit (zwp_keyboard_shortcuts_inhibit_v1): lets a
|
||||
fullscreen game/VM grab the compositor's keyboard shortcuts. While the
|
||||
focused surface's inhibitor is active, the grab chords in
|
||||
|
|
@ -5975,6 +5982,34 @@ static void handle_output_power_set_mode(struct wl_listener *listener,
|
|||
kick_request_redraw();
|
||||
}
|
||||
|
||||
/* Gamma control: apply the client's ramp to the single output (or reset it
|
||||
when the control went away: wlroots emits set_gamma with NULL then). A
|
||||
failed commit fails the control so the client (wlsunset) retries later
|
||||
instead of waiting on a ramp that never landed. */
|
||||
static void handle_gamma_set(struct wl_listener *listener, void *data) {
|
||||
(void)listener;
|
||||
struct wlr_gamma_control_manager_v1_set_gamma_event *ev = data;
|
||||
if (ev->output != server.output) {
|
||||
if (ev->control)
|
||||
wlr_gamma_control_v1_send_failed_and_destroy(ev->control);
|
||||
return;
|
||||
}
|
||||
struct wlr_output_state state;
|
||||
wlr_output_state_init(&state);
|
||||
bool ok = wlr_gamma_control_v1_apply(ev->control, &state);
|
||||
if (ok)
|
||||
ok = wlr_output_commit_state(ev->output, &state);
|
||||
wlr_output_state_finish(&state);
|
||||
if (!ok) {
|
||||
if (ev->control)
|
||||
wlr_gamma_control_v1_send_failed_and_destroy(ev->control);
|
||||
return;
|
||||
}
|
||||
kick_log(KICK_LOG_DEBUG, "[gamma] ramp %s size=%zu\n",
|
||||
ev->control ? "applied" : "reset",
|
||||
ev->control ? ev->control->ramp_size : 0);
|
||||
}
|
||||
|
||||
/* ===================== Virtual keyboard/pointer =====================
|
||||
Synthesised input (wtype & co.) feeds the seat through the exact same
|
||||
paths as real devices: virtual keys go through process_key_event so grab
|
||||
|
|
@ -10636,6 +10671,13 @@ int main(int argc, char *argv[]) {
|
|||
wl_signal_add(&server.output_power_mgr->events.set_mode,
|
||||
&server.output_power_set_mode);
|
||||
|
||||
/* Gamma control: night-light clients set the output ramp (see
|
||||
handle_gamma_set); wlroots itself fails controls for outputs with
|
||||
no LUT, so headless/nested clients learn it is unsupported. */
|
||||
server.gamma_mgr = wlr_gamma_control_manager_v1_create(server.wl_display);
|
||||
server.gamma_set.notify = handle_gamma_set;
|
||||
wl_signal_add(&server.gamma_mgr->events.set_gamma, &server.gamma_set);
|
||||
|
||||
/* Virtual keyboard/pointer: synthesised input feeds the seat via the
|
||||
same paths as real devices (see handle_virtual_kb_new/ptr_new). */
|
||||
wl_list_init(&server.virtual_kbs);
|
||||
|
|
|
|||
|
|
@ -225,6 +225,12 @@ protocols = {
|
|||
'wlr-protocols/input-method-unstable-v2.xml',
|
||||
'input-method-unstable-v2',
|
||||
],
|
||||
# Gamma control (night-light tools like wlsunset/gammastep): wlroots
|
||||
# extension, vendored like the other wlr-protocols XMLs.
|
||||
'gamma-control': [
|
||||
'wlr-protocols/wlr-gamma-control-unstable-v1.xml',
|
||||
'wlr-gamma-control-unstable-v1',
|
||||
],
|
||||
# Content hints (photo/video/game) + single-pixel buffers (1x1 solid
|
||||
# color without a shm pool). Both are staging protocols from the
|
||||
# system wayland-protocols, like wlroots itself uses.
|
||||
|
|
@ -357,6 +363,7 @@ executable('wltest',
|
|||
code_by_name['content-type'],
|
||||
code_by_name['single-pixel'],
|
||||
code_by_name['viewporter'],
|
||||
code_by_name['gamma-control'],
|
||||
client_headers['xdg-shell'],
|
||||
client_headers['cursor-shape'],
|
||||
client_headers['wlr-layer-shell-unstable-v1'],
|
||||
|
|
@ -375,6 +382,7 @@ executable('wltest',
|
|||
client_headers['content-type'],
|
||||
client_headers['single-pixel'],
|
||||
client_headers['viewporter'],
|
||||
client_headers['gamma-control'],
|
||||
dependencies: [dependency('wayland-client'),
|
||||
dependency('xkbcommon')])
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
126
wlr-protocols/wlr-gamma-control-unstable-v1.xml
Normal file
126
wlr-protocols/wlr-gamma-control-unstable-v1.xml
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="wlr_gamma_control_unstable_v1">
|
||||
<copyright>
|
||||
Copyright © 2015 Giulio camuffo
|
||||
Copyright © 2018 Simon Ser
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that copyright notice and this permission
|
||||
notice appear in supporting documentation, and that the name of
|
||||
the copyright holders not be used in advertising or publicity
|
||||
pertaining to distribution of the software without specific,
|
||||
written prior permission. The copyright holders make no
|
||||
representations about the suitability of this software for any
|
||||
purpose. It is provided "as is" without express or implied
|
||||
warranty.
|
||||
|
||||
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
||||
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
</copyright>
|
||||
|
||||
<description summary="manage gamma tables of outputs">
|
||||
This protocol allows a privileged client to set the gamma tables for
|
||||
outputs.
|
||||
|
||||
Warning! The protocol described in this file is experimental and
|
||||
backward incompatible changes may be made. Backward compatible changes
|
||||
may be added together with the corresponding interface version bump.
|
||||
Backward incompatible changes are done by bumping the version number in
|
||||
the protocol and interface names and resetting the interface version.
|
||||
Once the protocol is to be declared stable, the 'z' prefix and the
|
||||
version number in the protocol and interface names are removed and the
|
||||
interface version number is reset.
|
||||
</description>
|
||||
|
||||
<interface name="zwlr_gamma_control_manager_v1" version="1">
|
||||
<description summary="manager to create per-output gamma controls">
|
||||
This interface is a manager that allows creating per-output gamma
|
||||
controls.
|
||||
</description>
|
||||
|
||||
<request name="get_gamma_control">
|
||||
<description summary="get a gamma control for an output">
|
||||
Create a gamma control that can be used to adjust gamma tables for the
|
||||
provided output.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="zwlr_gamma_control_v1"/>
|
||||
<arg name="output" type="object" interface="wl_output"/>
|
||||
</request>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy the manager">
|
||||
All objects created by the manager will still remain valid, until their
|
||||
appropriate destroy request has been called.
|
||||
</description>
|
||||
</request>
|
||||
</interface>
|
||||
|
||||
<interface name="zwlr_gamma_control_v1" version="1">
|
||||
<description summary="adjust gamma tables for an output">
|
||||
This interface allows a client to adjust gamma tables for a particular
|
||||
output.
|
||||
|
||||
The client will receive the gamma size, and will then be able to set gamma
|
||||
tables. At any time the compositor can send a failed event indicating that
|
||||
this object is no longer valid.
|
||||
|
||||
There must always be at most one gamma control object per output, which
|
||||
has exclusive access to this particular output. When the gamma control
|
||||
object is destroyed, the gamma table is restored to its original value.
|
||||
</description>
|
||||
|
||||
<event name="gamma_size">
|
||||
<description summary="size of gamma ramps">
|
||||
Advertise the size of each gamma ramp.
|
||||
|
||||
This event is sent immediately when the gamma control object is created.
|
||||
</description>
|
||||
<arg name="size" type="uint" summary="number of elements in a ramp"/>
|
||||
</event>
|
||||
|
||||
<enum name="error">
|
||||
<entry name="invalid_gamma" value="1" summary="invalid gamma tables"/>
|
||||
</enum>
|
||||
|
||||
<request name="set_gamma">
|
||||
<description summary="set the gamma table">
|
||||
Set the gamma table. The file descriptor can be memory-mapped to provide
|
||||
the raw gamma table, which contains successive gamma ramps for the red,
|
||||
green and blue channels. Each gamma ramp is an array of 16-byte unsigned
|
||||
integers which has the same length as the gamma size.
|
||||
|
||||
The file descriptor data must have the same length as three times the
|
||||
gamma size.
|
||||
</description>
|
||||
<arg name="fd" type="fd" summary="gamma table file descriptor"/>
|
||||
</request>
|
||||
|
||||
<event name="failed">
|
||||
<description summary="object no longer valid">
|
||||
This event indicates that the gamma control is no longer valid. This
|
||||
can happen for a number of reasons, including:
|
||||
- The output doesn't support gamma tables
|
||||
- Setting the gamma tables failed
|
||||
- Another client already has exclusive gamma control for this output
|
||||
- The compositor has transferred gamma control to another client
|
||||
|
||||
Upon receiving this event, the client should destroy this object.
|
||||
</description>
|
||||
</event>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy this control">
|
||||
Destroys the gamma control object. If the object is still valid, this
|
||||
restores the original gamma tables.
|
||||
</description>
|
||||
</request>
|
||||
</interface>
|
||||
</protocol>
|
||||
Loading…
Add table
Add a link
Reference in a new issue