This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch up/6-hidpi
in repository enlightenment.
View the commit online.
commit 254185f4b5b12fdedbc20d563c8d6a24e0bb3473
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 27 21:50:43 2026 -0600
e_comp_wl - convert between surface-local and canvas coordinates
A Wayland client speaks in surface-local units, and wl_output.scale
says how many real pixels each one covers. E's canvas, its zones and
ec->x/y/w/h are real pixels. E treats the two as the same, which is
only true at scale 1.
e_comp_wl_client_scale_get() is the factor between them. It returns 1
here, so every conversion is an identity and nothing changes; turning
it on is a commit of its own, so it can be reverted alone. It is E_API
because wl_desktop_shell needs it too.
Positions going to a client are divided in fixed point: at scale 2 a
canvas pixel is half a surface unit, and whole units would move the
pointer in steps of two pixels. That covers pointer enter and motion,
touch, drag-and-drop enter and motion, and relative pointer motion.
Sizes and positions coming from a client are multiplied: the surface
size, the input region, subsurface offsets (in the parent's units), the
cursor hotspot, a drag icon's attach offset, min and max sizes, the
xdg_toplevel_drag offset, and pointer constraint regions and hints.
A wl_region can be set on several surfaces, so it is scaled where it
is applied to one, never where its rectangles are added.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/bin/e_comp_wl.c | 102 ++++++++++++++++++++++++++++++-----------
src/bin/e_comp_wl.h | 3 ++
src/bin/e_comp_wl_data.c | 17 +++----
src/bin/e_comp_wl_extensions.c | 12 ++++-
src/bin/e_comp_wl_input.c | 5 +-
5 files changed, 101 insertions(+), 38 deletions(-)
diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c
index 04eccd2f5..9a3ff0ece 100644
--- a/src/bin/e_comp_wl.c
+++ b/src/bin/e_comp_wl.c
@@ -197,6 +197,47 @@ e_comp_wl_pointer_frame_send(struct wl_resource *res)
wl_pointer_send_frame(res);
}
+/* How many canvas pixels one surface-local unit of this client covers. */
+E_API int
+e_comp_wl_client_scale_get(const E_Client *ec EINA_UNUSED)
+{
+ return 1;
+}
+
+/* Wayland hands clients surface-local coordinates, which are output scale
+ * times smaller than the canvas pixels of ec->x/y/w/h. A position is kept
+ * in fixed point: at scale 2 a canvas pixel is half a surface unit. */
+EINTERN void
+e_comp_wl_surface_coord_from_canvas(const E_Client *ec, int x, int y, wl_fixed_t *sx, wl_fixed_t *sy)
+{
+ int scale = e_comp_wl_client_scale_get(ec);
+
+ *sx = wl_fixed_from_double((double)(x - ec->client.x) / scale);
+ *sy = wl_fixed_from_double((double)(y - ec->client.y) / scale);
+}
+
+/* A wl_region can be set on several surfaces, so it is scaled where it is
+ * applied to one. Replaces *t with a scaled copy. */
+EINTERN void
+e_comp_wl_region_scale(Eina_Tiler **t, int scale)
+{
+ Eina_Tiler *scaled;
+ Eina_Iterator *it;
+ Eina_Rectangle *r;
+
+ if (scale == 1) return;
+
+ scaled = eina_tiler_new(65535, 65535);
+ eina_tiler_tile_size_set(scaled, 1, 1);
+ it = eina_tiler_iterator_new(*t);
+ EINA_ITERATOR_FOREACH(it, r)
+ eina_tiler_rect_add(scaled, &(Eina_Rectangle){r->x * scale, r->y * scale,
+ r->w * scale, r->h * scale});
+ eina_iterator_free(it);
+ eina_tiler_free(*t);
+ *t = scaled;
+}
+
/* The move grabber is a smart member of the frame of the client being
* moved, so while it is up evas has the pointer in that frame wherever it
* is, and showing it crosses the pointer out of the client and back in
@@ -215,6 +256,7 @@ _e_comp_wl_mouse_in(E_Client *ec, Evas_Event_Mouse_In *ev)
struct wl_client *wc;
Eina_List *l;
uint32_t serial;
+ wl_fixed_t sx, sy;
if (e_object_is_del(E_OBJECT(ec))) return;
if (_e_comp_wl_crossing_ignored(ec)) return;
@@ -230,6 +272,7 @@ _e_comp_wl_mouse_in(E_Client *ec, Evas_Event_Mouse_In *ev)
if (!eina_list_count(e_comp_wl->ptr.resources)) return;
wc = wl_resource_get_client(ec->comp_data->surface);
serial = wl_display_next_serial(e_comp_wl->wl.disp);
+ e_comp_wl_surface_coord_from_canvas(ec, ev->canvas.x, ev->canvas.y, &sx, &sy);
EINA_LIST_FOREACH(e_comp_wl->ptr.resources, l, res)
{
E_Comp_Wl_Pointer *ptr = wl_resource_get_user_data(res);
@@ -238,9 +281,7 @@ _e_comp_wl_mouse_in(E_Client *ec, Evas_Event_Mouse_In *ev)
if (wl_resource_get_client(res) != wc) continue;
if (ptr->entered) continue;
ptr->entered = 1;
- wl_pointer_send_enter(res, serial, ec->comp_data->surface,
- wl_fixed_from_int(ev->canvas.x - ec->client.x),
- wl_fixed_from_int(ev->canvas.y - ec->client.y));
+ wl_pointer_send_enter(res, serial, ec->comp_data->surface, sx, sy);
e_comp_wl_pointer_frame_send(res);
e_comp_wl_input_pointer_cursor_update(ptr);
}
@@ -381,6 +422,7 @@ _e_comp_wl_send_mouse_move(E_Client *ec, int x, int y, unsigned int timestamp)
E_Client *tec, *tec_in = NULL;
Eina_Bool found = EINA_FALSE;
Evas_Event_Mouse_In ev;
+ wl_fixed_t sx, sy;
/* begin hacks:
*
@@ -433,13 +475,12 @@ _e_comp_wl_send_mouse_move(E_Client *ec, int x, int y, unsigned int timestamp)
if (e_comp_wl->ptr.ec != ec) _e_comp_wl_pointer_enter_at(ec, x, y);
wc = wl_resource_get_client(ec->comp_data->surface);
+ e_comp_wl_surface_coord_from_canvas(ec, x, y, &sx, &sy);
EINA_LIST_FOREACH(e_comp_wl->ptr.resources, l, res)
{
if (!e_comp_wl_input_pointer_check(res)) continue;
if (wl_resource_get_client(res) != wc) continue;
- wl_pointer_send_motion(res, timestamp,
- wl_fixed_from_int(x - ec->client.x),
- wl_fixed_from_int(y - ec->client.y));
+ wl_pointer_send_motion(res, timestamp, sx, sy);
e_comp_wl_pointer_frame_send(res);
}
}
@@ -658,8 +699,7 @@ _e_comp_wl_evas_cb_multi_down(void *data, Evas *evas EINA_UNUSED, Evas_Object *o
wc = wl_resource_get_client(ec->comp_data->surface);
serial = wl_display_next_serial(e_comp_wl->wl.disp);
- x = wl_fixed_from_int(ev->canvas.x - ec->client.x);
- y = wl_fixed_from_int(ev->canvas.y - ec->client.y);
+ e_comp_wl_surface_coord_from_canvas(ec, ev->canvas.x, ev->canvas.y, &x, &y);
EINA_LIST_FOREACH(e_comp_wl->touch.resources, l, res)
{
@@ -715,8 +755,7 @@ _e_comp_wl_evas_cb_multi_move(void *data, Evas *evas EINA_UNUSED, Evas_Object *o
wc = wl_resource_get_client(ec->comp_data->surface);
- x = wl_fixed_from_int(ev->cur.canvas.x - ec->client.x);
- y = wl_fixed_from_int(ev->cur.canvas.y - ec->client.y);
+ e_comp_wl_surface_coord_from_canvas(ec, ev->cur.canvas.x, ev->cur.canvas.y, &x, &y);
EINA_LIST_FOREACH(e_comp_wl->touch.resources, l, res)
{
@@ -952,18 +991,18 @@ _e_comp_wl_evas_cb_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_U
EINA_LIST_FOREACH(_touch_points, ll, tp)
{
Eina_List *rl;
+ wl_fixed_t sx, sy;
if (tp->ec != ec) continue;
+ e_comp_wl_surface_coord_from_canvas(ec, tp->x, tp->y, &sx, &sy);
EINA_LIST_FOREACH(e_comp_wl->touch.resources, rl, res)
{
if (wl_resource_get_client(res) != wc) continue;
if (!e_comp_wl_input_touch_check(res)) continue;
wl_touch_send_motion(res,
(unsigned int)lround(ecore_loop_time_get() * 1000),
- tp->device,
- wl_fixed_from_int(tp->x - ec->client.x),
- wl_fixed_from_int(tp->y - ec->client.y));
+ tp->device, sx, sy);
wl_touch_send_frame(res);
}
}
@@ -1433,12 +1472,12 @@ _e_comp_wl_cb_mouse_move(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_Event_Mou
e_comp_wl->drag)
{
struct wl_resource *res;
- int x, y;
+ wl_fixed_t sx, sy;
res = e_comp_wl_data_find_for_client(wl_resource_get_client(e_comp_wl->selection.target->comp_data->surface));
- x = ev->x - e_comp_wl->selection.target->client.x;
- y = ev->y - e_comp_wl->selection.target->client.y;
- wl_data_device_send_motion(res, ev->timestamp, wl_fixed_from_int(x), wl_fixed_from_int(y));
+ e_comp_wl_surface_coord_from_canvas(e_comp_wl->selection.target,
+ ev->x, ev->y, &sx, &sy);
+ wl_data_device_send_motion(res, ev->timestamp, sx, sy);
}
if (e_comp_wl->drag &&
e_comp_wl->drag_client &&
@@ -1471,6 +1510,8 @@ _e_comp_wl_surface_state_size_update(E_Client *ec, E_Comp_Wl_Surface_State *stat
/* } */
if (!e_pixmap_size_get(ec->pixmap, &state->bw, &state->bh)) return;
+ state->bw *= e_comp_wl_client_scale_get(ec);
+ state->bh *= e_comp_wl_client_scale_get(ec);
if (e_client_has_xwindow(ec) || e_comp_object_frame_exists(ec->frame)) return;
window = &ec->comp_data->shell.window;
if (window->x || window->y || window->w || window->h)
@@ -1650,17 +1691,19 @@ _e_comp_wl_surface_state_commit(E_Client *ec, E_Comp_Wl_Surface_State *state)
if (ec->comp_data->shell.surface)
{
+ int scale = e_comp_wl_client_scale_get(ec);
+
if (ec->comp_data->shell.set.min_size.w)
- ec->icccm.min_w = ec->comp_data->shell.set.min_size.w;
+ ec->icccm.min_w = ec->comp_data->shell.set.min_size.w * scale;
ec->comp_data->shell.set.min_size.w = 0;
if (ec->comp_data->shell.set.min_size.h)
- ec->icccm.min_h = ec->comp_data->shell.set.min_size.h;
+ ec->icccm.min_h = ec->comp_data->shell.set.min_size.h * scale;
ec->comp_data->shell.set.min_size.h = 0;
if (ec->comp_data->shell.set.max_size.w)
- ec->icccm.max_w = ec->comp_data->shell.set.max_size.w;
+ ec->icccm.max_w = ec->comp_data->shell.set.max_size.w * scale;
ec->comp_data->shell.set.max_size.w = 0;
if (ec->comp_data->shell.set.max_size.h)
- ec->icccm.max_h = ec->comp_data->shell.set.max_size.h;
+ ec->icccm.max_h = ec->comp_data->shell.set.max_size.h * scale;
ec->comp_data->shell.set.max_size.h = 0;
if (ec->icccm.min_w && ec->icccm.max_w && (ec->icccm.min_w > ec->icccm.max_w))
wl_resource_post_error(ec->comp_data->shell.surface,
@@ -1829,10 +1872,13 @@ _e_comp_wl_surface_state_commit(E_Client *ec, E_Comp_Wl_Surface_State *state)
if (e_comp_wl->drag && e_comp_wl->drag_client &&
(e_comp_wl->drag_client == ec))
{
- e_comp_wl->drag->dx -= state->sx;
- e_comp_wl->drag->dy -= state->sy;
+ int dx = state->sx * e_comp_wl_client_scale_get(ec);
+ int dy = state->sy * e_comp_wl_client_scale_get(ec);
+
+ e_comp_wl->drag->dx -= dx;
+ e_comp_wl->drag->dy -= dy;
e_drag_move(e_comp_wl->drag,
- e_comp_wl->drag->x + state->sx, e_comp_wl->drag->y + state->sy);
+ e_comp_wl->drag->x + dx, e_comp_wl->drag->y + dy);
e_drag_resize(e_comp_wl->drag, state->bw, state->bh);
}
else
@@ -1925,6 +1971,7 @@ _e_comp_wl_surface_state_commit(E_Client *ec, E_Comp_Wl_Surface_State *state)
}
else if (state->input)
{
+ e_comp_wl_region_scale(&state->input, e_comp_wl_client_scale_get(ec));
e_comp_object_input_area_set(ec->frame, state->input);
eina_tiler_free(state->input);
@@ -2646,6 +2693,7 @@ _e_comp_wl_subsurface_cb_position_set(struct wl_client *client EINA_UNUSED, stru
{
E_Client *ec;
E_Comp_Wl_Subsurf_Data *sdata;
+ int scale;
DBG("Subsurface Cb Position Set: %d", wl_resource_get_id(resource));
@@ -2654,8 +2702,10 @@ _e_comp_wl_subsurface_cb_position_set(struct wl_client *client EINA_UNUSED, stru
if (!(sdata = ec->comp_data->sub.data)) return;
- sdata->pending_position.x = x;
- sdata->pending_position.y = y;
+ /* The offset is in the parent's surface-local units. */
+ scale = e_comp_wl_client_scale_get(sdata->parent);
+ sdata->pending_position.x = x * scale;
+ sdata->pending_position.y = y * scale;
sdata->pending_position.set = EINA_TRUE;
}
diff --git a/src/bin/e_comp_wl.h b/src/bin/e_comp_wl.h
index cb96fef75..25de3decf 100644
--- a/src/bin/e_comp_wl.h
+++ b/src/bin/e_comp_wl.h
@@ -466,6 +466,8 @@ EINTERN struct wl_resource *e_comp_wl_surface_create(struct wl_client *client, i
EINTERN void e_comp_wl_surface_destroy(struct wl_resource *resource);
EINTERN Eina_Bool e_comp_wl_surface_commit(E_Client *ec);
EINTERN Eina_Bool e_comp_wl_subsurface_commit(E_Client *ec);
+EINTERN void e_comp_wl_region_scale(Eina_Tiler **t, int scale);
+EINTERN void e_comp_wl_surface_coord_from_canvas(const E_Client *ec, int x, int y, wl_fixed_t *sx, wl_fixed_t *sy);
E_API E_Comp_Wl_Buffer *e_comp_wl_buffer_get(struct wl_resource *resource);
EINTERN void e_comp_wl_shm_guard_add(struct wl_shm_pool *pool, E_Comp_Wl_Buffer *buffer);
EINTERN void e_comp_wl_shm_guard_del(struct wl_shm_pool *pool);
@@ -475,6 +477,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 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);
EINTERN Eina_Bool e_comp_wl_key_up(Ecore_Event_Key *ev, E_Client *ec);
diff --git a/src/bin/e_comp_wl_data.c b/src/bin/e_comp_wl_data.c
index a5749024c..0d58a5b7d 100644
--- a/src/bin/e_comp_wl_data.c
+++ b/src/bin/e_comp_wl_data.c
@@ -380,7 +380,7 @@ static void
_e_comp_wl_data_source_toplevel_carry(E_Comp_Wl_Data_Source *source)
{
E_Client *ec = source->toplevel;
- int x, y;
+ int x, y, scale;
if (!ec) return;
if ((e_object_is_del(E_OBJECT(ec))) || (!ec->comp_data->mapped))
@@ -392,8 +392,9 @@ _e_comp_wl_data_source_toplevel_carry(E_Comp_Wl_Data_Source *source)
evas_pointer_canvas_xy_get(e_comp->evas, &x, &y);
/* The offset is relative to the window geometry, which is inside the
* surface that e_client_util_move_without_frame() places. */
- e_client_util_move_without_frame(ec, x - source->toplevel_x - ec->comp_data->shell.window.x,
- y - source->toplevel_y - ec->comp_data->shell.window.y);
+ scale = e_comp_wl_client_scale_get(ec);
+ e_client_util_move_without_frame(ec, x - (source->toplevel_x * scale) - ec->comp_data->shell.window.x,
+ y - (source->toplevel_y * scale) - ec->comp_data->shell.window.y);
}
static void
@@ -1041,7 +1042,7 @@ e_comp_wl_data_device_send_enter(E_Client *ec)
{
struct wl_resource *data_device_res = NULL, *offer_res = NULL;
uint32_t serial;
- int x, y;
+ wl_fixed_t x, y;
if (e_client_has_xwindow(ec) &&
e_client_has_xwindow(e_comp_wl->drag_client))
@@ -1109,12 +1110,12 @@ e_comp_wl_data_device_send_enter(E_Client *ec)
return;
}
#endif
- x = e_comp_wl->ptr.x - e_comp_wl->selection.target->client.x;
- y = e_comp_wl->ptr.y - e_comp_wl->selection.target->client.y;
+ e_comp_wl_surface_coord_from_canvas(e_comp_wl->selection.target,
+ e_comp_wl->ptr.x, e_comp_wl->ptr.y,
+ &x, &y);
serial = wl_display_next_serial(e_comp_wl->wl.disp);
wl_data_device_send_enter(data_device_res, serial, ec->comp_data->surface,
- wl_fixed_from_int(x), wl_fixed_from_int(y),
- offer_res);
+ x, y, offer_res);
}
E_API void
diff --git a/src/bin/e_comp_wl_extensions.c b/src/bin/e_comp_wl_extensions.c
index 625a096c4..2cc10e29e 100644
--- a/src/bin/e_comp_wl_extensions.c
+++ b/src/bin/e_comp_wl_extensions.c
@@ -1852,6 +1852,7 @@ e_comp_wl_extension_relative_motion_event(uint64_t time_usec, double dx, double
E_Client *focused;
struct wl_client *wc;
uint32_t hi, lo;
+ int scale;
focused = e_client_focused_get();
if ((!focused) || e_object_is_del(E_OBJECT(focused)) || (!focused->mouse.in)) return;
@@ -1862,11 +1863,14 @@ e_comp_wl_extension_relative_motion_event(uint64_t time_usec, double dx, double
hi = time_usec >> 32;
lo = (uint32_t)time_usec;
+ /* dx and dy are in the units of wl_pointer.motion; the unaccelerated
+ * motion is in device units. */
+ scale = e_comp_wl_client_scale_get(focused);
EINA_LIST_FOREACH(e_comp_wl->extensions->zwp_relative_pointer_manager_v1.resources, l, res)
{
if (wl_resource_get_client(res) != wc) continue;
- zwp_relative_pointer_v1_send_relative_motion(res, hi, lo, wl_fixed_from_double(dx),
- wl_fixed_from_double(dy), wl_fixed_from_double(dx_unaccel), wl_fixed_from_double(dy_unaccel));
+ zwp_relative_pointer_v1_send_relative_motion(res, hi, lo, wl_fixed_from_double(dx / scale),
+ wl_fixed_from_double(dy / scale), wl_fixed_from_double(dx_unaccel), wl_fixed_from_double(dy_unaccel));
}
}
@@ -1885,6 +1889,8 @@ e_comp_wl_extension_pointer_constraints_commit(E_Client *ec)
c->region = c->pending;
c->pending = NULL;
c->pending_region = 0;
+ if (c->region)
+ e_comp_wl_region_scale(&c->region, e_comp_wl_client_scale_get(ec));
}
if (c->pending_xy)
{
@@ -1892,6 +1898,8 @@ e_comp_wl_extension_pointer_constraints_commit(E_Client *ec)
free(c->pointer_xy);
c->pointer_xy = c->pending_xy;
c->pending_xy = NULL;
+ c->pointer_xy->x *= e_comp_wl_client_scale_get(ec);
+ c->pointer_xy->y *= e_comp_wl_client_scale_get(ec);
}
}
/* a newly committed region can be what makes a constraint eligible */
diff --git a/src/bin/e_comp_wl_input.c b/src/bin/e_comp_wl_input.c
index 4f1f5d413..822b38d6d 100644
--- a/src/bin/e_comp_wl_input.c
+++ b/src/bin/e_comp_wl_input.c
@@ -87,8 +87,9 @@ _e_comp_wl_input_pointer_cb_cursor_set(struct wl_client *client EINA_UNUSED, str
if (!ec) return;
ptr->cursor_set = 1;
ptr->cursor = ec;
- ptr->offset.x = x;
- ptr->offset.y = y;
+ /* The hotspot is in the cursor surface's own surface-local units. */
+ ptr->offset.x = x * e_comp_wl_client_scale_get(ec);
+ ptr->offset.y = y * e_comp_wl_client_scale_get(ec);
if (ec->comp_data->pending.input)
eina_tiler_clear(ec->comp_data->pending.input);
else
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.