Skip to content

Commit

Permalink
wl: Add CogWlPlatform::resized-window signal
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
psaavedra committed Oct 23, 2023
1 parent 660bb81 commit 6ce79c8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 28 deletions.
54 changes: 26 additions & 28 deletions platform/wayland/cog-platform-wl.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@
# include <wayland-cursor.h>
#endif

enum {
RESIZED_WINDOW,
N_SIGNALS,
};

static int s_signals[N_SIGNALS] = {
0,
};

G_DEFINE_DYNAMIC_TYPE_EXTENDED(
CogWlPlatform,
cog_wl_platform,
Expand Down Expand Up @@ -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
Expand All @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -459,7 +445,6 @@ cog_wl_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.
// Wait until a new exported image is reveived. See cog_wl_view_enter_fullscreen().
Expand All @@ -479,8 +464,6 @@ cog_wl_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));
Expand Down Expand Up @@ -2042,6 +2025,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 resized window.
* @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
Expand Down
2 changes: 2 additions & 0 deletions platform/wayland/cog-platform-wl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ typedef struct _CogWlView CogWlView;

G_BEGIN_DECLS

#define COG_WL_PLATFORM_TYPE cog_wl_platform_get_type()

G_DECLARE_FINAL_TYPE(CogWlPlatform, cog_wl_platform, COG, WL_PLATFORM, CogPlatform)
G_END_DECLS

Expand Down
22 changes: 22 additions & 0 deletions platform/wayland/cog-view-wl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down Expand Up @@ -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);
}

/*
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 6ce79c8

Please sign in to comment.