From 007a1281efe716cf619ba57562de8a166299d7a4 Mon Sep 17 00:00:00 2001 From: Pablo Saavedra Date: Mon, 23 Oct 2023 10:13:56 +0200 Subject: [PATCH] wl: Add CogWlPlatform::resized-window signal The `resized-window` signal is emitted when the window is resized. Handling this signal allows to react to changes in the geometry of the window and decouples the CogWlView from the CogWlPlatform internal logic. The view (or the views in the future) is now connected to this signal and reacts according. This change is motivated towards the progress of being able to have more than one view. --- platform/wayland/cog-platform-wl.c | 56 ++++++++++++++---------------- platform/wayland/cog-platform-wl.h | 2 ++ platform/wayland/cog-view-wl.c | 22 ++++++++++++ 3 files changed, 51 insertions(+), 29 deletions(-) diff --git a/platform/wayland/cog-platform-wl.c b/platform/wayland/cog-platform-wl.c index 06870b03..19deb0f3 100644 --- a/platform/wayland/cog-platform-wl.c +++ b/platform/wayland/cog-platform-wl.c @@ -70,6 +70,15 @@ # include #endif +enum { + RESIZED_WINDOW, + N_SIGNALS, +}; + +static int s_signals[N_SIGNALS] = { + 0, +}; + G_DEFINE_DYNAMIC_TYPE_EXTENDED( CogWlPlatform, cog_wl_platform, @@ -210,25 +219,9 @@ cog_wl_platform_configure_geometry(CogWlPlatform *platform, int32_t width, int32 g_debug("Configuring new size: %" PRId32 "x%" PRId32, width, height); platform->window.width = width; platform->window.height = height; - platform->view->should_update_opaque_region = true; - } -} -static void -cog_wl_platform_resize_window(CogWlPlatform *platform) -{ - CogWlDisplay *display = platform->display; - CogWlWindow *window = &platform->window; - - int32_t pixel_width = window->width * display->current_output->scale; - int32_t pixel_height = window->height * display->current_output->scale; - - struct wpe_view_backend *backend = cog_view_get_backend(COG_VIEW(platform->view)); - wpe_view_backend_dispatch_set_size(backend, window->width, window->height); - wpe_view_backend_dispatch_set_device_scale_factor(backend, display->current_output->scale); - - g_debug("Resized EGL buffer to: (%" PRIi32 ", %" PRIi32 ") @%" PRIi32 "x", pixel_width, pixel_height, - display->current_output->scale); + g_signal_emit(platform, s_signals[RESIZED_WINDOW], 0); + } } static void @@ -249,8 +242,6 @@ shell_surface_on_configure(void *data, cog_wl_platform_configure_geometry(platform, width, height); g_debug("New wl_shell configuration: (%" PRIu32 ", %" PRIu32 ")", width, height); - - cog_wl_platform_resize_window(platform); } static const struct wl_shell_surface_listener shell_surface_listener = { @@ -364,11 +355,6 @@ resize_to_largest_output(CogWlPlatform *platform) } } cog_wl_platform_configure_geometry(platform, width, height); - - struct wpe_view_backend *backend = cog_view_get_backend(COG_VIEW(platform->view)); - if (backend != NULL) { - cog_wl_platform_resize_window(platform); - } } static void @@ -459,9 +445,8 @@ cog_wl_platform_set_fullscreen(CogWlPlatform *platform, bool fullscreen) return false; platform->window.is_fullscreen = fullscreen; - if (fullscreen) { - // Resize the view_backend to the size of the screen. + // Resize window to the size of the screen. // Wait until a new exported image is reveived. See cog_wl_view_enter_fullscreen(). platform->window.is_resizing_fullscreen = true; platform->window.width_before_fullscreen = platform->window.width; @@ -480,8 +465,6 @@ cog_wl_platform_set_fullscreen(CogWlPlatform *platform, bool fullscreen) } cog_wl_platform_configure_geometry(platform, platform->window.width_before_fullscreen, platform->window.height_before_fullscreen); - cog_wl_platform_resize_window(platform); - #if HAVE_FULLSCREEN_HANDLING if (platform->window.was_fullscreen_requested_from_dom) { struct wpe_view_backend *backend = cog_view_get_backend(COG_VIEW(platform->view)); @@ -2046,6 +2029,21 @@ cog_wl_platform_class_init(CogWlPlatformClass *klass) platform_class->setup = cog_wl_platform_setup; platform_class->init_web_view = cog_wl_platform_init_web_view; platform_class->create_im_context = cog_wl_platform_create_im_context; + + /** + * CogWlPlatform::resized-window: + * @self: The platform. + * @user_data: User data. + * + * The `resized-window` signal is emitted when the window is resized. + * + * Handling this signal allows to react to changes in the geometry of + * the window. + * + * Returns: (void) + */ + s_signals[RESIZED_WINDOW] = + g_signal_new("resized-window", COG_WL_PLATFORM_TYPE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); } static void diff --git a/platform/wayland/cog-platform-wl.h b/platform/wayland/cog-platform-wl.h index ef68cacb..232c9d5c 100644 --- a/platform/wayland/cog-platform-wl.h +++ b/platform/wayland/cog-platform-wl.h @@ -17,6 +17,8 @@ G_BEGIN_DECLS typedef struct _CogWlView CogWlView; +#define COG_WL_PLATFORM_TYPE cog_wl_platform_get_type() + G_DECLARE_FINAL_TYPE(CogWlPlatform, cog_wl_platform, COG, WL_PLATFORM, CogPlatform) struct _CogWlPlatformClass { diff --git a/platform/wayland/cog-view-wl.c b/platform/wayland/cog-view-wl.c index 1fb40980..c9b9f28f 100644 --- a/platform/wayland/cog-view-wl.c +++ b/platform/wayland/cog-view-wl.c @@ -37,6 +37,8 @@ static void cog_wl_view_dispose(GObject *); #if HAVE_FULLSCREEN_HANDLING static bool cog_wl_view_handle_dom_fullscreen_request(void *, bool); #endif +static void cog_wl_view_resize_window(CogWlView *, CogWlPlatform *); + static void cog_wl_view_shm_buffer_destroy(CogWlView *, struct shm_buffer *); static void presentation_feedback_on_discarded(void *, struct wp_presentation_feedback *); @@ -94,6 +96,7 @@ cog_wl_view_init(CogWlView *self) wl_list_init(&self->shm_buffer_list); g_signal_connect(self, "show-option-menu", G_CALLBACK(on_show_option_menu), NULL); + g_signal_connect_swapped(self->platform, "resized-window", G_CALLBACK(cog_wl_view_resize_window), self); } /* @@ -279,6 +282,25 @@ cog_wl_view_request_frame(CogWlView *view) } } +static void +cog_wl_view_resize_window(CogWlView *view, CogWlPlatform *platform) +{ + CogWlDisplay *display = platform->display; + CogWlWindow *window = &platform->window; + + view->should_update_opaque_region = true; + + int32_t pixel_width = window->width * display->current_output->scale; + int32_t pixel_height = window->height * display->current_output->scale; + + struct wpe_view_backend *backend = cog_view_get_backend(COG_VIEW(view)); + wpe_view_backend_dispatch_set_size(backend, window->width, window->height); + wpe_view_backend_dispatch_set_device_scale_factor(backend, display->current_output->scale); + + g_debug("Resized EGL buffer to: (%" PRIi32 ", %" PRIi32 ") @%" PRIi32 "x", pixel_width, pixel_height, + display->current_output->scale); +} + void cog_wl_view_update_surface_contents(CogWlView *view) {