Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core, wl: Factor out view fullscreening #716

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 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_set_fullscreen(self, !cog_view_is_fullscreen(self));

return FALSE;
}

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

return TRUE;
}

/**
* cog_view_set_fullscreen:
* @self: A view.
* @enable: Whether to enable fullscreening.
*
* Change the fullscreening status of the view.
*
* Note that not all platform plug-ins may implement view fullscreening,
* and in that case %FALSE is always returned.
*
* Returns: Whether the view fullscreening state was set to the requested one.
*
* Since: 0.20
*/
gboolean
cog_view_set_fullscreen(CogView *self, gboolean enable)
{
g_return_val_if_fail(COG_IS_VIEW(self), FALSE);

CogViewClass *klass = COG_VIEW_GET_CLASS(self);
if (klass->set_fullscreen)
return (*klass->set_fullscreen)(self, enable);

return FALSE;
}

/**
* cog_view_is_fullscreen:
* @self: A view.
*
* Gets whether the view is fullscreened.
*
* Returns: Whether the view is fullscreened.
*
* Since: 0.20
*/
gboolean
cog_view_is_fullscreen(CogView *self)
{
g_return_val_if_fail(COG_IS_VIEW(self), FALSE);

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

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

WebKitWebViewBackend *(*create_backend)(CogView *);
/*< public >*/
WebKitWebViewBackend *(*create_backend)(CogView *self);
gboolean (*set_fullscreen)(CogView *self, gboolean enable);
gboolean (*is_fullscreen)(CogView *self);
};

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

COG_API gboolean cog_view_set_fullscreen(CogView *self, gboolean enable);
COG_API gboolean cog_view_is_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
27 changes: 27 additions & 0 deletions platform/wayland/cog-view-wl.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ 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_set_fullscreen(CogView *, gboolean);
static gboolean cog_wl_view_is_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 +91,8 @@ 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->set_fullscreen = cog_wl_view_set_fullscreen;
view_class->is_fullscreen = cog_wl_view_is_fullscreen;
}

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

gboolean
cog_wl_view_is_fullscreen(CogView *self)
{
CogWlViewport *viewport = COG_WL_VIEWPORT(cog_view_get_viewport(self));
return viewport->window.is_fullscreen ? TRUE : FALSE;
}

gboolean
cog_wl_view_set_fullscreen(CogView *self, gboolean enable)
{
if (cog_wl_view_is_fullscreen(self) == enable)
return TRUE;

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, enable ? true : false);
}
return TRUE;
}

bool
cog_wl_view_does_image_match_win_size(CogWlView *view)
{
Expand Down
Loading