This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch up/x11-iconify-flake
in repository enlightenment.
View the commit online.
commit fa55e3bc8773af3114599a8fe873eb9125dc1825
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 28 14:13:34 2026 -0600
e_comp_wl - add wp_fractional_scale_v1
A client that knows the scale of its output draws its buffer at that
scale and shows it through a wp_viewport destination, one buffer pixel
per screen pixel. wp_fractional_scale_v1 is how it learns the scale, in
120ths. Firefox and Chromium use it in preference to wl_surface
.set_buffer_scale, and Firefox warns when it is missing.
The scale is sent when a client asks for it, and again when its window
moves to another zone, which may be an output of another scale. A scale
changed under a window is not sent, as wl_output.scale only reaches the
window at its next commit either.
E's output scales are whole numbers, so the preferred scale is a
multiple of 120. That is still the right answer: a client on an output
of scale 2 is told 240 and draws at twice its size. Fractional output
scales need E's own coordinates to stop being whole screen pixels,
which this does not change.
wl-fractional-scale shows a 200x100 buffer through a 100x50 destination
on an output of scale 2, one to one, asks for the scale once the window
is shown and gets 240, gets 120 after moving to an output of scale 1,
and is refused a second object for the surface. It fails without the
send on creation, without the send on a zone change, with the scale
always 120, and when a second object is accepted. The zone change of
an X window under Xwayland is skipped, as its comp_data is not
Wayland's: wl-xwayland-close, -restore and -early-map crash E without
that check. wlcs's two
FractionalScaleV1 tests now run and pass.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/bin/e_comp_wl.c | 2 +
src/bin/e_comp_wl.h | 8 +-
src/bin/e_comp_wl_extensions.c | 87 ++++++++++++++++
src/bin/generated/meson.build | 1 +
src/tests/wayland/globals.expected | 1 +
src/tests/wayland/meson.build | 2 +
src/tests/wayland/test_fractional_scale.c | 161 ++++++++++++++++++++++++++++++
src/tests/wlcs/e_wlcs.c | 1 +
8 files changed, 262 insertions(+), 1 deletion(-)
diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c
index 297d49867..0af28d505 100644
--- a/src/bin/e_comp_wl.c
+++ b/src/bin/e_comp_wl.c
@@ -3269,6 +3269,8 @@ _e_comp_wl_client_cb_del(void *data EINA_UNUSED, E_Client *ec)
wl_resource_set_user_data(ec->comp_data->shortcuts_inhibitor, NULL);
if (ec->comp_data->viewport_resource)
wl_resource_set_user_data(ec->comp_data->viewport_resource, NULL);
+ if (ec->comp_data->fractional_scale_resource)
+ wl_resource_set_user_data(ec->comp_data->fractional_scale_resource, NULL);
_e_comp_wl_touch_points_drop(ec);
/* remove sub list */
diff --git a/src/bin/e_comp_wl.h b/src/bin/e_comp_wl.h
index 6d5e01d21..e2ef440c8 100644
--- a/src/bin/e_comp_wl.h
+++ b/src/bin/e_comp_wl.h
@@ -189,6 +189,10 @@ typedef struct E_Comp_Wl_Extension_Data
{
struct wl_global *global;
} wp_viewporter;
+ struct
+ {
+ struct wl_global *global;
+ } wp_fractional_scale_manager_v1;
struct
{
struct wl_global *global;
@@ -398,8 +402,10 @@ struct _E_Comp_Wl_Client_Data
int buffer_transform;
E_Comp_Wl_Viewport viewport;
int surface_w, surface_h;
- /* The surface's wp_viewport: there is at most one. */
+ /* The surface's wp_viewport and wp_fractional_scale_v1: there is at
+ * most one of each. */
struct wl_resource *viewport_resource;
+ struct wl_resource *fractional_scale_resource;
Eina_List *frames;
/* wp_presentation_feedback of the committed content, which is waiting
diff --git a/src/bin/e_comp_wl_extensions.c b/src/bin/e_comp_wl_extensions.c
index 079582b3f..007fcb303 100644
--- a/src/bin/e_comp_wl_extensions.c
+++ b/src/bin/e_comp_wl_extensions.c
@@ -14,6 +14,7 @@
#include "presentation-time-server-protocol.h"
#include "keyboard-shortcuts-inhibit-unstable-v1-server-protocol.h"
#include "viewporter-server-protocol.h"
+#include "fractional-scale-v1-server-protocol.h"
/* mutter uses 32, seems reasonable */
#define HANDLE_LEN 32
@@ -1800,6 +1801,89 @@ static const struct wp_viewporter_interface _e_wp_viewporter_interface =
_e_wp_viewporter_cb_get_viewport,
};
+/* wp_fractional_scale_v1 tells a surface the scale to draw at, in 120ths;
+ * the client then shows its buffer through a wp_viewport destination.
+ * Output scales are whole numbers in E, so this is always a multiple of
+ * 120. The user data is the E_Client, NULL once the surface is gone. */
+static void
+_e_fractional_scale_send(E_Client *ec)
+{
+ if (!ec->comp_data->fractional_scale_resource) return;
+ wp_fractional_scale_v1_send_preferred_scale(ec->comp_data->fractional_scale_resource,
+ e_comp_wl_client_scale_get(ec) * 120);
+}
+
+static void
+_e_wp_fractional_scale_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
+{
+ wl_resource_destroy(resource);
+}
+
+static void
+_e_wp_fractional_scale_cb_resource_destroy(struct wl_resource *resource)
+{
+ E_Client *ec = wl_resource_get_user_data(resource);
+
+ if (ec) ec->comp_data->fractional_scale_resource = NULL;
+}
+
+static const struct wp_fractional_scale_v1_interface _e_wp_fractional_scale_v1_interface =
+{
+ _e_wp_fractional_scale_cb_destroy,
+};
+
+static void
+_e_wp_fractional_scale_manager_v1_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
+{
+ wl_resource_destroy(resource);
+}
+
+static void
+_e_wp_fractional_scale_manager_v1_cb_get_fractional_scale(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface)
+{
+ E_Client *ec = wl_resource_get_user_data(surface);
+ struct wl_resource *res;
+
+ if ((ec) && (ec->comp_data->fractional_scale_resource))
+ {
+ wl_resource_post_error(resource,
+ WP_FRACTIONAL_SCALE_MANAGER_V1_ERROR_FRACTIONAL_SCALE_EXISTS,
+ "the surface already has a fractional scale");
+ return;
+ }
+ res = wl_resource_create(client, &wp_fractional_scale_v1_interface,
+ wl_resource_get_version(resource), id);
+ if (!res)
+ {
+ wl_resource_post_no_memory(resource);
+ return;
+ }
+ wl_resource_set_implementation(res, &_e_wp_fractional_scale_v1_interface, ec,
+ _e_wp_fractional_scale_cb_resource_destroy);
+ if (!ec) return;
+ ec->comp_data->fractional_scale_resource = res;
+ _e_fractional_scale_send(ec);
+}
+
+static const struct wp_fractional_scale_manager_v1_interface _e_wp_fractional_scale_manager_v1_interface =
+{
+ _e_wp_fractional_scale_manager_v1_cb_destroy,
+ _e_wp_fractional_scale_manager_v1_cb_get_fractional_scale,
+};
+
+/* Another zone may be another output, with another scale. The comp_data
+ * of an X window is not E_Comp_Wl_Client_Data. */
+static Eina_Bool
+_e_fractional_scale_cb_zone_set(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
+{
+ E_Event_Client_Zone_Set *ev = event;
+
+ if ((!e_object_is_del(E_OBJECT(ev->ec))) &&
+ (e_pixmap_type_get(ev->ec->pixmap) == E_PIXMAP_TYPE_WL))
+ _e_fractional_scale_send(ev->ec);
+ return ECORE_CALLBACK_RENEW;
+}
+
#define GLOBAL_BIND_CB(NAME, IFACE, ...) \
static void \
_e_comp_wl_##NAME##_cb_bind(struct wl_client *client, void *data EINA_UNUSED, uint32_t version, uint32_t id) \
@@ -1829,6 +1913,7 @@ GLOBAL_BIND_CB(xdg_activation_v1, xdg_activation_v1_interface)
GLOBAL_BIND_CB(zwp_idle_inhibit_manager_v1, zwp_idle_inhibit_manager_v1_interface)
GLOBAL_BIND_CB(zwp_keyboard_shortcuts_inhibit_manager_v1, zwp_keyboard_shortcuts_inhibit_manager_v1_interface)
GLOBAL_BIND_CB(wp_viewporter, wp_viewporter_interface)
+GLOBAL_BIND_CB(wp_fractional_scale_manager_v1, wp_fractional_scale_manager_v1_interface)
GLOBAL_BIND_CB(wp_presentation, wp_presentation_interface,
wp_presentation_send_clock_id(res, CLOCK_MONOTONIC);
)
@@ -1938,10 +2023,12 @@ e_comp_wl_extensions_init(void)
GLOBAL_CREATE_OR_RETURN(wp_presentation, wp_presentation_interface, 1);
GLOBAL_CREATE_OR_RETURN(zwp_keyboard_shortcuts_inhibit_manager_v1, zwp_keyboard_shortcuts_inhibit_manager_v1_interface, 1);
GLOBAL_CREATE_OR_RETURN(wp_viewporter, wp_viewporter_interface, 1);
+ GLOBAL_CREATE_OR_RETURN(wp_fractional_scale_manager_v1, wp_fractional_scale_manager_v1_interface, 1);
if (!e_comp_wl_text_input_init()) return EINA_FALSE;
e_comp_wl_privileges_init();
ecore_event_handler_add(ECORE_WL2_EVENT_SYNC_DONE, _dmabuf_add, NULL);
+ ecore_event_handler_add(E_EVENT_CLIENT_ZONE_SET, _e_fractional_scale_cb_zone_set, NULL);
e_client_hook_add(E_CLIENT_HOOK_MOVE_BEGIN, _e_comp_wl_extensions_client_move_begin, NULL);
e_client_hook_add(E_CLIENT_HOOK_MOVE_END, _e_comp_wl_extensions_client_move_end, NULL);
diff --git a/src/bin/generated/meson.build b/src/bin/generated/meson.build
index 0c0802299..814fde429 100644
--- a/src/bin/generated/meson.build
+++ b/src/bin/generated/meson.build
@@ -11,6 +11,7 @@ protos = [
'@0@/staging/xdg-activation/xdg-activation-v1.xml'.format(dir_wayland_protocols),
'@0@/stable/presentation-time/presentation-time.xml'.format(dir_wayland_protocols),
'@0@/stable/viewporter/viewporter.xml'.format(dir_wayland_protocols),
+ '@0@/staging/fractional-scale/fractional-scale-v1.xml'.format(dir_wayland_protocols),
'@0@/unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml'.format(dir_wayland_protocols),
'@0@/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'.format(dir_wayland_protocols),
'@0@/unstable/primary-selection/primary-selection-unstable-v1.xml'.format(dir_wayland_protocols),
diff --git a/src/tests/wayland/globals.expected b/src/tests/wayland/globals.expected
index ce13a074e..1e186b24e 100644
--- a/src/tests/wayland/globals.expected
+++ b/src/tests/wayland/globals.expected
@@ -7,6 +7,7 @@ wl_seat 8
wl_shell 1
wl_shm >=1
wl_subcompositor 1
+wp_fractional_scale_manager_v1 1
wp_presentation 1
wp_viewporter 1
xdg_activation_v1 1
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index b179cfe50..5ef264c00 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -33,6 +33,7 @@ foreach p: [
'@0@/staging/xdg-activation/xdg-activation-v1.xml'.format(dir_wayland_protocols),
'@0@/stable/presentation-time/presentation-time.xml'.format(dir_wayland_protocols),
'@0@/stable/viewporter/viewporter.xml'.format(dir_wayland_protocols),
+ '@0@/staging/fractional-scale/fractional-scale-v1.xml'.format(dir_wayland_protocols),
'@0@/staging/xdg-toplevel-drag/xdg-toplevel-drag-v1.xml'.format(dir_wayland_protocols),
'@0@/unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml'.format(dir_wayland_protocols),
'@0@/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'.format(dir_wayland_protocols),
@@ -93,6 +94,7 @@ wl_protocol_tests = [
['output-scale', 'test_output_scale.c'],
['buffer-transform', 'test_buffer_transform.c'],
['viewporter', 'test_viewporter.c'],
+ ['fractional-scale', 'test_fractional_scale.c'],
['activation', 'test_activation.c'],
['activation-expiry', 'test_activation.c',
{'E_TEST_ACTIVATION_TOKEN_LIFETIME': '1'}],
diff --git a/src/tests/wayland/test_fractional_scale.c b/src/tests/wayland/test_fractional_scale.c
new file mode 100644
index 000000000..d98707a1f
--- /dev/null
+++ b/src/tests/wayland/test_fractional_scale.c
@@ -0,0 +1,161 @@
+/* wp_fractional_scale_v1: a surface is told the scale of its output as
+ * soon as it asks, and again when it moves to an output of another scale.
+ * A client that follows it draws its buffer at that scale and shows it
+ * through a viewport destination, one buffer pixel per screen pixel. */
+#define _GNU_SOURCE 1
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <time.h>
+
+#include "e_wl_testkit.h"
+#include "viewporter-client-protocol.h"
+#include "fractional-scale-v1-client-protocol.h"
+
+#define PROG "test-fractional-scale"
+#define APP_ID "e.test.fractional-scale"
+
+typedef struct
+{
+ Tk *tk;
+ struct wl_shm *shm;
+ int configured;
+ uint32_t preferred;
+} Ctx;
+
+static void
+_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial)
+{
+ Ctx *ctx = data;
+
+ xdg_surface_ack_configure(xdg_surface, serial);
+ ctx->configured = 1;
+}
+
+static const struct xdg_surface_listener _xdg_surface_listener =
+{
+ _configure
+};
+
+static void
+_preferred_scale(void *data, struct wp_fractional_scale_v1 *fs __attribute__((unused)),
+ uint32_t scale)
+{
+ Ctx *ctx = data;
+
+ ctx->preferred = scale;
+}
+
+static const struct wp_fractional_scale_v1_listener _fractional_scale_listener =
+{
+ _preferred_scale
+};
+
+static struct wl_buffer *
+_buffer(Ctx *ctx, int w, int h)
+{
+ struct wl_shm_pool *pool;
+ struct wl_buffer *buffer;
+ int fd;
+
+ fd = memfd_create(PROG, MFD_CLOEXEC);
+ if ((fd < 0) || (ftruncate(fd, w * h * 4) < 0))
+ tk_fail(ctx->tk, "cannot make a %dx%d buffer", w, h);
+ pool = wl_shm_create_pool(ctx->shm, fd, w * h * 4);
+ buffer = wl_shm_pool_create_buffer(pool, 0, w, h, w * 4,
+ WL_SHM_FORMAT_XRGB8888);
+ wl_shm_pool_destroy(pool);
+ close(fd);
+ return buffer;
+}
+
+/* E moves a window to another zone through an event of its own main
+ * loop, so the scale may take more than one round trip to come. The caller
+ * clears ctx->preferred before what should send it. */
+static void
+_preferred_wait(Ctx *ctx, uint32_t want, const char *what)
+{
+ struct timespec step = { 0, 50000000 };
+ int i;
+
+ for (i = 0; (i < TK_WAIT_SECONDS * 20) && (!ctx->preferred); i++)
+ {
+ tk_sync(ctx->tk);
+ if (!ctx->preferred) nanosleep(&step, NULL);
+ }
+ if (ctx->preferred != want)
+ tk_fail(ctx->tk, "%s: preferred scale %u, wanted %u", what,
+ ctx->preferred, want);
+}
+
+int
+main(void)
+{
+ struct wp_fractional_scale_manager_v1 *manager;
+ struct wp_fractional_scale_v1 *fractional_scale;
+ struct wp_viewporter *viewporter;
+ struct wp_viewport *viewport;
+ struct xdg_surface *xdg_surface;
+ struct xdg_toplevel *toplevel;
+ struct wl_surface *surface;
+ struct wl_test *tester;
+ Ctx ctx = { 0 };
+ int w, h;
+
+ ctx.tk = tk_connect(PROG);
+ tester = tk_bind(ctx.tk, &wl_test_interface, 10);
+ ctx.shm = tk_bind(ctx.tk, &wl_shm_interface, 1);
+ viewporter = tk_bind(ctx.tk, &wp_viewporter_interface, 1);
+ manager = tk_bind(ctx.tk, &wp_fractional_scale_manager_v1_interface, 1);
+ if (!tester) tk_fail(ctx.tk, "no wl_test version 10");
+ if (!manager) tk_fail(ctx.tk, "no wp_fractional_scale_manager_v1");
+
+ wl_test_output_scale_set(tester, 0, 2);
+ tk_sync(ctx.tk);
+
+ surface = tk_surface_new(ctx.tk);
+ viewport = wp_viewporter_get_viewport(viewporter, surface);
+ xdg_surface = xdg_wm_base_get_xdg_surface(tk_wm_base(ctx.tk), surface);
+ xdg_surface_add_listener(xdg_surface, &_xdg_surface_listener, &ctx);
+ toplevel = xdg_surface_get_toplevel(xdg_surface);
+ xdg_toplevel_set_app_id(toplevel, APP_ID);
+ wl_surface_commit(surface);
+ while (!ctx.configured)
+ wl_display_dispatch(tk_display(ctx.tk));
+
+ /* 100x50 in surface-local units, drawn at 240/120. */
+ wp_viewport_set_destination(viewport, 100, 50);
+ wl_surface_attach(surface, _buffer(&ctx, 200, 100), 0, 0);
+ wl_surface_damage_buffer(surface, 0, 0, 200, 100);
+ wl_surface_commit(surface);
+ tk_settle(ctx.tk);
+ tk_expect(ctx.tk, APP_ID);
+ tk_surface_geometry(ctx.tk, surface, NULL, NULL, &w, &h);
+ if ((w != 200) || (h != 100))
+ tk_fail(ctx.tk, "a 200x100 buffer at 240/120 is shown at %dx%d", w, h);
+
+ /* Asked once the window is placed, it is answered at once. */
+ fractional_scale = wp_fractional_scale_manager_v1_get_fractional_scale(manager, surface);
+ wp_fractional_scale_v1_add_listener(fractional_scale, &_fractional_scale_listener, &ctx);
+ _preferred_wait(&ctx, 240, "a window on an output of scale 2");
+
+ wl_test_zone_add(tester, 1024, 0, 800, 600);
+ tk_sync(ctx.tk);
+ ctx.preferred = 0;
+ wl_test_move_surface(tester, surface, 1200, 100);
+ _preferred_wait(&ctx, 120, "moved to an output of scale 1");
+
+ wp_fractional_scale_manager_v1_get_fractional_scale(manager, surface);
+ if (tk_protocol_error(ctx.tk, NULL) !=
+ WP_FRACTIONAL_SCALE_MANAGER_V1_ERROR_FRACTIONAL_SCALE_EXISTS)
+ {
+ fprintf(stderr, PROG ": a second fractional scale was accepted\n");
+ return 1;
+ }
+
+ tk_disconnect(ctx.tk);
+ printf(PROG ": ok\n");
+ return 0;
+}
diff --git a/src/tests/wlcs/e_wlcs.c b/src/tests/wlcs/e_wlcs.c
index 3d3f8da35..164b1d750 100644
--- a/src/tests/wlcs/e_wlcs.c
+++ b/src/tests/wlcs/e_wlcs.c
@@ -716,6 +716,7 @@ static const WlcsExtensionDescriptor _extensions[] =
{ "wl_output", 2 },
{ "wl_data_device_manager", 3 },
{ "wp_viewporter", 1 },
+ { "wp_fractional_scale_manager_v1", 1 },
{ "xdg_wm_base", 6 },
{ "zxdg_shell_v6", 1 },
{ "wl_shell", 1 },
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.