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

wl: Change IM context functions signature #671

Merged
merged 1 commit into from
Nov 23, 2023
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
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 @@ -1349,7 +1349,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 @@ -1359,12 +1359,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 @@ -481,8 +481,10 @@ cog_wl_seat_set_cursor(CogWlSeat *seat, enum cursor_type type)
#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 @@ -491,10 +493,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 @@ -50,7 +50,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 @@ -310,7 +309,7 @@ void cog_wl_seat_destroy(CogWlSeat *);
void cog_wl_seat_set_cursor(CogWlSeat *, enum cursor_type);
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