From 98f0d51157fa2a2b8ccaae54ed4850a88d223d01 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 15:05:06 +0300 Subject: Simplify surface state, examples, and library installation --- src/platform/wayland/api.h | 4 +-- src/platform/wayland/backend.c | 6 ----- src/platform/wayland/buffer.c | 17 ++++-------- src/platform/wayland/clipboard.c | 2 ++ src/platform/wayland/internal.h | 9 +------ src/platform/wayland/keyboard.c | 1 + src/platform/wayland/keymap.h | 2 +- src/platform/wayland/popup.c | 1 + src/platform/wayland/shell.c | 56 +++++++++++++++++++--------------------- src/platform/wayland/surface.c | 2 ++ 10 files changed, 41 insertions(+), 59 deletions(-) (limited to 'src/platform/wayland') diff --git a/src/platform/wayland/api.h b/src/platform/wayland/api.h index 04a6bf1..bbd20df 100644 --- a/src/platform/wayland/api.h +++ b/src/platform/wayland/api.h @@ -1,8 +1,7 @@ #ifndef YASL_WAYLAND_API_H #define YASL_WAYLAND_API_H -#include "common/backend.h" -#include "yasl/native/wayland.h" +#include "yasl/yasl.h" struct wayland_display; struct wayland_surface; @@ -28,7 +27,6 @@ void wayland_surface_schedule_redraw(struct wayland_surface *s); bool wayland_surface_present(struct wayland_surface *s, const struct yasl_framebuffer *fb, const struct yasl_damage_list *damage); bool wayland_surface_input_poll(struct wayland_surface *s, struct yasl_input_event *ev); struct yasl_geometry wayland_surface_geometry(const struct wayland_surface *s); -uint32_t wayland_surface_state(const struct wayland_surface *s); struct yasl_timing wayland_surface_timing(const struct wayland_surface *s); void wayland_surface_set_cursor(struct wayland_surface *s, enum yasl_cursor cursor); void wayland_surface_set_background_color(struct wayland_surface *s, uint32_t bg); diff --git a/src/platform/wayland/backend.c b/src/platform/wayland/backend.c index 3eada38..cc96934 100644 --- a/src/platform/wayland/backend.c +++ b/src/platform/wayland/backend.c @@ -111,11 +111,6 @@ static struct yasl_geometry impl_surface_geometry(const struct yasl_surface *s) return wayland_surface_geometry((const struct wayland_surface *)s); } -static uint32_t impl_surface_state(const struct yasl_surface *s) -{ - return wayland_surface_state((const struct wayland_surface *)s); -} - static struct yasl_timing impl_surface_timing(const struct yasl_surface *s) { return wayland_surface_timing((const struct wayland_surface *)s); @@ -212,7 +207,6 @@ const struct yasl_backend_ops yasl_wayland_backend = { .surface_present = impl_surface_present, .surface_input_poll = impl_surface_input_poll, .surface_geometry = impl_surface_geometry, - .surface_state = impl_surface_state, .surface_timing = impl_surface_timing, .surface_frame_time_ns = impl_surface_frame_time_ns, .surface_set_cursor = impl_surface_set_cursor, diff --git a/src/platform/wayland/buffer.c b/src/platform/wayland/buffer.c index f4243d1..f5a2c0f 100644 --- a/src/platform/wayland/buffer.c +++ b/src/platform/wayland/buffer.c @@ -1,4 +1,6 @@ #include "internal.h" +#include "common/utf8.h" +#include #include static long minor_faults(void) @@ -134,7 +136,8 @@ int apply_pending_geometry(struct wayland_surface *w) w->size_pending = false; return 0; } - bool floating = !w->parent && !w->maximized && !w->fullscreen && !w->tiled; + bool floating = !w->parent && !(w->base.state & + (YASL_STATE_MAXIMIZED | YASL_STATE_FULLSCREEN | YASL_STATE_TILED)); int free_w = floating && w->floating_width > 0 ? w->floating_width : w->logical_width; int free_h = floating && w->floating_height > 0 ? w->floating_height : w->logical_height; int logical_w = !w->parent && w->req_width > 0 ? w->req_width : free_w; @@ -143,7 +146,7 @@ int apply_pending_geometry(struct wayland_surface *w) if (logical_w < YASL_MIN_LOGICAL_PX) logical_w = YASL_MIN_LOGICAL_PX; if (logical_h < YASL_MIN_LOGICAL_PX) logical_h = YASL_MIN_LOGICAL_PX; } - if (!w->fullscreen) { + if (!(w->base.state & YASL_STATE_FULLSCREEN)) { if (w->bound_width > 0 && logical_w > w->bound_width) logical_w = w->bound_width; if (w->bound_height > 0 && logical_h > w->bound_height) @@ -539,16 +542,6 @@ void wayland_surface_set_title(struct wayland_surface *w, const char *title) free(copy); } -uint32_t wayland_surface_state(const struct wayland_surface *w) -{ - if (unlikely(!w)) return 0; - return ((uint32_t)w->fullscreen * YASL_STATE_FULLSCREEN) | - ((uint32_t)w->maximized * YASL_STATE_MAXIMIZED) | - ((uint32_t)w->activated * YASL_STATE_ACTIVATED) | - ((uint32_t)w->suspended * YASL_STATE_SUSPENDED) | - ((uint32_t)!w->server_decorated * YASL_STATE_CSD); -} - struct yasl_timing wayland_surface_timing(const struct wayland_surface *w) { struct yasl_timing t = { diff --git a/src/platform/wayland/clipboard.c b/src/platform/wayland/clipboard.c index 24dee97..353e993 100644 --- a/src/platform/wayland/clipboard.c +++ b/src/platform/wayland/clipboard.c @@ -1,6 +1,8 @@ #define _GNU_SOURCE #include "internal.h" #include "clipboard.h" +#include "common/utf8.h" +#include #define CLIPBOARD_TEXT_MAX (256u * 1024) diff --git a/src/platform/wayland/internal.h b/src/platform/wayland/internal.h index f777674..d619dba 100644 --- a/src/platform/wayland/internal.h +++ b/src/platform/wayland/internal.h @@ -4,8 +4,8 @@ #define _GNU_SOURCE #include "api.h" +#include "common/backend.h" #include "common/timing.h" -#include "common/utf8.h" #include "clipboard.h" #include @@ -24,7 +24,6 @@ #include "protocols/xdg-toplevel-drag-v1-client-protocol.h" #include "protocols/primary-selection-unstable-v1-client-protocol.h" -#include #include #include #include @@ -307,10 +306,8 @@ struct wayland_surface { uint32_t pending_serial; /* 1-byte booleans packed tightly */ - bool server_decorated; bool frame_active; bool frame_presented; - bool tiled; bool size_pending; bool sample_refresh; bool has_pending_serial; @@ -318,10 +315,6 @@ struct wayland_surface { bool closed; bool destroyed; bool opaque; - bool fullscreen; - bool maximized; - bool activated; - bool suspended; bool want_draw; }; diff --git a/src/platform/wayland/keyboard.c b/src/platform/wayland/keyboard.c index 0913079..ebd0fc7 100644 --- a/src/platform/wayland/keyboard.c +++ b/src/platform/wayland/keyboard.c @@ -1,6 +1,7 @@ #include "internal.h" #include "common/keyboard.h" #include "keymap.h" +#include #define XKB_EVDEV_OFFSET 8 #define KEYMAP_MAX_BYTES (8u * 1024 * 1024) diff --git a/src/platform/wayland/keymap.h b/src/platform/wayland/keymap.h index 26a5cd6..c0ff81e 100644 --- a/src/platform/wayland/keymap.h +++ b/src/platform/wayland/keymap.h @@ -1,7 +1,7 @@ #ifndef YASL_WAYLAND_KEYMAP_H #define YASL_WAYLAND_KEYMAP_H -#include "yasl/yasl.h" +#include "yasl/keycodes.h" enum yasl_key yasl_key_from_evdev(uint32_t code); diff --git a/src/platform/wayland/popup.c b/src/platform/wayland/popup.c index fd415c9..cb578d5 100644 --- a/src/platform/wayland/popup.c +++ b/src/platform/wayland/popup.c @@ -137,6 +137,7 @@ struct wayland_surface *wayland_surface_create_popup(struct wayland_surface *par if (!w) return NULL; w->base.display = &c->base; + w->base.state = YASL_STATE_CSD; w->conn = c; w->conn_next = c->surfaces; c->surfaces = w; diff --git a/src/platform/wayland/shell.c b/src/platform/wayland/shell.c index 4c1caad..92c89d1 100644 --- a/src/platform/wayland/shell.c +++ b/src/platform/wayland/shell.c @@ -265,10 +265,12 @@ static const struct xdg_wm_base_listener wm_base_listener = { .ping = wm_base_ping, }; -static void notify_state(struct wayland_surface *w) +static void set_state(struct wayland_surface *w, uint32_t state) { + if (state == w->base.state) return; + w->base.state = state; if (w->cbs && w->cbs->state) - w->cbs->state(&w->base, wayland_surface_state(w), w->ud); + w->cbs->state(&w->base, state, w->ud); } static void toplevel_configure(void *data, struct xdg_toplevel *toplevel, @@ -277,35 +279,29 @@ static void toplevel_configure(void *data, struct xdg_toplevel *toplevel, (void)toplevel; struct wayland_surface *w = data; - uint32_t state_mask = 0; + uint32_t state = w->base.state & ~(YASL_STATE_FULLSCREEN | + YASL_STATE_MAXIMIZED | YASL_STATE_ACTIVATED | + YASL_STATE_SUSPENDED | YASL_STATE_TILED); uint32_t *s; wl_array_for_each(s, states) { - if (*s < 32) - state_mask |= (1u << *s); + switch (*s) { + case XDG_TOPLEVEL_STATE_FULLSCREEN: state |= YASL_STATE_FULLSCREEN; break; + case XDG_TOPLEVEL_STATE_MAXIMIZED: state |= YASL_STATE_MAXIMIZED; break; + case XDG_TOPLEVEL_STATE_ACTIVATED: state |= YASL_STATE_ACTIVATED; break; + case XDG_TOPLEVEL_STATE_SUSPENDED: state |= YASL_STATE_SUSPENDED; break; + case XDG_TOPLEVEL_STATE_TILED_LEFT: + case XDG_TOPLEVEL_STATE_TILED_RIGHT: + case XDG_TOPLEVEL_STATE_TILED_TOP: + case XDG_TOPLEVEL_STATE_TILED_BOTTOM: + state |= YASL_STATE_TILED; + break; + default: break; + } } - bool max = (state_mask & (1u << XDG_TOPLEVEL_STATE_MAXIMIZED)) != 0; - bool fs = (state_mask & (1u << XDG_TOPLEVEL_STATE_FULLSCREEN)) != 0; - bool act = (state_mask & (1u << XDG_TOPLEVEL_STATE_ACTIVATED)) != 0; - bool susp = (state_mask & (1u << XDG_TOPLEVEL_STATE_SUSPENDED)) != 0; - bool tiled = (state_mask & ( - (1u << XDG_TOPLEVEL_STATE_TILED_LEFT) | - (1u << XDG_TOPLEVEL_STATE_TILED_RIGHT) | - (1u << XDG_TOPLEVEL_STATE_TILED_TOP) | - (1u << XDG_TOPLEVEL_STATE_TILED_BOTTOM))) != 0; - - if ((fs ^ w->fullscreen) | (max ^ w->maximized) | - (act ^ w->activated) | (susp ^ w->suspended)) { - w->fullscreen = fs; - w->maximized = max; - w->activated = act; - w->suspended = susp; - notify_state(w); - } - - w->tiled = tiled; w->req_width = width; w->req_height = height; + set_state(w, state); } static void toplevel_close(void *data, struct xdg_toplevel *toplevel) @@ -363,10 +359,12 @@ static void toplevel_decoration_configure(void *data, { (void)toplevel_decor; struct wayland_surface *w = data; - bool was_server = w->server_decorated; - w->server_decorated = (mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); - if (was_server != w->server_decorated) - notify_state(w); + uint32_t state = w->base.state; + if (mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE) + state &= ~YASL_STATE_CSD; + else + state |= YASL_STATE_CSD; + set_state(w, state); } static const struct zxdg_toplevel_decoration_v1_listener toplevel_decoration_listener = { diff --git a/src/platform/wayland/surface.c b/src/platform/wayland/surface.c index 7daa679..ad3a24c 100644 --- a/src/platform/wayland/surface.c +++ b/src/platform/wayland/surface.c @@ -1,5 +1,6 @@ #include "internal.h" #include +#include static void display_free(struct wayland_display *c); @@ -335,6 +336,7 @@ struct wayland_surface *wayland_surface_create_toplevel(struct wayland_display * if (!w) return NULL; c->depth++; conn_link(c, w); + w->base.state = YASL_STATE_CSD; wayland_surface_set_callbacks(w, NULL, NULL); w->cursor = YASL_CURSOR_TEXT; w->req_width = width; -- cgit v1.2.3