From 16bedd8b739808193b527f173c0ae2053926b736 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Tue, 10 Feb 2026 12:43:12 +0100 Subject: redraw request --- src/events.h | 12 ++-- src/wayclock.cc | 26 ++++++++- src/window.cc | 10 ++++ src/window.h | 2 + src/xdg-shell.c | 171 ++++++++++++++++++++++++++------------------------------ 5 files changed, 123 insertions(+), 98 deletions(-) (limited to 'src') diff --git a/src/events.h b/src/events.h index 16bf1d3..ea241ce 100644 --- a/src/events.h +++ b/src/events.h @@ -8,31 +8,35 @@ enum event_kind_e { EVENT_KIND_RESIZE, EVENT_KIND_CLOSE, + EVENT_KIND_FRAME, }; struct event_kind_resize_s { i32 width, height; }; -union event_kind_data_u { +union event_data_u { struct event_kind_resize_s resize; }; struct event_s { enum event_kind_e kind; struct window_s *window; - union event_kind_data_u data; + union event_data_u data; }; #define WAYC_EVENT_INIT(kind, window, ...) \ event_s { kind, window, __VA_ARGS__ } #define WAYC_EVENT_CLOSE(window) \ - WAYC_EVENT_INIT(EVENT_KIND_CLOSE, window, event_kind_data_u{}) + WAYC_EVENT_INIT(EVENT_KIND_CLOSE, window, event_data_u{}) #define WAYC_EVENT_RESIZE(window, width, height) \ WAYC_EVENT_INIT(EVENT_KIND_RESIZE, window, \ - event_kind_data_u{event_kind_resize_s{width, height}}) + event_data_u{event_kind_resize_s{width, height}}) + +#define WAYC_EVENT_FRAME(window) \ + WAYC_EVENT_INIT(EVENT_KIND_FRAME, window, event_data_u{}) struct eventloop_s; diff --git a/src/wayclock.cc b/src/wayclock.cc index 369657e..17d7123 100644 --- a/src/wayclock.cc +++ b/src/wayclock.cc @@ -1,12 +1,33 @@ #include "events.h" #include "window.h" +#include #define WAYC_APP_NAME "Wayclock" +void frame(struct window_s *window, struct eventloop_s *loop) { + wayc_notnull(window); + wayc_notnull(loop); + + wayc_window_redraw(window, loop); +} + void handle(struct eventloop_s *loop, struct event_s *event) { + wayc_notnull(loop); + wayc_notnull(event); + + struct window_s *window = event->window; + union event_data_u data = event->data; + switch (event->kind) { case EVENT_KIND_CLOSE: - wayc_eventloop_unregister(loop, event->window->id); + wayc_eventloop_unregister(loop, window->id); + break; + case EVENT_KIND_RESIZE: + fprintf(stderr, "Window resized: %d x %d\n", data.resize.width, + data.resize.height); + break; + case EVENT_KIND_FRAME: + frame(window, loop); break; default: break; @@ -27,9 +48,8 @@ int main() { window_id_t winid = wayc_eventloop_register(&loop, &window); window.id = winid; - while (wayc_eventloop_running(&loop)) { + while (wayc_eventloop_running(&loop)) wayc_eventloop_update(&loop); - } wayc_window_deinit(&window); wayc_eventloop_deinit(&loop); diff --git a/src/window.cc b/src/window.cc index 496027b..1a59189 100644 --- a/src/window.cc +++ b/src/window.cc @@ -87,6 +87,7 @@ bool wayc_window_init(struct window_s *window, const char *name, window->surface = surface; window->xdg_surface = xdg_surface; window->xdg_toplevel = xdg_toplevel; + window->loop = loop; return true; } @@ -106,3 +107,12 @@ void wayc_window_deinit(struct window_s *window) { window->xdg_surface = nullptr; window->surface = nullptr; } + +void wayc_window_redraw(struct window_s *window, struct eventloop_s *loop) { + wayc_notnull(window); + wayc_notnull(loop); + + struct event_s event = WAYC_EVENT_FRAME(window); + wayc_vec_push(&loop->events, &event); + wl_surface_commit(window->surface); +} \ No newline at end of file diff --git a/src/window.h b/src/window.h index df4ee05..c302c2f 100644 --- a/src/window.h +++ b/src/window.h @@ -3,6 +3,7 @@ #include "utils.h" struct eventloop_s; + typedef u32 window_id_t; struct window_s { @@ -17,3 +18,4 @@ struct window_s { bool wayc_window_init(struct window_s *window, const char *name, struct eventloop_s *loop); void wayc_window_deinit(struct window_s *window); +void wayc_window_redraw(struct window_s *window, struct eventloop_s *loop); diff --git a/src/xdg-shell.c b/src/xdg-shell.c index 5a50433..14733ba 100644 --- a/src/xdg-shell.c +++ b/src/xdg-shell.c @@ -28,17 +28,17 @@ * DEALINGS IN THE SOFTWARE. */ +#include "wayland-util.h" #include -#include #include -#include "wayland-util.h" +#include #ifndef __has_attribute -# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ #endif #if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) -#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#define WL_PRIVATE __attribute__((visibility("hidden"))) #else #define WL_PRIVATE #endif @@ -52,133 +52,122 @@ extern const struct wl_interface xdg_surface_interface; extern const struct wl_interface xdg_toplevel_interface; static const struct wl_interface *xdg_shell_types[] = { - NULL, - NULL, - NULL, - NULL, - &xdg_positioner_interface, - &xdg_surface_interface, - &wl_surface_interface, - &xdg_toplevel_interface, - &xdg_popup_interface, - &xdg_surface_interface, - &xdg_positioner_interface, - &xdg_toplevel_interface, - &wl_seat_interface, - NULL, - NULL, - NULL, - &wl_seat_interface, - NULL, - &wl_seat_interface, - NULL, - NULL, - &wl_output_interface, - &wl_seat_interface, - NULL, - &xdg_positioner_interface, - NULL, + NULL, + NULL, + NULL, + NULL, + &xdg_positioner_interface, + &xdg_surface_interface, + &wl_surface_interface, + &xdg_toplevel_interface, + &xdg_popup_interface, + &xdg_surface_interface, + &xdg_positioner_interface, + &xdg_toplevel_interface, + &wl_seat_interface, + NULL, + NULL, + NULL, + &wl_seat_interface, + NULL, + &wl_seat_interface, + NULL, + NULL, + &wl_output_interface, + &wl_seat_interface, + NULL, + &xdg_positioner_interface, + NULL, }; static const struct wl_message xdg_wm_base_requests[] = { - { "destroy", "", xdg_shell_types + 0 }, - { "create_positioner", "n", xdg_shell_types + 4 }, - { "get_xdg_surface", "no", xdg_shell_types + 5 }, - { "pong", "u", xdg_shell_types + 0 }, + {"destroy", "", xdg_shell_types + 0}, + {"create_positioner", "n", xdg_shell_types + 4}, + {"get_xdg_surface", "no", xdg_shell_types + 5}, + {"pong", "u", xdg_shell_types + 0}, }; static const struct wl_message xdg_wm_base_events[] = { - { "ping", "u", xdg_shell_types + 0 }, + {"ping", "u", xdg_shell_types + 0}, }; WL_PRIVATE const struct wl_interface xdg_wm_base_interface = { - "xdg_wm_base", 7, - 4, xdg_wm_base_requests, - 1, xdg_wm_base_events, + "xdg_wm_base", 7, 4, xdg_wm_base_requests, 1, xdg_wm_base_events, }; static const struct wl_message xdg_positioner_requests[] = { - { "destroy", "", xdg_shell_types + 0 }, - { "set_size", "ii", xdg_shell_types + 0 }, - { "set_anchor_rect", "iiii", xdg_shell_types + 0 }, - { "set_anchor", "u", xdg_shell_types + 0 }, - { "set_gravity", "u", xdg_shell_types + 0 }, - { "set_constraint_adjustment", "u", xdg_shell_types + 0 }, - { "set_offset", "ii", xdg_shell_types + 0 }, - { "set_reactive", "3", xdg_shell_types + 0 }, - { "set_parent_size", "3ii", xdg_shell_types + 0 }, - { "set_parent_configure", "3u", xdg_shell_types + 0 }, + {"destroy", "", xdg_shell_types + 0}, + {"set_size", "ii", xdg_shell_types + 0}, + {"set_anchor_rect", "iiii", xdg_shell_types + 0}, + {"set_anchor", "u", xdg_shell_types + 0}, + {"set_gravity", "u", xdg_shell_types + 0}, + {"set_constraint_adjustment", "u", xdg_shell_types + 0}, + {"set_offset", "ii", xdg_shell_types + 0}, + {"set_reactive", "3", xdg_shell_types + 0}, + {"set_parent_size", "3ii", xdg_shell_types + 0}, + {"set_parent_configure", "3u", xdg_shell_types + 0}, }; WL_PRIVATE const struct wl_interface xdg_positioner_interface = { - "xdg_positioner", 7, - 10, xdg_positioner_requests, - 0, NULL, + "xdg_positioner", 7, 10, xdg_positioner_requests, 0, NULL, }; static const struct wl_message xdg_surface_requests[] = { - { "destroy", "", xdg_shell_types + 0 }, - { "get_toplevel", "n", xdg_shell_types + 7 }, - { "get_popup", "n?oo", xdg_shell_types + 8 }, - { "set_window_geometry", "iiii", xdg_shell_types + 0 }, - { "ack_configure", "u", xdg_shell_types + 0 }, + {"destroy", "", xdg_shell_types + 0}, + {"get_toplevel", "n", xdg_shell_types + 7}, + {"get_popup", "n?oo", xdg_shell_types + 8}, + {"set_window_geometry", "iiii", xdg_shell_types + 0}, + {"ack_configure", "u", xdg_shell_types + 0}, }; static const struct wl_message xdg_surface_events[] = { - { "configure", "u", xdg_shell_types + 0 }, + {"configure", "u", xdg_shell_types + 0}, }; WL_PRIVATE const struct wl_interface xdg_surface_interface = { - "xdg_surface", 7, - 5, xdg_surface_requests, - 1, xdg_surface_events, + "xdg_surface", 7, 5, xdg_surface_requests, 1, xdg_surface_events, }; static const struct wl_message xdg_toplevel_requests[] = { - { "destroy", "", xdg_shell_types + 0 }, - { "set_parent", "?o", xdg_shell_types + 11 }, - { "set_title", "s", xdg_shell_types + 0 }, - { "set_app_id", "s", xdg_shell_types + 0 }, - { "show_window_menu", "ouii", xdg_shell_types + 12 }, - { "move", "ou", xdg_shell_types + 16 }, - { "resize", "ouu", xdg_shell_types + 18 }, - { "set_max_size", "ii", xdg_shell_types + 0 }, - { "set_min_size", "ii", xdg_shell_types + 0 }, - { "set_maximized", "", xdg_shell_types + 0 }, - { "unset_maximized", "", xdg_shell_types + 0 }, - { "set_fullscreen", "?o", xdg_shell_types + 21 }, - { "unset_fullscreen", "", xdg_shell_types + 0 }, - { "set_minimized", "", xdg_shell_types + 0 }, + {"destroy", "", xdg_shell_types + 0}, + {"set_parent", "?o", xdg_shell_types + 11}, + {"set_title", "s", xdg_shell_types + 0}, + {"set_app_id", "s", xdg_shell_types + 0}, + {"show_window_menu", "ouii", xdg_shell_types + 12}, + {"move", "ou", xdg_shell_types + 16}, + {"resize", "ouu", xdg_shell_types + 18}, + {"set_max_size", "ii", xdg_shell_types + 0}, + {"set_min_size", "ii", xdg_shell_types + 0}, + {"set_maximized", "", xdg_shell_types + 0}, + {"unset_maximized", "", xdg_shell_types + 0}, + {"set_fullscreen", "?o", xdg_shell_types + 21}, + {"unset_fullscreen", "", xdg_shell_types + 0}, + {"set_minimized", "", xdg_shell_types + 0}, }; static const struct wl_message xdg_toplevel_events[] = { - { "configure", "iia", xdg_shell_types + 0 }, - { "close", "", xdg_shell_types + 0 }, - { "configure_bounds", "4ii", xdg_shell_types + 0 }, - { "wm_capabilities", "5a", xdg_shell_types + 0 }, + {"configure", "iia", xdg_shell_types + 0}, + {"close", "", xdg_shell_types + 0}, + {"configure_bounds", "4ii", xdg_shell_types + 0}, + {"wm_capabilities", "5a", xdg_shell_types + 0}, }; WL_PRIVATE const struct wl_interface xdg_toplevel_interface = { - "xdg_toplevel", 7, - 14, xdg_toplevel_requests, - 4, xdg_toplevel_events, + "xdg_toplevel", 7, 14, xdg_toplevel_requests, 4, xdg_toplevel_events, }; static const struct wl_message xdg_popup_requests[] = { - { "destroy", "", xdg_shell_types + 0 }, - { "grab", "ou", xdg_shell_types + 22 }, - { "reposition", "3ou", xdg_shell_types + 24 }, + {"destroy", "", xdg_shell_types + 0}, + {"grab", "ou", xdg_shell_types + 22}, + {"reposition", "3ou", xdg_shell_types + 24}, }; static const struct wl_message xdg_popup_events[] = { - { "configure", "iiii", xdg_shell_types + 0 }, - { "popup_done", "", xdg_shell_types + 0 }, - { "repositioned", "3u", xdg_shell_types + 0 }, + {"configure", "iiii", xdg_shell_types + 0}, + {"popup_done", "", xdg_shell_types + 0}, + {"repositioned", "3u", xdg_shell_types + 0}, }; WL_PRIVATE const struct wl_interface xdg_popup_interface = { - "xdg_popup", 7, - 3, xdg_popup_requests, - 3, xdg_popup_events, + "xdg_popup", 7, 3, xdg_popup_requests, 3, xdg_popup_events, }; - -- cgit v1.2.3