Merge branch 'imwayland_enable' into 'gtk-3-24'
imwayland: Handle enter and leave events See merge request GNOME/gtk!369
This commit is contained in:
commit
f879741e89
@ -42,6 +42,10 @@ struct _GtkIMContextWaylandGlobal
|
||||
|
||||
GtkIMContext *current;
|
||||
|
||||
/* The input-method.enter event may happen before or after GTK focus-in,
|
||||
* so the context may not exist at the time. Same for leave and focus-out. */
|
||||
gboolean focused;
|
||||
|
||||
guint serial;
|
||||
};
|
||||
|
||||
@ -128,18 +132,6 @@ notify_external_change (GtkIMContextWayland *context)
|
||||
g_signal_emit_by_name (global->current, "retrieve-surrounding", &result);
|
||||
}
|
||||
|
||||
static void
|
||||
text_input_enter (void *data,
|
||||
struct zwp_text_input_v3 *text_input,
|
||||
struct wl_surface *surface)
|
||||
{}
|
||||
|
||||
static void
|
||||
text_input_leave (void *data,
|
||||
struct zwp_text_input_v3 *text_input,
|
||||
struct wl_surface *surface)
|
||||
{}
|
||||
|
||||
static void
|
||||
text_input_preedit (void *data,
|
||||
struct zwp_text_input_v3 *text_input,
|
||||
@ -274,71 +266,6 @@ text_input_done (void *data,
|
||||
text_input_preedit_apply(global);
|
||||
}
|
||||
|
||||
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_done,
|
||||
};
|
||||
|
||||
static void
|
||||
registry_handle_global (void *data,
|
||||
struct wl_registry *registry,
|
||||
uint32_t id,
|
||||
const char *interface,
|
||||
uint32_t version)
|
||||
{
|
||||
GtkIMContextWaylandGlobal *global = data;
|
||||
GdkSeat *seat = gdk_display_get_default_seat (gdk_display_get_default ());
|
||||
|
||||
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,
|
||||
&zwp_text_input_manager_v3_interface, 1);
|
||||
global->text_input =
|
||||
zwp_text_input_manager_v3_get_text_input (global->text_input_manager,
|
||||
gdk_wayland_seat_get_wl_seat (seat));
|
||||
global->serial = 0;
|
||||
zwp_text_input_v3_add_listener (global->text_input,
|
||||
&text_input_listener, global);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
registry_handle_global_remove (void *data,
|
||||
struct wl_registry *registry,
|
||||
uint32_t id)
|
||||
{
|
||||
GtkIMContextWaylandGlobal *global = data;
|
||||
|
||||
if (id != global->text_input_manager_wl_id)
|
||||
return;
|
||||
|
||||
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 = {
|
||||
registry_handle_global,
|
||||
registry_handle_global_remove
|
||||
};
|
||||
|
||||
static void
|
||||
gtk_im_context_wayland_global_init (GdkDisplay *display)
|
||||
{
|
||||
g_return_if_fail (global == NULL);
|
||||
|
||||
global = g_new0 (GtkIMContextWaylandGlobal, 1);
|
||||
global->display = gdk_wayland_display_get_wl_display (display);
|
||||
global->registry = wl_display_get_registry (global->display);
|
||||
|
||||
wl_registry_add_listener (global->registry, ®istry_listener, global);
|
||||
}
|
||||
|
||||
static void
|
||||
notify_surrounding_text (GtkIMContextWayland *context)
|
||||
{
|
||||
@ -466,12 +393,6 @@ commit_state (GtkIMContextWayland *context)
|
||||
context->surrounding_change = ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_INPUT_METHOD;
|
||||
}
|
||||
|
||||
static void
|
||||
enable_text_input (GtkIMContextWayland *context)
|
||||
{
|
||||
zwp_text_input_v3_enable (global->text_input);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_im_context_wayland_finalize (GObject *object)
|
||||
{
|
||||
@ -516,14 +437,15 @@ released_cb (GtkGestureMultiPress *gesture,
|
||||
|
||||
g_object_get (context, "input-hints", &hints, NULL);
|
||||
|
||||
if (n_press == 1 &&
|
||||
if (global->focused &&
|
||||
n_press == 1 &&
|
||||
(hints & GTK_INPUT_HINT_INHIBIT_OSK) == 0 &&
|
||||
!gtk_drag_check_threshold (context->widget,
|
||||
context->press_x,
|
||||
context->press_y,
|
||||
x, y))
|
||||
{
|
||||
enable_text_input (GTK_IM_CONTEXT_WAYLAND (context));
|
||||
zwp_text_input_v3_enable (global->text_input);
|
||||
g_signal_emit_by_name (global->current, "retrieve-surrounding", &result);
|
||||
commit_state (context);
|
||||
}
|
||||
@ -627,18 +549,10 @@ gtk_im_context_wayland_filter_keypress (GtkIMContext *context,
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_im_context_wayland_focus_in (GtkIMContext *context)
|
||||
enable (GtkIMContextWayland *context_wayland)
|
||||
{
|
||||
GtkIMContextWayland *context_wayland = GTK_IM_CONTEXT_WAYLAND (context);
|
||||
gboolean result;
|
||||
|
||||
if (global->current == context)
|
||||
return;
|
||||
if (!global->text_input)
|
||||
return;
|
||||
|
||||
global->current = context;
|
||||
enable_text_input (context_wayland);
|
||||
zwp_text_input_v3_enable (global->text_input);
|
||||
g_signal_emit_by_name (global->current, "retrieve-surrounding", &result);
|
||||
notify_content_type (context_wayland);
|
||||
notify_cursor_location (context_wayland);
|
||||
@ -646,15 +560,8 @@ gtk_im_context_wayland_focus_in (GtkIMContext *context)
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_im_context_wayland_focus_out (GtkIMContext *context)
|
||||
disable (GtkIMContextWayland *context_wayland)
|
||||
{
|
||||
GtkIMContextWayland *context_wayland;
|
||||
|
||||
if (global->current != context)
|
||||
return;
|
||||
|
||||
context_wayland = GTK_IM_CONTEXT_WAYLAND (context);
|
||||
|
||||
zwp_text_input_v3_disable (global->text_input);
|
||||
commit_state (context_wayland);
|
||||
|
||||
@ -664,6 +571,122 @@ gtk_im_context_wayland_focus_out (GtkIMContext *context)
|
||||
text_input_preedit (global, global->text_input, NULL, 0, 0);
|
||||
text_input_preedit_apply (global);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
text_input_enter (void *data,
|
||||
struct zwp_text_input_v3 *text_input,
|
||||
struct wl_surface *surface)
|
||||
{
|
||||
global->focused = TRUE;
|
||||
|
||||
if (global->current)
|
||||
enable (GTK_IM_CONTEXT_WAYLAND (global->current));
|
||||
}
|
||||
|
||||
static void
|
||||
text_input_leave (void *data,
|
||||
struct zwp_text_input_v3 *text_input,
|
||||
struct wl_surface *surface)
|
||||
{
|
||||
global->focused = FALSE;
|
||||
|
||||
if (global->current)
|
||||
disable (GTK_IM_CONTEXT_WAYLAND (global->current));
|
||||
}
|
||||
|
||||
|
||||
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_done,
|
||||
};
|
||||
|
||||
static void
|
||||
registry_handle_global (void *data,
|
||||
struct wl_registry *registry,
|
||||
uint32_t id,
|
||||
const char *interface,
|
||||
uint32_t version)
|
||||
{
|
||||
GtkIMContextWaylandGlobal *global = data;
|
||||
GdkSeat *seat = gdk_display_get_default_seat (gdk_display_get_default ());
|
||||
|
||||
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,
|
||||
&zwp_text_input_manager_v3_interface, 1);
|
||||
global->text_input =
|
||||
zwp_text_input_manager_v3_get_text_input (global->text_input_manager,
|
||||
gdk_wayland_seat_get_wl_seat (seat));
|
||||
global->serial = 0;
|
||||
zwp_text_input_v3_add_listener (global->text_input,
|
||||
&text_input_listener, global);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
registry_handle_global_remove (void *data,
|
||||
struct wl_registry *registry,
|
||||
uint32_t id)
|
||||
{
|
||||
GtkIMContextWaylandGlobal *global = data;
|
||||
|
||||
if (id != global->text_input_manager_wl_id)
|
||||
return;
|
||||
|
||||
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 = {
|
||||
registry_handle_global,
|
||||
registry_handle_global_remove
|
||||
};
|
||||
|
||||
static void
|
||||
gtk_im_context_wayland_global_init (GdkDisplay *display)
|
||||
{
|
||||
g_return_if_fail (global == NULL);
|
||||
|
||||
global = g_new0 (GtkIMContextWaylandGlobal, 1);
|
||||
global->display = gdk_wayland_display_get_wl_display (display);
|
||||
global->registry = wl_display_get_registry (global->display);
|
||||
|
||||
wl_registry_add_listener (global->registry, ®istry_listener, global);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_im_context_wayland_focus_in (GtkIMContext *context)
|
||||
{
|
||||
GtkIMContextWayland *context_wayland = GTK_IM_CONTEXT_WAYLAND (context);
|
||||
|
||||
if (global->current == context)
|
||||
return;
|
||||
if (!global->text_input)
|
||||
return;
|
||||
|
||||
global->current = context;
|
||||
|
||||
if (global->focused)
|
||||
enable (context_wayland);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_im_context_wayland_focus_out (GtkIMContext *context)
|
||||
{
|
||||
GtkIMContextWayland *context_wayland = GTK_IM_CONTEXT_WAYLAND (context);
|
||||
|
||||
if (global->current != context)
|
||||
return;
|
||||
|
||||
if (global->focused)
|
||||
disable (context_wayland);
|
||||
|
||||
global->current = NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user