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/common/app.c | 36 +++++++++++++++++++------- src/common/app_internal.h | 3 +-- src/common/backend.c | 4 +-- src/common/backend.h | 3 +-- src/common/keyboard.h | 2 +- src/platform/cocoa/api.h | 2 +- src/platform/cocoa/keymap.h | 2 +- src/platform/cocoa/window.m | 21 +++++---------- src/platform/sync.h | 2 +- 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 ++ src/platform/x11/keymap.h | 2 +- src/platform/x11/window.c | 17 +++++------- 21 files changed, 90 insertions(+), 104 deletions(-) (limited to 'src') diff --git a/src/common/app.c b/src/common/app.c index da9747d..e1148f9 100644 --- a/src/common/app.c +++ b/src/common/app.c @@ -35,6 +35,7 @@ struct app_runner { struct yasl_display *display; const struct yasl_app_desc *desc; bool running; + bool failed; bool had_surfaces; int surface_count; struct app_surface *surfaces; @@ -380,6 +381,7 @@ static void app_runner_dispatch_input_events(struct app_runner *ar) if (ie.mouse.kind == YASL_PTR_PRESS || ie.mouse.kind == YASL_PTR_RELEASE) { ev.type = YASL_EVENT_MOUSE_BUTTON; ev.mouse_button.pos = ie.mouse.pos; + ev.mouse_button.device = ie.mouse.device; ev.mouse_button.button = ie.mouse.button; ev.mouse_button.pressed = (ie.mouse.kind == YASL_PTR_PRESS); ev.mouse_button.mods = ie.mouse.mods; @@ -391,6 +393,7 @@ static void app_runner_dispatch_input_events(struct app_runner *ar) } else if (ie.mouse.kind == YASL_PTR_MOTION) { ev.type = YASL_EVENT_MOUSE_MOTION; ev.mouse_motion.pos = ie.mouse.pos; + ev.mouse_motion.device = ie.mouse.device; if (as->has_last_mouse_pos) { ev.mouse_motion.delta.x = ie.mouse.pos.x - as->last_mouse_pos.x; ev.mouse_motion.delta.y = ie.mouse.pos.y - as->last_mouse_pos.y; @@ -439,6 +442,9 @@ static void app_runner_dispatch_input_events(struct app_runner *ar) break; case YASL_INPUT_RESET: as->has_last_mouse_pos = false; + ev.type = YASL_EVENT_INPUT_RESET; + if (ar->desc->event(ar->desc->userdata, &ev) == YASL_APP_QUIT) + ar->running = false; break; default: break; @@ -447,27 +453,38 @@ static void app_runner_dispatch_input_events(struct app_runner *ar) } } +static void app_runner_quit(void *ud) +{ + ((struct app_runner *)ud)->running = false; +} + +static void app_runner_lost(void *ud) +{ + struct app_runner *runner = ud; + runner->failed = true; + runner->running = false; +} + int yasl_run(const struct yasl_app_desc *desc) { if (!desc || !desc->init) return -1; + struct app_runner runner = {.desc = desc, .running = true}; + const struct yasl_display_cbs callbacks = { + .quit = app_runner_quit, .lost = app_runner_lost, + }; struct yasl_display_spec dspec = { .app_id = desc->app_id, .backend = desc->backend, + .cbs = &callbacks, + .ud = &runner, }; struct yasl_display *d = yasl_display_open(NULL, &dspec); if (!d) return -1; - struct app_runner runner = { - .display = d, - .desc = desc, - .running = true, - .had_surfaces = false, - .surface_count = 0, - .surfaces = NULL, - }; + runner.display = d; int sync_error = yasl_mutex_init(&runner.user_event_mutex); if (sync_error) { yasl_display_close(d); @@ -503,6 +520,7 @@ int yasl_run(const struct yasl_app_desc *desc) int res = yasl_display_dispatch(d, timeout_ms); if (res < 0) { + runner.failed = true; break; } @@ -546,5 +564,5 @@ int yasl_run(const struct yasl_app_desc *desc) yasl_mutex_destroy(&runner.user_event_mutex); yasl_display_close(d); - return 0; + return runner.failed ? -1 : 0; } diff --git a/src/common/app_internal.h b/src/common/app_internal.h index 64fa34c..143df41 100644 --- a/src/common/app_internal.h +++ b/src/common/app_internal.h @@ -1,8 +1,7 @@ #ifndef YASL_APP_INTERNAL_H #define YASL_APP_INTERNAL_H -#include "yasl/app.h" -#include "common/backend.h" +struct yasl_surface; void app_runner_register_surface(void *runner, struct yasl_surface *s); void app_runner_unregister_surface(void *runner, struct yasl_surface *s); diff --git a/src/common/backend.c b/src/common/backend.c index be06136..3f2143d 100644 --- a/src/common/backend.c +++ b/src/common/backend.c @@ -328,9 +328,7 @@ struct yasl_geometry yasl_surface_geometry(const struct yasl_surface *s) uint32_t yasl_surface_state(const struct yasl_surface *s) { - if (!s || !s->display->ops->surface_state) - return 0; - return s->display->ops->surface_state(s); + return s ? s->state : 0; } struct yasl_timing yasl_surface_timing(const struct yasl_surface *s) diff --git a/src/common/backend.h b/src/common/backend.h index 37fa167..17d781e 100644 --- a/src/common/backend.h +++ b/src/common/backend.h @@ -22,7 +22,7 @@ struct yasl_surface { void *native_handle; struct yasl_vector2i size; uint32_t scale_120; - uint32_t state; + uint32_t state; /* Authoritative YASL_STATE_* bitmask, maintained by the backend. */ uint32_t bg_color; struct yasl_window_cbs callbacks; void *ud; @@ -72,7 +72,6 @@ struct yasl_backend_ops { bool (*surface_present)(struct yasl_surface *s, const struct yasl_framebuffer *fb, const struct yasl_damage_list *damage); bool (*surface_input_poll)(struct yasl_surface *s, struct yasl_input_event *ev); struct yasl_geometry (*surface_geometry)(const struct yasl_surface *s); - uint32_t (*surface_state)(const struct yasl_surface *s); struct yasl_timing (*surface_timing)(const struct yasl_surface *s); uint64_t (*surface_frame_time_ns)(struct yasl_surface *s, uint64_t now); void (*surface_set_cursor)(struct yasl_surface *s, enum yasl_cursor cursor); diff --git a/src/common/keyboard.h b/src/common/keyboard.h index 77c6380..d8b8bbc 100644 --- a/src/common/keyboard.h +++ b/src/common/keyboard.h @@ -1,7 +1,7 @@ #ifndef YASL_COMMON_KEYBOARD_H #define YASL_COMMON_KEYBOARD_H -#include "yasl/yasl.h" +#include /* Layout labels omit controls, invalid Unicode, and Cocoa function-key PUA. */ static inline uint32_t yasl_key_label(uint32_t cp) diff --git a/src/platform/cocoa/api.h b/src/platform/cocoa/api.h index 89b71f3..0f705dd 100644 --- a/src/platform/cocoa/api.h +++ b/src/platform/cocoa/api.h @@ -1,7 +1,7 @@ #ifndef YASL_COCOA_API_H #define YASL_COCOA_API_H -#include "common/backend.h" +#include "yasl/yasl.h" struct cocoa_display; struct cocoa_surface; diff --git a/src/platform/cocoa/keymap.h b/src/platform/cocoa/keymap.h index 1aba70b..a5394e2 100644 --- a/src/platform/cocoa/keymap.h +++ b/src/platform/cocoa/keymap.h @@ -1,7 +1,7 @@ #ifndef YASL_COCOA_KEYMAP_H #define YASL_COCOA_KEYMAP_H -#include "yasl/yasl.h" +#include "yasl/keycodes.h" enum yasl_key yasl_key_from_cocoa(uint32_t code); diff --git a/src/platform/cocoa/window.m b/src/platform/cocoa/window.m index dc6175d..aa9fa48 100644 --- a/src/platform/cocoa/window.m +++ b/src/platform/cocoa/window.m @@ -3,6 +3,7 @@ #import #include "platform/cocoa/api.h" +#include "common/backend.h" #include "yasl/native/cocoa.h" #include "common/timing.h" #include "common/loop.h" @@ -93,7 +94,6 @@ struct cocoa_surface { struct input_queue input; struct yasl_vector2i pointer; double scroll_x; - uint32_t state; uint32_t mods; uint32_t buttons; enum yasl_cursor cursor; @@ -180,13 +180,13 @@ static void set_state(struct cocoa_surface *w, uint32_t bit, bool on) { if (!w || w->closed) return; - uint32_t next = on ? (w->state | bit) : (w->state & ~bit); - if (next == w->state) + uint32_t next = on ? (w->base.state | bit) : (w->base.state & ~bit); + if (next == w->base.state) return; - w->state = next; + w->base.state = next; darwin_ctx.depth++; if (w->cbs->state) - w->cbs->state(&w->base, w->state, w->ud); + w->cbs->state(&w->base, next, w->ud); darwin_ctx.depth--; } @@ -713,7 +713,7 @@ static struct yasl_vector2i dragging_pos(YaslView *view, id send if (period > 0.0 && period < 0.25) w->clock.refresh_ns = period * 1e9; w->frame_due = true; - if (!w->want_draw || (w->state & YASL_STATE_SUSPENDED)) { + if (!w->want_draw || (w->base.state & YASL_STATE_SUSPENDED)) { if (++w->idle_frames >= LINK_IDLE_FRAMES) link.paused = YES; return; @@ -1069,7 +1069,7 @@ bool cocoa_surface_present(struct cocoa_surface *w, const struct yasl_framebuffe static void render_and_commit(struct cocoa_surface *w) { if (w->closed || !w->cbs->draw || w->rendering || w->size.x <= 0 || w->size.y <= 0 || - (w->state & YASL_STATE_SUSPENDED)) + (w->base.state & YASL_STATE_SUSPENDED)) return; size_t count = (size_t)w->size.x * (size_t)w->size.y; @@ -2042,12 +2042,6 @@ static struct yasl_geometry impl_surface_geometry(const struct yasl_surface *s) return cocoa_surface_geometry((const struct cocoa_surface *)s); } -static uint32_t impl_surface_state(const struct yasl_surface *s) -{ - const struct cocoa_surface *w = (const struct cocoa_surface *)s; - return w ? w->state : 0; -} - static struct yasl_timing impl_surface_timing(const struct yasl_surface *s) { return cocoa_surface_timing((const struct cocoa_surface *)s); @@ -2156,7 +2150,6 @@ const struct yasl_backend_ops yasl_cocoa_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/sync.h b/src/platform/sync.h index 1dcf28f..43b4a34 100644 --- a/src/platform/sync.h +++ b/src/platform/sync.h @@ -5,6 +5,6 @@ * yasl_mutex_init/destroy/lock/unlock operations. Init returns zero on success * or an errno value on failure. The other operations require an initialized * mutex. Native types and calls stay in the selected implementation header. */ -#include "yasl_platform_sync.h" +#include "yasl_platform_sync.h" // IWYU pragma: export #endif 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; diff --git a/src/platform/x11/keymap.h b/src/platform/x11/keymap.h index 2ec4295..8114fb5 100644 --- a/src/platform/x11/keymap.h +++ b/src/platform/x11/keymap.h @@ -1,7 +1,7 @@ #ifndef YASL_X11_KEYMAP_H #define YASL_X11_KEYMAP_H -#include "yasl/yasl.h" +#include "yasl/keycodes.h" enum yasl_key yasl_key_from_xkb_name(const char name[4]); diff --git a/src/platform/x11/window.c b/src/platform/x11/window.c index 347b4c2..3bab6e2 100644 --- a/src/platform/x11/window.c +++ b/src/platform/x11/window.c @@ -58,7 +58,6 @@ struct x11_surface { struct yasl_frame frame; struct yasl_damage_list damage; struct yasl_frame_clock clock; - uint32_t state; bool want_draw, drawing, presented, destroyed; struct x11_surface *parent; bool is_popup; @@ -700,7 +699,7 @@ static struct yasl_surface *create_toplevel(struct yasl_display *base, if (spec->fullscreen) { XChangeProperty(d->native, s->window, d->net_state, XA_ATOM, 32, PropModeReplace, (unsigned char *)&d->fullscreen, 1); - s->state |= YASL_STATE_FULLSCREEN; + s->base.state |= YASL_STATE_FULLSCREEN; } XMapWindow(d->native, s->window); XFlush(d->native); @@ -893,7 +892,7 @@ static void update_state(struct x11_surface *s) int format; unsigned long count, left; unsigned char *data = NULL; - uint32_t state = s->state & YASL_STATE_ACTIVATED; + uint32_t state = s->base.state & ~(YASL_STATE_FULLSCREEN | YASL_STATE_MAXIMIZED); if (XGetWindowProperty(d->native, s->window, d->net_state, 0, 64, False, XA_ATOM, &actual, &format, &count, &left, &data) == Success && format == 32) { Atom *atoms = (Atom *)data; @@ -906,8 +905,8 @@ static void update_state(struct x11_surface *s) if (h && v) state |= YASL_STATE_MAXIMIZED; } if (data) XFree(data); - if (state == s->state) return; - s->state = state; + if (state == s->base.state) return; + s->base.state = state; if (s->cbs && s->cbs->state) s->cbs->state(&s->base, state, s->ud); } @@ -1335,11 +1334,11 @@ static void dispatch(struct yasl_display *base) case FocusIn: case FocusOut: { bool focused = event.type == FocusIn; if (s->ic) { if (focused) XSetICFocus(s->ic); else XUnsetICFocus(s->ic); } - if (focused) s->state |= YASL_STATE_ACTIVATED; - else s->state &= ~YASL_STATE_ACTIVATED; + if (focused) s->base.state |= YASL_STATE_ACTIVATED; + else s->base.state &= ~YASL_STATE_ACTIVATED; push(s, (struct yasl_input_event){ .kind = YASL_INPUT_FOCUS, .focus.focused = focused}, NULL, 0); - if (s->cbs && s->cbs->state) s->cbs->state(&s->base, s->state, s->ud); + if (s->cbs && s->cbs->state) s->cbs->state(&s->base, s->base.state, s->ud); break; } case PropertyNotify: @@ -1746,7 +1745,6 @@ static struct yasl_geometry geometry(const struct yasl_surface *s) { return (struct yasl_geometry){((const struct x11_surface *)s)->size, YASL_SCALE_UNIT}; } -static uint32_t state(const struct yasl_surface *s) { return ((const struct x11_surface *)s)->state; } static int mods(const struct yasl_display *d) { return (int)((const struct x11_display *)d)->mods; } static void *native_display(struct yasl_display *d) { return ((struct x11_display *)d)->native; } static void *native_surface(struct yasl_surface *s) { return (void *)(uintptr_t)((struct x11_surface *)s)->window; } @@ -2042,7 +2040,6 @@ const struct yasl_backend_ops yasl_x11_backend = { .surface_present = present, .surface_input_poll = input_poll, .surface_geometry = geometry, - .surface_state = state, .surface_timing = timing, .surface_frame_time_ns = frame_time, .surface_set_cursor = cursor, -- cgit v1.2.3