Skip to content

Commit

Permalink
core, wl: Factor out view fullscreening
Browse files Browse the repository at this point in the history
Move view fullscreening to a new vfunc in the CogView class, which gets
in turn implemented by CogWlView. This moves the entry point to common
code, which would allow other platform plug-ins to implement the
functionality if desired. Also, handling its key binding can be moved
along to common code.
  • Loading branch information
aperezdc committed Jun 13, 2024
1 parent b40c212 commit e9265c7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
16 changes: 16 additions & 0 deletions core/cog-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ cog_view_try_handle_key_binding(CogView *self, const struct wpe_input_keyboard_e
return TRUE;
}

/* F11, toggle fullscreen */
if (!event->modifiers && event->key_code == WPE_KEY_F11)
return cog_view_toggle_fullscreen(self);

return FALSE;
}

Expand Down Expand Up @@ -499,3 +503,15 @@ cog_view_set_visible(CogView *self)

return TRUE;
}

gboolean
cog_view_toggle_fullscreen(CogView *self)
{
g_return_val_if_fail(COG_IS_VIEW(self), FALSE);

CogViewClass *klass = COG_VIEW_GET_CLASS(self);
if (klass->toggle_fullscreen)
return (*klass->toggle_fullscreen)(self);

return FALSE;
}
4 changes: 4 additions & 0 deletions core/cog-view.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ struct _CogViewClass {
/*< private >*/
WebKitWebViewClass parent_class;

/*< public >*/
WebKitWebViewBackend *(*create_backend)(CogView *);
gboolean (*toggle_fullscreen)(CogView *);
};

#define COG_TYPE_VIEW_IMPL (cog_view_get_impl_type())
Expand Down Expand Up @@ -61,4 +63,6 @@ gboolean cog_view_is_visible(CogView *self);
COG_API
gboolean cog_view_set_visible(CogView *self);

COG_API gboolean cog_view_toggle_fullscreen(CogView *self);

G_END_DECLS
13 changes: 0 additions & 13 deletions platform/wayland/cog-platform-wl.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,19 +579,6 @@ handle_key_event(CogWlSeat *seat, uint32_t key, uint32_t state, uint32_t time)
return;

uint32_t keysym = xkb_state_key_get_one_sym(seat->xkb.state, key);
uint32_t unicode = xkb_state_key_get_utf32(seat->xkb.state, key);

/* TODO: Move as much as possible from fullscreen handling to common code. */
if (cog_view_get_use_key_bindings(view) && state == WL_KEYBOARD_KEY_STATE_PRESSED && seat->xkb.modifiers == 0 &&
unicode == 0 && keysym == XKB_KEY_F11) {
if (viewport->window.is_fullscreen && viewport->window.was_fullscreen_requested_from_dom) {
struct wpe_view_backend *backend = cog_view_get_backend(view);
wpe_view_backend_dispatch_request_exit_fullscreen(backend);
return;
}
cog_wl_viewport_set_fullscreen(viewport, !viewport->window.is_fullscreen);
return;
}

if (seat->xkb.compose_state != NULL && state == WL_KEYBOARD_KEY_STATE_PRESSED &&
xkb_compose_state_feed(seat->xkb.compose_state, keysym) == XKB_COMPOSE_FEED_ACCEPTED &&
Expand Down
15 changes: 15 additions & 0 deletions platform/wayland/cog-view-wl.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ G_DEFINE_DYNAMIC_TYPE(CogWlView, cog_wl_view, COG_TYPE_VIEW)

static void cog_wl_view_clear_buffers(CogWlView *);
static WebKitWebViewBackend *cog_wl_view_create_backend(CogView *);
static gboolean cog_wl_view_toggle_fullscreen(CogView *);
static void cog_wl_view_dispose(GObject *);
static bool cog_wl_view_handle_dom_fullscreen_request(void *, bool);
static void cog_wl_view_shm_buffer_destroy(CogWlView *, struct shm_buffer *);
Expand Down Expand Up @@ -89,6 +90,7 @@ cog_wl_view_class_init(CogWlViewClass *klass)

CogViewClass *view_class = COG_VIEW_CLASS(klass);
view_class->create_backend = cog_wl_view_create_backend;
view_class->toggle_fullscreen = cog_wl_view_toggle_fullscreen;
}

static void
Expand Down Expand Up @@ -195,6 +197,19 @@ cog_wl_view_create_backend(CogView *view)
return wk_view_backend;
}

gboolean
cog_wl_view_toggle_fullscreen(CogView *self)
{
CogWlViewport *viewport = COG_WL_VIEWPORT(cog_view_get_viewport(self));
if (viewport->window.is_fullscreen && viewport->window.was_fullscreen_requested_from_dom) {
struct wpe_view_backend *backend = cog_view_get_backend(COG_VIEW(self));
wpe_view_backend_dispatch_request_exit_fullscreen(backend);
} else {
cog_wl_viewport_set_fullscreen(viewport, !viewport->window.is_fullscreen);
}
return TRUE;
}

bool
cog_wl_view_does_image_match_win_size(CogWlView *view)
{
Expand Down

0 comments on commit e9265c7

Please sign in to comment.