diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 14:44:58 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 14:44:58 +0300 |
| commit | a553abf3c46133f76b9a9e3c8166099efbcb9bcf (patch) | |
| tree | 836be926a7bfff99030ceff6b721492b49321c93 | |
| parent | 93ea4e79528ba9f42d57f9004260dcba309492ba (diff) | |
wayland: make conn_surface_for static inline zero-lookup accessor
| -rw-r--r-- | src/wayland/internal.h | 6 | ||||
| -rw-r--r-- | src/wayland/surface.c | 11 | ||||
| -rw-r--r-- | tests/wayland/test_cursor.c | 1 |
3 files changed, 6 insertions, 12 deletions
diff --git a/src/wayland/internal.h b/src/wayland/internal.h index d519abd..ad6531b 100644 --- a/src/wayland/internal.h +++ b/src/wayland/internal.h @@ -370,7 +370,11 @@ void surface_fail(struct wayland_surface *w); void display_enter(struct wayland_display *c); void display_leave(struct wayland_display *c); -struct wayland_surface *conn_surface_for(struct wayland_display *c, struct wl_surface *s); +static inline struct wayland_surface *conn_surface_for(struct wayland_display *c, struct wl_surface *s) +{ + (void)c; + return s ? (struct wayland_surface *)wl_surface_get_user_data(s) : NULL; +} static inline struct wayland_surface *surface_root(struct wayland_surface *w) { diff --git a/src/wayland/surface.c b/src/wayland/surface.c index 242531c..8a2bb5b 100644 --- a/src/wayland/surface.c +++ b/src/wayland/surface.c @@ -319,17 +319,6 @@ static void conn_unlink(struct wayland_surface *w) w->conn = NULL; } -struct wayland_surface *conn_surface_for(struct wayland_display *c, struct wl_surface *s) -{ - if (unlikely(!c || !s)) return NULL; - struct wayland_surface *fast = (struct wayland_surface *)wl_surface_get_user_data(s); - if (likely(fast && fast->conn == c && fast->surface == s)) - return fast; - for (struct wayland_surface *w = c->surfaces; w; w = w->conn_next) - if (w->surface == s) - return w; - return NULL; -} static bool spec_valid(const struct yasl_surface_spec *spec) { diff --git a/tests/wayland/test_cursor.c b/tests/wayland/test_cursor.c index e43bff4..f7a7ba7 100644 --- a/tests/wayland/test_cursor.c +++ b/tests/wayland/test_cursor.c @@ -55,6 +55,7 @@ int main(void) struct wayland_surface surface = {.base.display = &display.base, .conn = &display, .scale_factor = 1, .cursor = YASL_CURSOR_TEXT}; surface.surface = (struct wl_surface *)&surface; + wl_surface_set_user_data(surface.surface, &surface); display.surfaces = &surface; struct seat seat = {.conn = &display}; seat.pointer = (struct wl_pointer *)&seat; |
