Skip to content

Commit

Permalink
wl: Change IM context functions signature
Browse files Browse the repository at this point in the history
The input method context is now defined and assigned to the View once
this is added to a Viewport, in cog_viewport_add(). It is not possible
before because we need to have access to the wl_surface associated to
the Viewport->Window for configuring the IM context.
  • Loading branch information
psaavedra committed Nov 23, 2023
1 parent 4333758 commit f8d84ed
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 18 deletions.
5 changes: 3 additions & 2 deletions core/cog-platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,14 @@ cog_platform_init_web_view (CogPlatform *platform,
}

WebKitInputMethodContext *
cog_platform_create_im_context(CogPlatform *platform)
cog_platform_create_im_context(CogViewport *viewport)
{
CogPlatform *platform = cog_platform_get();
g_return_val_if_fail(COG_IS_PLATFORM(platform), NULL);

CogPlatformClass *klass = COG_PLATFORM_GET_CLASS(platform);
if (klass->create_im_context)
return klass->create_im_context(platform);
return klass->create_im_context(viewport);

return NULL;
}
9 changes: 5 additions & 4 deletions core/cog-platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ G_BEGIN_DECLS

#define COG_PLATFORM_ERROR (cog_platform_error_quark())

typedef struct _CogViewport CogViewport;

typedef enum {
COG_PLATFORM_ERROR_NO_MODULE,
} CogPlatformError;
Expand Down Expand Up @@ -47,7 +49,7 @@ struct _CogPlatformClass {
gboolean (*setup)(CogPlatform *, CogShell *shell, const char *params, GError **);
WebKitWebViewBackend *(*get_view_backend)(CogPlatform *, WebKitWebView *related_view, GError **);
void (*init_web_view)(CogPlatform *, WebKitWebView *);
WebKitInputMethodContext *(*create_im_context)(CogPlatform *);
WebKitInputMethodContext *(*create_im_context)(CogViewport *);

GType (*get_view_type)(void);
GType (*get_viewport_type)(void);
Expand All @@ -64,11 +66,10 @@ WebKitWebViewBackend *cog_platform_get_view_backend (CogPlatform *platfor
GError **error);

COG_API
void cog_platform_init_web_view (CogPlatform *platform,
WebKitWebView *view);
void cog_platform_init_web_view(CogPlatform *platform, WebKitWebView *view);

COG_API
WebKitInputMethodContext *cog_platform_create_im_context (CogPlatform *platform);
WebKitInputMethodContext *cog_platform_create_im_context(CogViewport *viewport);

G_END_DECLS

Expand Down
5 changes: 5 additions & 0 deletions core/cog-viewport.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ cog_viewport_add(CogViewport *self, CogView *view)
struct wpe_view_backend *backend = cog_view_get_backend(view);
wpe_view_backend_add_activity_state(backend, wpe_view_activity_state_in_window);

g_autoptr(WebKitInputMethodContext) im_context = cog_platform_create_im_context(self);
webkit_web_view_set_input_method_context(WEBKIT_WEB_VIEW(view), im_context);

if (!priv->visible_view) {
g_debug("%s<%p>: adding view %p as visible", G_STRFUNC, self, view);
cog_viewport_set_visible_view_internal(self, priv, view);
Expand Down Expand Up @@ -307,6 +310,8 @@ cog_viewport_remove(CogViewport *self, CogView *view)
return;
}

webkit_web_view_set_input_method_context(WEBKIT_WEB_VIEW(view), NULL);

cog_view_set_viewport(view, NULL);

g_object_ref(view);
Expand Down
2 changes: 0 additions & 2 deletions launcher/cog-launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ cog_launcher_create_view(CogLauncher *self, CogShell *shell)
g_signal_connect(web_view, "create", G_CALLBACK(on_web_view_create), NULL);

cog_platform_init_web_view(platform, web_view);
g_autoptr(WebKitInputMethodContext) im_context = cog_platform_create_im_context(platform);
webkit_web_view_set_input_method_context(web_view, im_context);

if (s_options.background_color != NULL) {
WebKitColor color;
Expand Down
10 changes: 6 additions & 4 deletions platform/wayland/cog-platform-wl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ cog_wl_platform_finalize(GObject *object)
{
CogWlPlatform *platform = COG_WL_PLATFORM(object);

cog_wl_text_input_clear(platform);
cog_wl_text_input_clear();
if (platform->popup)
cog_wl_platform_popup_destroy();
clear_egl(platform->display);
Expand All @@ -1371,12 +1371,14 @@ cog_wl_platform_finalize(GObject *object)
}

static WebKitInputMethodContext *
cog_wl_platform_create_im_context(CogPlatform *platform)
cog_wl_platform_create_im_context(CogViewport *viewport)
{
CogWlPlatform *platform = (CogWlPlatform *) cog_platform_get();
g_assert(COG_WL_PLATFORM(platform)->display->seat_default);
cog_wl_text_input_set(COG_WL_PLATFORM(platform), COG_WL_PLATFORM(platform)->display->seat_default);
CogWlDisplay *display = COG_WL_PLATFORM(platform)->display;

cog_wl_text_input_set(COG_WL_VIEWPORT(viewport), COG_WL_PLATFORM(platform)->display->seat_default);

CogWlDisplay *display = COG_WL_PLATFORM(platform)->display;
if (display->text_input_manager)
return cog_im_context_wl_new();
if (display->text_input_manager_v1)
Expand Down
9 changes: 6 additions & 3 deletions platform/wayland/cog-utils-wl.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,10 @@ cog_wl_seat_set_cursor(CogWlSeat *seat, WebKitHitTestResult *hit_test)
#endif /* COG_USE_WAYLAND_CURSOR */

void
cog_wl_text_input_clear(CogWlPlatform *platform)
cog_wl_text_input_clear(void)
{
CogWlPlatform *platform = (CogWlPlatform *) cog_platform_get();

CogWlDisplay *display = platform->display;
cog_im_context_wl_set_text_input(NULL);
g_clear_pointer(&display->text_input_manager, zwp_text_input_manager_v3_destroy);
Expand All @@ -493,10 +495,11 @@ cog_wl_text_input_clear(CogWlPlatform *platform)
}

void
cog_wl_text_input_set(CogWlPlatform *platform, CogWlSeat *seat)
cog_wl_text_input_set(CogWlViewport *viewport, CogWlSeat *seat)
{
CogWlPlatform *platform = (CogWlPlatform *) cog_platform_get();
CogWlDisplay *display = platform->display;
CogWlViewport *viewport = COG_WL_VIEWPORT(platform->viewport);

if (display->text_input_manager != NULL) {
struct zwp_text_input_v3 *text_input =
zwp_text_input_manager_v3_get_text_input(display->text_input_manager, seat->seat);
Expand Down
5 changes: 2 additions & 3 deletions platform/wayland/cog-utils-wl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ typedef struct _CogWlTouch CogWlTouch;
typedef struct _CogWlWindow CogWlWindow;
typedef struct _CogWlXkb CogWlXkb;

typedef struct _CogWlPlatform CogWlPlatform;
typedef struct _CogWlViewport CogWlViewport;

struct _CogWlAxis {
Expand Down Expand Up @@ -311,7 +310,7 @@ void cog_wl_seat_destroy(CogWlSeat *);
void cog_wl_seat_set_cursor(CogWlSeat *, WebKitHitTestResult *);
uint32_t cog_wl_seat_get_serial(CogWlSeat *);

void cog_wl_text_input_clear(CogWlPlatform *);
void cog_wl_text_input_set(CogWlPlatform *, CogWlSeat *);
void cog_wl_text_input_clear(void);
void cog_wl_text_input_set(CogWlViewport *, CogWlSeat *);

G_END_DECLS

0 comments on commit f8d84ed

Please sign in to comment.