Commit 77b4c443 authored by Matthias Clasen's avatar Matthias Clasen

Merge branch 'wl_text_input_clean' into 'gtk-3-24'

Replace gtk_text_input with text_input_unstable_v3 support

See merge request !272
parents 5f0a14fa 8d77256d
Pipeline #22418 passed with stage
in 12 minutes and 16 seconds
......@@ -697,6 +697,14 @@ match_backend (GtkIMContextInfo *context)
{
#ifdef GDK_WINDOWING_WAYLAND
if (g_strcmp0 (context->context_id, "wayland") == 0)
{
GdkDisplay *display = gdk_display_get_default ();
return GDK_IS_WAYLAND_DISPLAY (display) &&
gdk_wayland_display_query_registry (display,
"zwp_text_input_manager_v3");
}
if (g_strcmp0 (context->context_id, "waylandgtk") == 0)
{
GdkDisplay *display = gdk_display_get_default ();
......
......@@ -1907,12 +1907,19 @@ gtk_settings_create_for_display (GdkDisplay *display)
if (GDK_IS_WAYLAND_DISPLAY (display))
{
if (gdk_wayland_display_query_registry (display,
"gtk_text_input_manager"))
"zwp_text_input_manager_v3"))
{
settings = g_object_new (GTK_TYPE_SETTINGS,
"gtk-im-module", "wayland",
NULL);
}
else if (gdk_wayland_display_query_registry (display,
"gtk_text_input_manager"))
{
settings = g_object_new (GTK_TYPE_SETTINGS,
"gtk-im-module", "waylandgtk",
NULL);
}
else
{
/* Fallback to other IM methods if the compositor does not
......
......@@ -175,8 +175,8 @@ endif
endif
protocol_built_sources = \
gtk-text-input-protocol.c \
gtk-text-input-client-protocol.h
text-input-unstable-v3-protocol.c \
text-input-unstable-v3-client-protocol.h
im_wayland_la_CPPFLAGS = $(AM_CPPFLAGS)
im_wayland_la_LDFLAGS = -rpath $(moduledir) -avoid-version -module $(no_undefined)
......@@ -191,6 +191,23 @@ WAYLAND_MODULE = im-wayland.la
endif
endif
protocol_built_sources_gtk = \
gtk-text-input-protocol.c \
gtk-text-input-client-protocol.h
im_waylandgtk_la_CPPFLAGS = $(AM_CPPFLAGS)
im_waylandgtk_la_LDFLAGS = -rpath $(moduledir) -avoid-version -module $(no_undefined)
im_waylandgtk_la_SOURCES = imwaylandgtk.c $(protocol_built_sources_gtk)
libstatic_im_waylandgtk_la_SOURCES = $(im_waylandgtk_la_SOURCES)
im_waylandgtk_la_LIBADD = $(LDADDS)
if INCLUDE_IM_WAYLAND
STATIC_WAYLANDGTK_MODULE = libstatic-im-waylandgtk.la
else
if USE_WAYLAND
WAYLANDGTK_MODULE = im-waylandgtk.la
endif
endif
multipress_defs = -DMULTIPRESS_LOCALEDIR=\""$(mplocaledir)"\" -DMULTIPRESS_CONFDIR=\""$(sysconfdir)/gtk-3.0"\"
im_multipress_la_CPPFLAGS = $(AM_CPPFLAGS) $(multipress_defs)
libstatic_im_multipress_la_CPPFLAGS = $(im_multipress_la_CPPFLAGS)
......@@ -253,6 +270,7 @@ module_LTLIBRARIES = \
$(QUARTZ_MODULE) \
$(BROADWAY_MODULE) \
$(WAYLAND_MODULE) \
$(WAYLANDGTK_MODULE) \
$(THAI_MODULE) \
$(TI_ER_MODULE) \
$(TI_ET_MODULE) \
......@@ -272,6 +290,7 @@ noinst_LTLIBRARIES = \
$(STATIC_QUARTZ_MODULE) \
$(STATIC_BROADWAY_MODULE) \
$(STATIC_WAYLAND_MODULE) \
$(STATIC_WAYLANDGTK_MODULE) \
$(STATIC_THAI_MODULE) \
$(STATIC_TI_ER_MODULE) \
$(STATIC_TI_ET_MODULE) \
......@@ -284,8 +303,8 @@ immodules.cache: Makefile.am $(module_LTLIBRARIES)
$(AM_V_GEN) $(top_builddir)/gtk/gtk-query-immodules-3.0$(EXEEXT) $(module_LTLIBRARIES) > immodules.cache
if USE_WAYLAND
BUILT_SOURCES = $(protocol_built_sources)
EXTRA_DIST += $(protocol_built_sources)
BUILT_SOURCES = $(protocol_built_sources) $(protocol_built_sources_gtk)
EXTRA_DIST += $(protocol_built_sources) $(protocol_built_sources_gtk)
endif
EXTRA_DIST += README.multipress
......
/* GTK - The GIMP Toolkit
* Copyright (C) 2017 Red Hat, Inc.
* Copyright (C) 2018 Purism SPC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -25,7 +26,7 @@
#include "gtk/gtkimmodule.h"
#include "gdk/wayland/gdkwayland.h"
#include "gtk-text-input-client-protocol.h"
#include "text-input-unstable-v3-client-protocol.h"
typedef struct _GtkIMContextWaylandGlobal GtkIMContextWaylandGlobal;
typedef struct _GtkIMContextWayland GtkIMContextWayland;
......@@ -36,9 +37,8 @@ struct _GtkIMContextWaylandGlobal
struct wl_display *display;
struct wl_registry *registry;
uint32_t text_input_manager_wl_id;
struct gtk_text_input_manager *text_input_manager;
struct gtk_text_input *text_input;
uint32_t enter_serial;
struct zwp_text_input_manager_v3 *text_input_manager;
struct zwp_text_input_v3 *text_input;
GtkIMContext *current;
};
......@@ -48,6 +48,17 @@ struct _GtkIMContextWaylandClass
GtkIMContextSimpleClass parent_class;
};
struct preedit {
gchar *text;
gint cursor_begin;
gint cursor_end;
};
struct surrounding_delete {
guint before_length;
guint after_length;
};
struct _GtkIMContextWayland
{
GtkIMContextSimple parent_instance;
......@@ -61,12 +72,19 @@ struct _GtkIMContextWayland
struct {
gchar *text;
gint cursor_idx;
gint anchor_idx;
} surrounding;
struct {
gchar *text;
gint cursor_idx;
} preedit;
enum zwp_text_input_v3_change_cause surrounding_change;
guint serial;
struct surrounding_delete pending_surrounding_delete;
struct preedit current_preedit;
struct preedit pending_preedit;
gchar *pending_commit;
cairo_rectangle_int_t cursor_rect;
guint use_preedit : 1;
......@@ -99,102 +117,182 @@ static const GtkIMContextInfo *info_list[] =
#endif
static void
reset_preedit (GtkIMContextWayland *context)
notify_external_change (GtkIMContextWayland *context)
{
if (context->preedit.text == NULL)
return;
gboolean result;
g_clear_pointer (&context->preedit.text, g_free);
context->preedit.cursor_idx = 0;
g_signal_emit_by_name (context, "preedit-changed");
context->surrounding_change = ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_OTHER;
g_signal_emit_by_name (global->current, "retrieve-surrounding", &result);
}
static void
text_input_enter (void *data,
struct gtk_text_input *text_input,
uint32_t serial,
struct zwp_text_input_v3 *text_input,
struct wl_surface *surface)
{
GtkIMContextWaylandGlobal *global = data;
global->enter_serial = serial;
}
{}
static void
text_input_leave (void *data,
struct gtk_text_input *text_input,
uint32_t serial,
struct zwp_text_input_v3 *text_input,
struct wl_surface *surface)
{
/*
GtkIMContextWayland *context;
if (!global->current)
return;
context = GTK_IM_CONTEXT_WAYLAND (global->current);
TODO: does this clear text input or modify text?
reset_preedit (context);
*/
}
static void
text_input_preedit (void *data,
struct gtk_text_input *text_input,
struct zwp_text_input_v3 *text_input,
const char *text,
guint cursor)
gint cursor_begin,
gint cursor_end)
{
GtkIMContextWayland *context;
gboolean state_change;
GtkIMContextWaylandGlobal *global = data;
if (!global->current)
return;
context = GTK_IM_CONTEXT_WAYLAND (global->current);
if (!text && !context->preedit.text)
g_free (context->pending_preedit.text);
context->pending_preedit.text = g_strdup (text);
context->pending_preedit.cursor_begin = cursor_begin;
context->pending_preedit.cursor_end = cursor_end;
}
static void
text_input_preedit_apply (GtkIMContextWaylandGlobal *global)
{
GtkIMContextWayland *context;
gboolean state_change;
struct preedit defaults = {0};
if (!global->current)
return;
state_change = ((text == NULL) != (context->preedit.text == NULL));
context = GTK_IM_CONTEXT_WAYLAND (global->current);
state_change = ((context->pending_preedit.text == NULL)
!= (context->current_preedit.text == NULL));
if (state_change && !context->preedit.text)
if (state_change && !context->current_preedit.text)
g_signal_emit_by_name (context, "preedit-start");
g_free (context->preedit.text);
context->preedit.text = g_strdup (text);
context->preedit.cursor_idx = cursor;
g_free (context->current_preedit.text);
context->current_preedit = context->pending_preedit;
context->pending_preedit = defaults;
g_signal_emit_by_name (context, "preedit-changed");
if (state_change && !context->preedit.text)
if (state_change && !context->current_preedit.text)
g_signal_emit_by_name (context, "preedit-end");
}
static void
text_input_commit (void *data,
struct gtk_text_input *text_input,
struct zwp_text_input_v3 *text_input,
const char *text)
{
GtkIMContextWaylandGlobal *global = data;
GtkIMContextWayland *context;
if (!global->current)
return;
context = GTK_IM_CONTEXT_WAYLAND (global->current);
g_free (context->pending_commit);
context->pending_commit = g_strdup (text);
}
if (global->current && text)
g_signal_emit_by_name (global->current, "commit", text);
static void
text_input_commit_apply (GtkIMContextWaylandGlobal *global, gboolean valid)
{
GtkIMContextWayland *context;
context = GTK_IM_CONTEXT_WAYLAND (global->current);
if (context->pending_commit && valid)
g_signal_emit_by_name (global->current, "commit", context->pending_commit);
g_free (context->pending_commit);
context->pending_commit = NULL;
}
static void
text_input_delete_surrounding_text (void *data,
struct gtk_text_input *text_input,
uint32_t offset,
uint32_t len)
struct zwp_text_input_v3 *text_input,
uint32_t before_length,
uint32_t after_length)
{
GtkIMContextWaylandGlobal *global = data;
GtkIMContextWayland *context;
if (!global->current)
return;
context = GTK_IM_CONTEXT_WAYLAND (global->current);
context->pending_surrounding_delete.before_length = before_length;
context->pending_surrounding_delete.after_length = after_length;
}
static void
text_input_delete_surrounding_text_apply (GtkIMContextWaylandGlobal *global,
gboolean valid)
{
GtkIMContextWayland *context;
gint len;
struct surrounding_delete defaults = {0};
context = GTK_IM_CONTEXT_WAYLAND (global->current);
len = context->pending_surrounding_delete.after_length
+ context->pending_surrounding_delete.before_length;
if (len > 0 && valid)
g_signal_emit_by_name (global->current, "delete-surrounding",
-context->pending_surrounding_delete.before_length,
len);
context->pending_surrounding_delete = defaults;
}
static void
text_input_done (void *data,
struct zwp_text_input_v3 *text_input,
uint32_t serial)
{
GtkIMContextWayland *context;
GtkIMContextWaylandGlobal *global = data;
gboolean result;
gboolean valid;
if (!global->current)
return;
if (global->current)
g_signal_emit_by_name (global->current, "delete-surrounding", offset, len);
context = GTK_IM_CONTEXT_WAYLAND (global->current);
valid = serial == context->serial;
text_input_delete_surrounding_text_apply(global, valid);
text_input_commit_apply(global, valid);
g_signal_emit_by_name (global->current, "retrieve-surrounding", &result);
text_input_preedit_apply(global);
}
static const struct gtk_text_input_listener text_input_listener = {
static const struct zwp_text_input_v3_listener text_input_listener = {
text_input_enter,
text_input_leave,
text_input_preedit,
text_input_commit,
text_input_delete_surrounding_text
text_input_delete_surrounding_text,
text_input_done,
};
static void
......@@ -207,17 +305,17 @@ registry_handle_global (void *data,
GtkIMContextWaylandGlobal *global = data;
GdkSeat *seat = gdk_display_get_default_seat (gdk_display_get_default ());
if (strcmp (interface, "gtk_text_input_manager") == 0)
if (strcmp (interface, "zwp_text_input_manager_v3") == 0)
{
global->text_input_manager_wl_id = id;
global->text_input_manager =
wl_registry_bind (global->registry, global->text_input_manager_wl_id,
&gtk_text_input_manager_interface, 1);
&zwp_text_input_manager_v3_interface, 1);
global->text_input =
gtk_text_input_manager_get_text_input (global->text_input_manager,
gdk_wayland_seat_get_wl_seat (seat));
gtk_text_input_add_listener (global->text_input,
&text_input_listener, global);
zwp_text_input_manager_v3_get_text_input (global->text_input_manager,
gdk_wayland_seat_get_wl_seat (seat));
zwp_text_input_v3_add_listener (global->text_input,
&text_input_listener, global);
}
}
......@@ -231,8 +329,8 @@ registry_handle_global_remove (void *data,
if (id != global->text_input_manager_wl_id)
return;
g_clear_pointer(&global->text_input, gtk_text_input_destroy);
g_clear_pointer(&global->text_input_manager, gtk_text_input_manager_destroy);
g_clear_pointer(&global->text_input, zwp_text_input_v3_destroy);
g_clear_pointer(&global->text_input_manager, zwp_text_input_manager_v3_destroy);
}
static const struct wl_registry_listener registry_listener = {
......@@ -262,10 +360,12 @@ notify_surrounding_text (GtkIMContextWayland *context)
if (!context->surrounding.text)
return;
gtk_text_input_set_surrounding_text (global->text_input,
context->surrounding.text,
context->surrounding.cursor_idx,
context->surrounding.cursor_idx);
zwp_text_input_v3_set_surrounding_text (global->text_input,
context->surrounding.text,
context->surrounding.cursor_idx,
context->surrounding.anchor_idx);
zwp_text_input_v3_set_text_change_cause (global->text_input,
context->surrounding_change);
}
static void
......@@ -284,9 +384,9 @@ notify_cursor_location (GtkIMContextWayland *context)
gdk_window_get_root_coords (context->window, rect.x, rect.y,
&rect.x, &rect.y);
gtk_text_input_set_cursor_rectangle (global->text_input,
rect.x, rect.y,
rect.width, rect.height);
zwp_text_input_v3_set_cursor_rectangle (global->text_input,
rect.x, rect.y,
rect.width, rect.height);
}
static uint32_t
......@@ -296,23 +396,23 @@ translate_hints (GtkInputHints input_hints,
uint32_t hints = 0;
if (input_hints & GTK_INPUT_HINT_SPELLCHECK)
hints |= GTK_TEXT_INPUT_CONTENT_HINT_SPELLCHECK;
hints |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_SPELLCHECK;
if (input_hints & GTK_INPUT_HINT_WORD_COMPLETION)
hints |= GTK_TEXT_INPUT_CONTENT_HINT_COMPLETION;
hints |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_COMPLETION;
if (input_hints & GTK_INPUT_HINT_LOWERCASE)
hints |= GTK_TEXT_INPUT_CONTENT_HINT_LOWERCASE;
hints |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_LOWERCASE;
if (input_hints & GTK_INPUT_HINT_UPPERCASE_CHARS)
hints |= GTK_TEXT_INPUT_CONTENT_HINT_UPPERCASE;
hints |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_UPPERCASE;
if (input_hints & GTK_INPUT_HINT_UPPERCASE_WORDS)
hints |= GTK_TEXT_INPUT_CONTENT_HINT_TITLECASE;
hints |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_TITLECASE;
if (input_hints & GTK_INPUT_HINT_UPPERCASE_SENTENCES)
hints |= GTK_TEXT_INPUT_CONTENT_HINT_AUTO_CAPITALIZATION;
hints |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_AUTO_CAPITALIZATION;
if (purpose == GTK_INPUT_PURPOSE_PIN ||
purpose == GTK_INPUT_PURPOSE_PASSWORD)
{
hints |= (GTK_TEXT_INPUT_CONTENT_HINT_HIDDEN_TEXT |
GTK_TEXT_INPUT_CONTENT_HINT_SENSITIVE_DATA);
hints |= (ZWP_TEXT_INPUT_V3_CONTENT_HINT_HIDDEN_TEXT |
ZWP_TEXT_INPUT_V3_CONTENT_HINT_SENSITIVE_DATA);
}
return hints;
......@@ -324,28 +424,28 @@ translate_purpose (GtkInputPurpose purpose)
switch (purpose)
{
case GTK_INPUT_PURPOSE_FREE_FORM:
return GTK_TEXT_INPUT_CONTENT_PURPOSE_NORMAL;
return ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL;
case GTK_INPUT_PURPOSE_ALPHA:
return GTK_TEXT_INPUT_CONTENT_PURPOSE_ALPHA;
return ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_ALPHA;
case GTK_INPUT_PURPOSE_DIGITS:
return GTK_TEXT_INPUT_CONTENT_PURPOSE_DIGITS;
return ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DIGITS;
case GTK_INPUT_PURPOSE_NUMBER:
return GTK_TEXT_INPUT_CONTENT_PURPOSE_NUMBER;
return ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NUMBER;
case GTK_INPUT_PURPOSE_PHONE:
return GTK_TEXT_INPUT_CONTENT_PURPOSE_PHONE;
return ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PHONE;
case GTK_INPUT_PURPOSE_URL:
return GTK_TEXT_INPUT_CONTENT_PURPOSE_URL;
return ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_URL;
case GTK_INPUT_PURPOSE_EMAIL:
return GTK_TEXT_INPUT_CONTENT_PURPOSE_EMAIL;
return ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_EMAIL;
case GTK_INPUT_PURPOSE_NAME:
return GTK_TEXT_INPUT_CONTENT_PURPOSE_NAME;
return ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NAME;
case GTK_INPUT_PURPOSE_PASSWORD:
return GTK_TEXT_INPUT_CONTENT_PURPOSE_PASSWORD;
return ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PASSWORD;
case GTK_INPUT_PURPOSE_PIN:
return GTK_TEXT_INPUT_CONTENT_PURPOSE_PIN;
return ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PIN;
}
return GTK_TEXT_INPUT_CONTENT_PURPOSE_NORMAL;
return ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL;
}
static void
......@@ -362,9 +462,9 @@ notify_content_type (GtkIMContextWayland *context)
"input-purpose", &purpose,
NULL);
gtk_text_input_set_content_type (global->text_input,
translate_hints (hints, purpose),
translate_purpose (purpose));
zwp_text_input_v3_set_content_type (global->text_input,
translate_hints (hints, purpose),
translate_purpose (purpose));
}
static void
......@@ -372,23 +472,15 @@ commit_state (GtkIMContextWayland *context)
{
if (global->current != GTK_IM_CONTEXT (context))
return;
gtk_text_input_commit (global->text_input);
context->serial++;
zwp_text_input_v3_commit (global->text_input);
context->surrounding_change = ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_INPUT_METHOD;
}
static void
enable_text_input (GtkIMContextWayland *context,
gboolean toggle_panel)
enable_text_input (GtkIMContextWayland *context)
{
guint flags = 0;
if (context->use_preedit)
flags |= GTK_TEXT_INPUT_ENABLE_FLAGS_CAN_SHOW_PREEDIT;
if (toggle_panel)
flags |= GTK_TEXT_INPUT_ENABLE_FLAGS_TOGGLE_INPUT_PANEL;
gtk_text_input_enable (global->text_input,
global->enter_serial,
flags);
zwp_text_input_v3_enable (global->text_input);
}
static void
......@@ -424,6 +516,7 @@ released_cb (GtkGestureMultiPress *gesture,
GtkIMContextWayland *context)
{
GtkInputHints hints;
gboolean result;
if (!global->current)
return;
......@@ -437,7 +530,9 @@ released_cb (GtkGestureMultiPress *gesture,
context->press_y,
x, y))
{
enable_text_input (GTK_IM_CONTEXT_WAYLAND (context), TRUE);
enable_text_input (GTK_IM_CONTEXT_WAYLAND (context));
g_signal_emit_by_name (global->current, "retrieve-surrounding", &result);
commit_state (context);
}
}
......@@ -491,7 +586,9 @@ gtk_im_context_wayland_get_preedit_string (GtkIMContext *context,
if (attrs)
*attrs = NULL;
GTK_IM_CONTEXT_CLASS (parent_class)->get_preedit_string (context, str, attrs, cursor_pos);
GTK_IM_CONTEXT_CLASS (parent_class)->get_preedit_string (context,
str, attrs,
cursor_pos);
/* If the parent implementation returns a len>0 string, go with it */
if (str && *str)
......@@ -503,12 +600,12 @@ gtk_im_context_wayland_get_preedit_string (GtkIMContext *context,
}
preedit_str =
context_wayland->preedit.text ? context_wayland->preedit.text : "";
context_wayland->current_preedit.text ? context_wayland->current_preedit.text : "";
if (str)
*str = g_strdup (preedit_str);
if (cursor_pos)
*cursor_pos = context_wayland->preedit.cursor_idx;
*cursor_pos = context_wayland->current_preedit.cursor_begin;
if (attrs)
{
......@@ -516,6 +613,15 @@ gtk_im_context_wayland_get_preedit_string (GtkIMContext *context,
*attrs = pango_attr_list_new ();
pango_attr_list_insert (*attrs,
pango_attr_underline_new (PANGO_UNDERLINE_SINGLE));
if (context_wayland->current_preedit.cursor_begin
!= context_wayland->current_preedit.cursor_end)
{
/* FIXME: Oh noes, how to highlight while taking into account user preferences? */
PangoAttribute *cursor = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
cursor->start_index = context_wayland->current_preedit.cursor_begin;
cursor->end_index = context_wayland->current_preedit.cursor_end;
pango_attr_list_insert (*attrs, cursor);
}
}
}
......@@ -531,6 +637,7 @@ static void
gtk_im_context_wayland_focus_in (GtkIMContext *context)
{
GtkIMContextWayland *context_wayland = GTK_IM_CONTEXT_WAYLAND (context);
gboolean result;
if (global->current == context)
return;
......@@ -538,9 +645,9 @@ gtk_im_context_wayland_focus_in (GtkIMContext *context)
return;
global->current = context;
enable_text_input (context_wayland, FALSE);
enable_text_input (context_wayland);
g_signal_emit_by_name (global->current, "retrieve-surrounding", &result);
notify_content_type (context_wayland);
notify_surrounding_text (context_wayland);
notify_cursor_location (context_wayland);
commit_state (context_wayland);
}
......@@ -548,17 +655,22 @@ gtk_im_context_wayland_focus_in (GtkIMContext *context)
static void
gtk_im_context_wayland_focus_out (GtkIMContext *context)
{
GtkIMContextWayland *context_wayland;
if (global->current != context)
return;
gtk_text_input_disable (global->text_input);
context_wayland = GTK_IM_CONTEXT_WAYLAND (context);
zwp_text_input_v3_disable (global->text_input);
commit_state (context_wayland);
global->current = NULL;
}
static void
gtk_im_context_wayland_reset (GtkIMContext *context)
{
reset_preedit (GTK_IM_CONTEXT_WAYLAND (context));
notify_external_change (GTK_IM_CONTEXT_WAYLAND (context));
GTK_IM_CONTEXT_CLASS (parent_class)->reset (context);
}
......@@ -598,9 +710,15 @@ gtk_im_context_wayland_set_surrounding (GtkIMContext *context,
g_free (context_wayland->surrounding.text);
context_wayland->surrounding.text = g_strdup (text);
context_wayland->surrounding.cursor_idx = cursor_index;
/* Anchor is not exposed via the set_surrounding interface, emulating. */
context_wayland->surrounding.anchor_idx = cursor_index;
notify_surrounding_text (context_wayland);
commit_state (context_wayland);
/* State changes coming from reset don't have any other opportunity to get
* committed. */
if (context_wayland->surrounding_change !=
ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_INPUT_METHOD)
commit_state (context_wayland);
}
static gboolean
......
/* GTK - The GIMP Toolkit
* Copyright (C) 2017 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <wayland-client-protocol.h>
#include <gtk/gtk.h>
#include "gtk/gtkintl.h"
#include "gtk/gtkimmodule.h"
#include "gdk/wayland/gdkwayland.h"
#include "gtk-text-input-client-protocol.h"
typedef struct _GtkIMContextWaylandGlobal GtkIMContextWaylandGlobal;
typedef struct _GtkIMContextWayland GtkIMContextWayland;
typedef struct _GtkIMContextWaylandClass GtkIMContextWaylandClass;
struct _GtkIMContextWaylandGlobal
{
struct wl_display *display;
struct wl_registry *registry;
uint32_t text_input_manager_wl_id;
struct gtk_text_input_manager *text_input_manager;
struct gtk_text_input *text_input;
uint32_t enter_serial;
GtkIMContext *current;
};
struct _GtkIMContextWaylandClass
{
GtkIMContextSimpleClass parent_class;
};
struct _GtkIMContextWayland
{
GtkIMContextSimple parent_instance;
GdkWindow *window;
GtkWidget *widget;
GtkGesture *gesture;
gdouble press_x;
gdouble press_y;
struct {
gchar *text;
gint cursor_idx;
} surrounding;
struct {
gchar *text;
gint cursor_idx;
} preedit;