This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch wl-virtual-output
in repository enlightenment.
View the commit online.
commit 69874fdec9ee9ae8408b2bf930090555f8358805
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Dec 1 18:50:18 2026 -0600
e_comp_wl - let a module resize the headless output
A headless session has to follow the size of the remote client's
window, and the wl_buffer backend had no way to change its output after
start: the canvas, the zone and the wl_output all kept the size it was
created with.
e_comp_wl_virtual_output_set() resizes the canvas, zone 0 and the
wl_output of the buffer backend, which tells bound clients (wl_output
mode, scale and done, xdg_output logical size) and reconfigures
maximized and fullscreen clients, to the new size in surface-local
units. Only one output is supported, the one wl_buffer makes at start,
now named VIRTUAL-1 instead of having no id. It fails with an error for
any other id, a size below 1, a scale below 1, a canvas with more than
one zone, and on a backend that owns real outputs (wl_drm, wl_x11,
wl_wl). The backend opts in with a flag on e_comp_wl, since nothing in
the resize is specific to it.
The scale is whole, as every output scale in E is: wl_output.scale
rounds and xdg_output truncates, so a fraction would disagree with
itself. It is handed to the output scale E already sends; no scaling
work is added.
A change of the scale alone leaves the zone the same size, so the zone
resize that reconfigures maximized and fullscreen clients does not
happen, and the rescale that follows works from the buffer the client
drew. The call sends those clients a configure itself in that case.
No shared file is changed. e_comp_canvas_resize() and
e_comp_canvas_update() are called as wl_wl and e_randr2 do. The wl_test
protocol gets virtual_output_set (version 13) so that a test can drive
it and read the refusal.
Tested with the default suite, the x11 suite (private Xvfb) and the new
wl-virtual-output and wl-virtual-output-zones tests, 20 repeats.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
---
src/bin/e_comp_wl.c | 79 ++++++
src/bin/e_comp_wl.h | 2 +
src/modules/wl_buffer/e_mod_main.c | 11 +-
src/modules/wl_test/e_mod_main.c | 10 +-
src/protocol/wl-test.xml | 18 +-
src/tests/wayland/e_wl_testkit.c | 26 +-
src/tests/wayland/e_wl_testkit.h | 5 +
src/tests/wayland/meson.build | 2 +
src/tests/wayland/test_virtual_output.c | 362 ++++++++++++++++++++++++++
src/tests/wayland/test_virtual_output_zones.c | 113 ++++++++
10 files changed, 611 insertions(+), 17 deletions(-)
diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c
index 12a8afe38..5ad43dc4d 100644
--- a/src/bin/e_comp_wl.c
+++ b/src/bin/e_comp_wl.c
@@ -4372,6 +4372,85 @@ e_comp_wl_output_remove(const char *id)
ecore_timer_loop_add(5.0, _e_comp_wl_output_destroy_cb, output);
}
+/* A client of the zone that is maximized or fullscreen keeps its size in
+ * canvas pixels when only the scale of the output changes, so nothing else
+ * tells it that the same pixels are now fewer surface-local units. The
+ * rescale that follows works from the buffer it drew, which is too late. */
+static void
+_e_comp_wl_zone_clients_configure_send(E_Zone *zone)
+{
+ E_Client *ec;
+
+ E_CLIENT_FOREACH(ec)
+ {
+ if (e_object_is_del(E_OBJECT(ec))) continue;
+ if (e_pixmap_type_get(ec->pixmap) != E_PIXMAP_TYPE_WL) continue;
+ if (ec->zone != zone) continue;
+ if ((!ec->fullscreen) && (!ec->maximized)) continue;
+ if (!ec->comp_data->shell.configure_send) continue;
+ _e_comp_wl_configure_send(ec, 0, EINA_TRUE);
+ }
+}
+
+/**
+ * Resizes the output of a backend that has no real one.
+ *
+ * Only the headless backend, which makes a single output at start, takes
+ * this: the backends that own real outputs follow the monitors instead.
+ * Maximized and fullscreen clients are configured for the new size and
+ * scale.
+ *
+ * @param id name of the output, as the backend gave it
+ * @param w new width of the canvas in pixels, above 0
+ * @param h new height of the canvas in pixels, above 0
+ * @param scale whole scale of the output, 1 or more
+ *
+ * @returns True if the canvas, the zone and the output were resized
+ */
+E_API Eina_Bool
+e_comp_wl_virtual_output_set(const char *id, int w, int h, int scale)
+{
+ E_Comp_Wl_Output *output;
+ E_Zone *zone;
+ Eina_Bool scale_only;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(id, EINA_FALSE);
+ if (!e_comp_wl->virtual_output)
+ {
+ ERR("this backend owns real outputs, cannot resize \"%s\"", id);
+ return EINA_FALSE;
+ }
+ if ((w <= 0) || (h <= 0) || (scale < 1))
+ {
+ ERR("cannot resize output \"%s\" to %dx%d at scale %d", id, w, h, scale);
+ return EINA_FALSE;
+ }
+ if (eina_list_count(e_comp->zones) != 1)
+ {
+ ERR("cannot resize output \"%s\": the canvas has %d zones", id,
+ eina_list_count(e_comp->zones));
+ return EINA_FALSE;
+ }
+ zone = e_comp_zone_number_get(0);
+ output = zone ? zone->output : NULL;
+ if ((!output) || (!eina_streq(output->id, id)))
+ {
+ ERR("no virtual output \"%s\"", id);
+ return EINA_FALSE;
+ }
+
+ scale_only = ((w == output->w) && (h == output->h) &&
+ (scale != (int)output->scale));
+ e_comp_canvas_resize(w, h);
+ e_comp_canvas_update();
+ output->scale = scale;
+ if (scale_only) _e_comp_wl_zone_clients_configure_send(zone);
+ return e_comp_wl_output_init(output->id, output->make, output->model,
+ 0, 0, w, h, output->phys_width,
+ output->phys_height, output->refresh / 1000,
+ output->subpixel, output->transform, 0);
+}
+
/* Set while e_comp_wl_key_inject runs, to keep a key out of the grab it
* came back from. */
static Eina_Bool _key_injected = EINA_FALSE;
diff --git a/src/bin/e_comp_wl.h b/src/bin/e_comp_wl.h
index e6e93d3b1..5d111a895 100644
--- a/src/bin/e_comp_wl.h
+++ b/src/bin/e_comp_wl.h
@@ -365,6 +365,7 @@ struct _E_Comp_Wl_Data
Eina_List *efl_wls;
Eina_Bool dmabuf_disable E_BITFIELD;
+ Eina_Bool virtual_output E_BITFIELD;
};
struct _E_Comp_Wl_Client_Data
@@ -530,6 +531,7 @@ E_API struct wl_signal e_comp_wl_surface_create_signal_get(void);
E_API double e_comp_wl_idle_time_get(void);
E_API Eina_Bool e_comp_wl_output_init(const char *id, const char *make, const char *model, int x, int y, int w, int h, int pw, int ph, unsigned int refresh, unsigned int subpixel, unsigned int transform, unsigned int num);
E_API void e_comp_wl_output_remove(const char *id);
+E_API Eina_Bool e_comp_wl_virtual_output_set(const char *id, int w, int h, int scale);
E_API int e_comp_wl_client_scale_get(const E_Client *ec);
EINTERN Eina_Bool e_comp_wl_key_down(Ecore_Event_Key *ev, E_Client *ec);
diff --git a/src/modules/wl_buffer/e_mod_main.c b/src/modules/wl_buffer/e_mod_main.c
index 50424a8be..720a04a0e 100644
--- a/src/modules/wl_buffer/e_mod_main.c
+++ b/src/modules/wl_buffer/e_mod_main.c
@@ -2,6 +2,8 @@
E_API E_Module_Api e_modapi = { E_MODULE_API_VERSION, "Wl_Buffer" };
+#define E_WL_BUFFER_OUTPUT_ID "VIRTUAL-1"
+
/* The canvas size: E_COMP_SIZE=WxH as e_comp_canvas_init() reads it, so
* that the canvas, the zone and the output agree, or 1024x768. */
static Eina_Bool
@@ -45,8 +47,13 @@ e_modapi_init(E_Module *m)
EINA_SAFETY_ON_TRUE_RETURN_VAL(!e_comp_canvas_init(w, h), NULL);
/* The randr path that creates outputs on other backends never runs
- * behind an ecore_evas_buffer, so the output is made here, as wl_wl does. */
- e_comp_wl_output_init(NULL, NULL, NULL, 0, 0, w, h, 0, 0, 0, 0, 0, 0);
+ * behind an ecore_evas_buffer, so the output is made here, as wl_wl does.
+ * e_comp_wl_output_init() finds the zone by its randr id, which a zone
+ * made outside that path does not have. */
+ e_comp_zone_number_get(0)->randr2_id = strdup(E_WL_BUFFER_OUTPUT_ID);
+ e_comp_wl_output_init(E_WL_BUFFER_OUTPUT_ID, NULL, NULL, 0, 0, w, h, 0, 0,
+ 0, 0, 0, 0);
+ e_comp_wl->virtual_output = EINA_TRUE;
ecore_event_evas_init();
ecore_evas_input_event_register(e_comp->ee);
diff --git a/src/modules/wl_test/e_mod_main.c b/src/modules/wl_test/e_mod_main.c
index ad360f009..9dbff24ae 100644
--- a/src/modules/wl_test/e_mod_main.c
+++ b/src/modules/wl_test/e_mod_main.c
@@ -708,6 +708,13 @@ _wl_test_cb_get_format_alpha(struct wl_client *client EINA_UNUSED, struct wl_res
e_pixmap_format_has_alpha(format));
}
+static void
+_wl_test_cb_virtual_output_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, const char *id, int32_t w, int32_t h, int32_t scale)
+{
+ wl_test_send_virtual_output_result(resource,
+ e_comp_wl_virtual_output_set(id, w, h, scale));
+}
+
static const struct wl_test_interface _wl_test_implementation =
{
_wl_test_cb_destroy,
@@ -735,6 +742,7 @@ static const struct wl_test_interface _wl_test_implementation =
_wl_test_cb_output_scale_set,
_wl_test_cb_output_remove,
_wl_test_cb_get_format_alpha,
+ _wl_test_cb_virtual_output_set,
};
static void
@@ -768,7 +776,7 @@ e_modapi_init(E_Module *m)
return NULL;
}
- _wl_test_global = wl_global_create(e_comp_wl->wl.disp, &wl_test_interface, 12,
+ _wl_test_global = wl_global_create(e_comp_wl->wl.disp, &wl_test_interface, 13,
NULL, _wl_test_cb_bind);
if (!_wl_test_global)
{
diff --git a/src/protocol/wl-test.xml b/src/protocol/wl-test.xml
index 87e22d7c7..a9f295d3d 100644
--- a/src/protocol/wl-test.xml
+++ b/src/protocol/wl-test.xml
@@ -23,7 +23,7 @@
DEALINGS IN THE SOFTWARE.
</copyright>
- <interface name="wl_test" version="12">
+ <interface name="wl_test" version="13">
<description summary="private interface for the compositor test suite">
A back door into the compositor for its own test suite. It exposes
internal state and synthesises input, so it is only built with
@@ -395,5 +395,21 @@
<arg name="format" type="uint"/>
<arg name="alpha" type="uint" summary="1 if blended, 0 if opaque"/>
</event>
+
+ <request name="virtual_output_set" since="13">
+ <description summary="resize the output of the headless backend">
+ Calls e_comp_wl_virtual_output_set() and answers with a
+ virtual_output_result event, so that a test can tell a refusal from
+ a resize that has not landed yet.
+ </description>
+ <arg name="id" type="string" summary="name of the output"/>
+ <arg name="w" type="int" summary="canvas pixels"/>
+ <arg name="h" type="int" summary="canvas pixels"/>
+ <arg name="scale" type="int"/>
+ </request>
+
+ <event name="virtual_output_result" since="13">
+ <arg name="ok" type="uint" summary="1 if E resized the output, 0 if it refused"/>
+ </event>
</interface>
</protocol>
diff --git a/src/tests/wayland/e_wl_testkit.c b/src/tests/wayland/e_wl_testkit.c
index d2b1be0fb..33d2ad534 100644
--- a/src/tests/wayland/e_wl_testkit.c
+++ b/src/tests/wayland/e_wl_testkit.c
@@ -659,8 +659,8 @@ tk_expect(Tk *tk, const char *app_id)
return c;
}
-static double
-_tk_now(void)
+double
+tk_now(void)
{
struct timespec ts;
@@ -668,8 +668,8 @@ _tk_now(void)
return ts.tv_sec + (ts.tv_nsec / 1e9);
}
-static int
-_tk_wait_seconds(void)
+int
+tk_wait_seconds(void)
{
const char *s = getenv("E_TEST_WAIT_SECONDS");
@@ -680,42 +680,42 @@ Tk_Client *
tk_wait_states(Tk *tk, const char *app_id, unsigned int mask,
unsigned int want, const char *what)
{
- double deadline = _tk_now() + _tk_wait_seconds();
+ double deadline = tk_now() + tk_wait_seconds();
Tk_Client *c;
for (;;)
{
c = tk_expect(tk, app_id);
if ((c->states & mask) == want) return c;
- if (_tk_now() > deadline) break;
+ if (tk_now() > deadline) break;
tk_sync(tk);
}
tk_fail(tk, "%s: states still 0x%x after %ds, waiting for 0x%x in 0x%x",
- what, c->states, _tk_wait_seconds(), want, mask);
+ what, c->states, tk_wait_seconds(), want, mask);
}
Tk_Client *
tk_wait(Tk *tk, const char *app_id, int (*done)(const Tk_Client *c, void *data),
void *data, const char *what)
{
- double deadline = _tk_now() + _tk_wait_seconds();
+ double deadline = tk_now() + tk_wait_seconds();
Tk_Client *c;
for (;;)
{
c = tk_expect(tk, app_id);
if (done(c, data)) return c;
- if (_tk_now() > deadline) break;
+ if (tk_now() > deadline) break;
tk_sync(tk);
}
tk_fail(tk, "%s: still %dx%d+%d+%d states 0x%x output %u after %ds", what,
- c->w, c->h, c->x, c->y, c->states, c->output, _tk_wait_seconds());
+ c->w, c->h, c->x, c->y, c->states, c->output, tk_wait_seconds());
}
Tk_Client *
tk_wait_window(Tk *tk, const char *app_id_part)
{
- double deadline = _tk_now() + _tk_wait_seconds();
+ double deadline = tk_now() + tk_wait_seconds();
Tk_Client *best;
int i, n;
@@ -732,11 +732,11 @@ tk_wait_window(Tk *tk, const char *app_id_part)
if ((!best) || ((c->w * c->h) > (best->w * best->h))) best = c;
}
if (best) return best;
- if (_tk_now() > deadline) break;
+ if (tk_now() > deadline) break;
tk_sync(tk);
}
tk_fail(tk, "no shown window with an app_id containing '%s' after %ds",
- app_id_part, _tk_wait_seconds());
+ app_id_part, tk_wait_seconds());
}
void
diff --git a/src/tests/wayland/e_wl_testkit.h b/src/tests/wayland/e_wl_testkit.h
index a01c84528..f15a98957 100644
--- a/src/tests/wayland/e_wl_testkit.h
+++ b/src/tests/wayland/e_wl_testkit.h
@@ -141,6 +141,11 @@ Tk_Client *tk_expect(Tk *tk, const char *app_id);
* masked by mask are want, and fails saying what it waited for if that
* takes more than TK_WAIT_SECONDS, or E_TEST_WAIT_SECONDS when set. */
#define TK_WAIT_SECONDS 10
+/* The clock the waits run on, in seconds, and how long they last:
+ * TK_WAIT_SECONDS, or E_TEST_WAIT_SECONDS when set. For a test that waits
+ * on a state tk_wait cannot see. */
+double tk_now(void);
+int tk_wait_seconds(void);
Tk_Client *tk_wait_states(Tk *tk, const char *app_id, unsigned int mask,
unsigned int want, const char *what);
/* The same, until done returns non-zero for the window. */
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index ced6ad90d..662bb10f1 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -124,6 +124,8 @@ wl_protocol_tests = [
['format-alpha', 'test_format_alpha.c'],
['dmabuf-feedback', 'test_dmabuf_feedback.c'],
['content-type', 'test_content_type.c'],
+ ['virtual-output', 'test_virtual_output.c'],
+ ['virtual-output-zones', 'test_virtual_output_zones.c'],
]
tk_src = files('e_wl_testkit.c')
diff --git a/src/tests/wayland/test_virtual_output.c b/src/tests/wayland/test_virtual_output.c
new file mode 100644
index 000000000..63446fcf2
--- /dev/null
+++ b/src/tests/wayland/test_virtual_output.c
@@ -0,0 +1,362 @@
+/* A module can resize the headless output while clients are mapped: the
+ * mode and logical size clients read follow, maximized and fullscreen
+ * windows are reconfigured, and the canvas E draws on is the new size. */
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include "e_wl_testkit.h"
+#include "xdg-output-unstable-v1-client-protocol.h"
+
+#define PROG "test-virtual-output"
+#define OUTPUT_ID "VIRTUAL-1"
+#define WHITE 0xffffffff
+
+typedef struct
+{
+ Tk *tk;
+ int mode_w, mode_h;
+ int scale;
+ int logical_w, logical_h;
+ /* The mode, scale and logical size as they were when the last done came. */
+ int done_mode_w, done_mode_h;
+ int done_scale;
+ int done_logical_w, done_logical_h;
+ int dones;
+ unsigned int result;
+ int answered;
+ unsigned int argb;
+ int pixel_answered;
+} Ctx;
+
+static Ctx ctx;
+
+static void
+_geometry(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)),
+ int32_t x __attribute__((unused)), int32_t y __attribute__((unused)),
+ int32_t pw __attribute__((unused)), int32_t ph __attribute__((unused)),
+ int32_t subpixel __attribute__((unused)), const char *make __attribute__((unused)),
+ const char *model __attribute__((unused)), int32_t transform __attribute__((unused)))
+{
+}
+
+static void
+_mode(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)),
+ uint32_t flags __attribute__((unused)), int32_t w, int32_t h,
+ int32_t refresh __attribute__((unused)))
+{
+ ctx.mode_w = w;
+ ctx.mode_h = h;
+}
+
+static void
+_done(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)))
+{
+ ctx.dones++;
+ ctx.done_mode_w = ctx.mode_w;
+ ctx.done_mode_h = ctx.mode_h;
+ ctx.done_scale = ctx.scale;
+ ctx.done_logical_w = ctx.logical_w;
+ ctx.done_logical_h = ctx.logical_h;
+}
+
+static void
+_scale(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)),
+ int32_t factor)
+{
+ ctx.scale = factor;
+}
+
+static void
+_name(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)),
+ const char *name __attribute__((unused)))
+{
+}
+
+static void
+_description(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)),
+ const char *description __attribute__((unused)))
+{
+}
+
+static const struct wl_output_listener _output_listener =
+{
+ _geometry, _mode, _done, _scale, _name, _description
+};
+
+static void
+_xdg_position(void *data __attribute__((unused)),
+ struct zxdg_output_v1 *o __attribute__((unused)),
+ int32_t x __attribute__((unused)), int32_t y __attribute__((unused)))
+{
+}
+
+static void
+_xdg_size(void *data __attribute__((unused)),
+ struct zxdg_output_v1 *o __attribute__((unused)), int32_t w, int32_t h)
+{
+ ctx.logical_w = w;
+ ctx.logical_h = h;
+}
+
+static void
+_xdg_done(void *data __attribute__((unused)),
+ struct zxdg_output_v1 *o __attribute__((unused)))
+{
+}
+
+static void
+_xdg_name(void *data __attribute__((unused)),
+ struct zxdg_output_v1 *o __attribute__((unused)),
+ const char *name __attribute__((unused)))
+{
+}
+
+static void
+_xdg_description(void *data __attribute__((unused)),
+ struct zxdg_output_v1 *o __attribute__((unused)),
+ const char *description __attribute__((unused)))
+{
+}
+
+static const struct zxdg_output_v1_listener _xdg_output_listener =
+{
+ _xdg_position, _xdg_size, _xdg_done, _xdg_name, _xdg_description
+};
+
+static void
+_virtual_output_result(void *data __attribute__((unused)),
+ struct wl_test *t __attribute__((unused)), uint32_t ok)
+{
+ ctx.result = ok;
+ ctx.answered = 1;
+}
+
+static void
+_pixel(void *data __attribute__((unused)), struct wl_test *t __attribute__((unused)),
+ int32_t x __attribute__((unused)), int32_t y __attribute__((unused)),
+ uint32_t argb)
+{
+ ctx.argb = argb;
+ ctx.pixel_answered = 1;
+}
+
+/* Only the events this test asks for are answered on its own wl_test. */
+static const struct wl_test_listener _tester_listener =
+{
+ .pixel = _pixel,
+ .virtual_output_result = _virtual_output_result
+};
+
+static unsigned int
+_virtual_output_set(struct wl_test *tester, const char *id, int w, int h,
+ int scale)
+{
+ ctx.answered = 0;
+ wl_test_virtual_output_set(tester, id, w, h, scale);
+ tk_sync(ctx.tk);
+ if (!ctx.answered)
+ tk_fail(ctx.tk, "no answer to virtual_output_set(%s, %d, %d, %d)", id, w,
+ h, scale);
+ return ctx.result;
+}
+
+/* Waits one compositor main loop iteration at a time, as tk_wait does. */
+static void
+_configured_wait(Tk_Toplevel *top, int w, int h, const char *what)
+{
+ double end = tk_now() + tk_wait_seconds();
+ int cw, ch;
+
+ for (;;)
+ {
+ tk_toplevel_configured(top, &cw, &ch, NULL);
+ if ((cw == w) && (ch == h)) return;
+ if (tk_now() > end)
+ tk_fail(ctx.tk, "%s: configured to %dx%d, wanted %dx%d", what, cw,
+ ch, w, h);
+ tk_sync(ctx.tk);
+ }
+}
+
+static void
+_maximized_wait(Tk_Toplevel *top, int above_w, int max_w, int max_h,
+ const char *what)
+{
+ double end = tk_now() + tk_wait_seconds();
+ int cw, ch;
+
+ for (;;)
+ {
+ tk_toplevel_configured(top, &cw, &ch, NULL);
+ if ((cw > above_w) && (cw <= max_w) && (ch > 0) && (ch <= max_h))
+ return;
+ if (tk_now() > end)
+ tk_fail(ctx.tk, "%s: configured to %dx%d, wanted wider than %d "
+ "and within %dx%d", what, cw, ch, above_w, max_w, max_h);
+ tk_sync(ctx.tk);
+ }
+}
+
+static unsigned int
+_pixel_get(struct wl_test *tester, int x, int y)
+{
+ ctx.pixel_answered = 0;
+ wl_test_get_pixel(tester, x, y);
+ tk_sync(ctx.tk);
+ if (!ctx.pixel_answered) tk_fail(ctx.tk, "no answer to get_pixel");
+ return ctx.argb;
+}
+
+static void
+_pixel_wait(struct wl_test *tester, int x, int y, unsigned int want,
+ const char *what)
+{
+ double end = tk_now() + tk_wait_seconds();
+ unsigned int argb;
+
+ for (;;)
+ {
+ argb = _pixel_get(tester, x, y);
+ if (argb == want) return;
+ if (tk_now() > end)
+ tk_fail(ctx.tk, "%s: pixel %d,%d is %#x, wanted %#x", what, x, y,
+ argb, want);
+ }
+}
+
+static void
+_mode_check(int w, int h, int scale, const char *what)
+{
+ if ((ctx.done_mode_w != w) || (ctx.done_mode_h != h))
+ tk_fail(ctx.tk, "%s: the mode at wl_output.done is %dx%d, wanted %dx%d",
+ what, ctx.done_mode_w, ctx.done_mode_h, w, h);
+ if (ctx.done_scale != scale)
+ tk_fail(ctx.tk, "%s: the scale at wl_output.done is %d, wanted %d", what,
+ ctx.done_scale, scale);
+ if ((ctx.done_logical_w != w / scale) || (ctx.done_logical_h != h / scale))
+ tk_fail(ctx.tk, "%s: the logical size at wl_output.done is %dx%d, "
+ "wanted %dx%d", what, ctx.done_logical_w, ctx.done_logical_h,
+ w / scale, h / scale);
+}
+
+static void
+_resize(struct wl_test *tester, int w, int h, int scale, const char *what)
+{
+ int dones = ctx.dones;
+
+ if (!_virtual_output_set(tester, OUTPUT_ID, w, h, scale))
+ tk_fail(ctx.tk, "%s: E refused to resize %s to %dx%d at scale %d", what,
+ OUTPUT_ID, w, h, scale);
+ if (ctx.dones <= dones)
+ tk_fail(ctx.tk, "%s: no wl_output.done after the resize", what);
+ _mode_check(w, h, scale, what);
+}
+
+/* What every client must have been told once the output is w x h at this
+ * scale: the fullscreen one exactly the logical size, the maximized one
+ * within it and wider than above_w. */
+static void
+_clients_check(Tk_Toplevel *maximized, Tk_Toplevel *fullscreen, int w, int h,
+ int scale, int above_w, const char *what)
+{
+ _configured_wait(fullscreen, w / scale, h / scale, what);
+ _maximized_wait(maximized, above_w, w / scale, h / scale, what);
+}
+
+static void
+_refused(struct wl_test *tester, const char *id, int w, int h, int scale,
+ const char *what)
+{
+ int dones = ctx.dones;
+ int mode_w = ctx.mode_w, mode_h = ctx.mode_h;
+
+ if (_virtual_output_set(tester, id, w, h, scale))
+ tk_fail(ctx.tk, "%s: E accepted virtual_output_set(%s, %d, %d, %d)",
+ what, id, w, h, scale);
+ tk_settle(ctx.tk);
+ if ((ctx.dones != dones) || (ctx.mode_w != mode_w) || (ctx.mode_h != mode_h))
+ tk_fail(ctx.tk, "%s: refused, but the output changed to %dx%d (%d "
+ "dones, was %d)", what, ctx.mode_w, ctx.mode_h, ctx.dones, dones);
+}
+
+int
+main(void)
+{
+ Tk *tk;
+ Tk_Toplevel *maximized, *fullscreen;
+ struct wl_test *tester;
+ struct wl_output *output;
+ struct zxdg_output_manager_v1 *manager;
+ struct zxdg_output_v1 *xdg;
+ int start_w, start_h;
+
+ tk = tk_connect(PROG);
+ ctx.tk = tk;
+
+ tester = tk_bind(tk, &wl_test_interface, 13);
+ if (!tester) tk_fail(tk, "no wl_test version 13");
+ wl_test_add_listener(tester, &_tester_listener, NULL);
+
+ output = tk_bind(tk, &wl_output_interface, 4);
+ if (!output) tk_fail(tk, "no wl_output");
+ wl_output_add_listener(output, &_output_listener, NULL);
+ manager = tk_bind(tk, &zxdg_output_manager_v1_interface, 3);
+ if (!manager) tk_fail(tk, "no zxdg_output_manager_v1");
+ xdg = zxdg_output_manager_v1_get_xdg_output(manager, output);
+ zxdg_output_v1_add_listener(xdg, &_xdg_output_listener, NULL);
+ tk_sync(tk);
+ if (!ctx.dones) tk_fail(tk, "wl_output sent no done");
+ start_w = ctx.mode_w;
+ start_h = ctx.mode_h;
+ if ((start_w <= 0) || (start_h <= 0))
+ tk_fail(tk, "the output starts at %dx%d", start_w, start_h);
+
+ maximized = tk_toplevel_new(tk, "e.test.virtual_output.max", "max", 200, 150);
+ tk_toplevel_maximize(maximized, 1);
+ fullscreen = tk_toplevel_new(tk, "e.test.virtual_output.fs", "fs", 200, 150);
+ xdg_toplevel_set_fullscreen(tk_toplevel_xdg(fullscreen), NULL);
+ tk_settle(tk);
+ _configured_wait(fullscreen, start_w, start_h, "fullscreen at the start");
+
+ _refused(tester, "NO-SUCH-OUTPUT", 1280, 720, 1, "unknown id");
+ _refused(tester, OUTPUT_ID, 0, 720, 1, "no width");
+ _refused(tester, OUTPUT_ID, 1280, 0, 1, "no height");
+ _refused(tester, OUTPUT_ID, -1280, 720, 1, "negative width");
+ _refused(tester, OUTPUT_ID, 1280, -720, 1, "negative height");
+ _refused(tester, OUTPUT_ID, 1280, 720, 0, "no scale");
+ _refused(tester, OUTPUT_ID, 1280, 720, -1, "negative scale");
+ _mode_check(start_w, start_h, 1, "after the refusals");
+
+ /* Wider than the start and shorter at once. */
+ _resize(tester, 1280, 720, 1, "to 1280x720");
+ _clients_check(maximized, fullscreen, 1280, 720, 1, start_w, "1280x720");
+ _pixel_wait(tester, 1279, 719, WHITE, "fullscreen at 1280x720");
+ _pixel_wait(tester, 640, 360, WHITE, "fullscreen at 1280x720");
+
+ /* Smaller than the start in both. */
+ _resize(tester, 800, 600, 1, "to 800x600");
+ _clients_check(maximized, fullscreen, 800, 600, 1, 0, "800x600");
+ _pixel_wait(tester, 799, 599, WHITE, "fullscreen at 800x600");
+
+ /* The scale alone: the same pixels are fewer surface-local units. */
+ _resize(tester, 800, 600, 2, "800x600 to scale 2");
+ _clients_check(maximized, fullscreen, 800, 600, 2, 0, "800x600 at scale 2");
+ _pixel_wait(tester, 799, 599, WHITE, "fullscreen at 800x600, scale 2");
+ _resize(tester, 800, 600, 1, "800x600 back to scale 1");
+ _clients_check(maximized, fullscreen, 800, 600, 1, 400, "800x600 at scale 1");
+
+ /* Both at once. */
+ _resize(tester, 1280, 720, 2, "to 1280x720 at scale 2");
+ _clients_check(maximized, fullscreen, 1280, 720, 2, 0, "1280x720 at scale 2");
+ _pixel_wait(tester, 1279, 719, WHITE, "fullscreen at 1280x720, scale 2");
+
+ tk_toplevel_del(fullscreen);
+ tk_toplevel_del(maximized);
+ zxdg_output_v1_destroy(xdg);
+ zxdg_output_manager_v1_destroy(manager);
+ wl_output_release(output);
+ tk_sync(tk);
+ tk_disconnect(tk);
+ printf(PROG ": ok\n");
+ return 0;
+}
diff --git a/src/tests/wayland/test_virtual_output_zones.c b/src/tests/wayland/test_virtual_output_zones.c
new file mode 100644
index 000000000..7969e0a4e
--- /dev/null
+++ b/src/tests/wayland/test_virtual_output_zones.c
@@ -0,0 +1,113 @@
+/* With a second zone, resizing the headless output is refused: the canvas
+ * would no longer be the size of one zone, and the resize would stretch
+ * zone 0 over all of it. */
+#include <stdio.h>
+#include "e_wl_testkit.h"
+
+#define PROG "test-virtual-output-zones"
+#define OUTPUT_ID "VIRTUAL-1"
+
+typedef struct
+{
+ int mode_w, mode_h;
+ unsigned int result;
+ int answered;
+} Ctx;
+
+static Ctx ctx;
+
+static void
+_geometry(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)),
+ int32_t x __attribute__((unused)), int32_t y __attribute__((unused)),
+ int32_t pw __attribute__((unused)), int32_t ph __attribute__((unused)),
+ int32_t subpixel __attribute__((unused)), const char *make __attribute__((unused)),
+ const char *model __attribute__((unused)), int32_t transform __attribute__((unused)))
+{
+}
+
+static void
+_mode(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)),
+ uint32_t flags __attribute__((unused)), int32_t w, int32_t h,
+ int32_t refresh __attribute__((unused)))
+{
+ ctx.mode_w = w;
+ ctx.mode_h = h;
+}
+
+static void
+_done(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)))
+{
+}
+
+static void
+_scale(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)),
+ int32_t factor __attribute__((unused)))
+{
+}
+
+static void
+_name(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)),
+ const char *name __attribute__((unused)))
+{
+}
+
+static void
+_description(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)),
+ const char *description __attribute__((unused)))
+{
+}
+
+static const struct wl_output_listener _output_listener =
+{
+ _geometry, _mode, _done, _scale, _name, _description
+};
+
+static void
+_virtual_output_result(void *data __attribute__((unused)),
+ struct wl_test *t __attribute__((unused)), uint32_t ok)
+{
+ ctx.result = ok;
+ ctx.answered = 1;
+}
+
+static const struct wl_test_listener _tester_listener =
+{
+ .virtual_output_result = _virtual_output_result
+};
+
+int
+main(void)
+{
+ Tk *tk;
+ struct wl_test *tester;
+ struct wl_output *output;
+ int start_w, start_h;
+
+ tk = tk_connect(PROG);
+ tester = tk_bind(tk, &wl_test_interface, 13);
+ if (!tester) tk_fail(tk, "no wl_test version 13");
+ wl_test_add_listener(tester, &_tester_listener, NULL);
+ output = tk_bind(tk, &wl_output_interface, 4);
+ if (!output) tk_fail(tk, "no wl_output");
+ wl_output_add_listener(output, &_output_listener, NULL);
+ tk_sync(tk);
+ start_w = ctx.mode_w;
+ start_h = ctx.mode_h;
+
+ wl_test_zone_add(tester, start_w, 0, 640, 480);
+ tk_settle(tk);
+
+ wl_test_virtual_output_set(tester, OUTPUT_ID, start_w + 100, start_h + 100, 1);
+ tk_settle(tk);
+ if (!ctx.answered) tk_fail(tk, "no answer to virtual_output_set");
+ if (ctx.result) tk_fail(tk, "E resized the output with two zones");
+ if ((ctx.mode_w != start_w) || (ctx.mode_h != start_h))
+ tk_fail(tk, "refused, but the mode is now %dx%d, was %dx%d", ctx.mode_w,
+ ctx.mode_h, start_w, start_h);
+
+ wl_output_release(output);
+ tk_sync(tk);
+ tk_disconnect(tk);
+ printf(PROG ": ok\n");
+ return 0;
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.