Compare commits
11 Commits
3.32.0
...
wip/carlos
Author | SHA1 | Date | |
---|---|---|---|
9a13882a95 | |||
4f6a3cd874 | |||
59e89f0d63 | |||
8ec46e8021 | |||
92ce68d257 | |||
ff79e651f0 | |||
0f9b388526 | |||
d7cb3da324 | |||
ca654ac544 | |||
6e3b0eb430 | |||
3483cc8831 |
@ -87,6 +87,8 @@ source_h = \
|
||||
clutter-image.h \
|
||||
clutter-input-device.h \
|
||||
clutter-input-device-tool.h \
|
||||
clutter-input-focus.h \
|
||||
clutter-input-method.h \
|
||||
clutter-interval.h \
|
||||
clutter-keyframe-transition.h \
|
||||
clutter-keysyms.h \
|
||||
@ -169,6 +171,8 @@ source_c = \
|
||||
clutter-image.c \
|
||||
clutter-input-device.c \
|
||||
clutter-input-device-tool.c \
|
||||
clutter-input-focus.c \
|
||||
clutter-input-method.c \
|
||||
clutter-virtual-input-device.c \
|
||||
clutter-interval.c \
|
||||
clutter-keyframe-transition.c \
|
||||
|
@ -58,6 +58,8 @@ struct _ClutterBackend
|
||||
gint32 units_serial;
|
||||
|
||||
GList *event_translators;
|
||||
|
||||
ClutterInputMethod *input_method;
|
||||
};
|
||||
|
||||
struct _ClutterBackendClass
|
||||
|
@ -127,6 +127,7 @@ clutter_backend_finalize (GObject *gobject)
|
||||
|
||||
g_free (backend->font_name);
|
||||
clutter_backend_set_font_options (backend, NULL);
|
||||
g_clear_object (&backend->input_method);
|
||||
|
||||
G_OBJECT_CLASS (clutter_backend_parent_class)->finalize (gobject);
|
||||
}
|
||||
@ -1373,3 +1374,31 @@ clutter_backend_bell_notify (ClutterBackend *backend)
|
||||
if (klass->bell_notify)
|
||||
klass->bell_notify (backend);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_backend_get_input_method:
|
||||
* @backend: the #CLutterBackend
|
||||
*
|
||||
* Returns the input method used by Clutter
|
||||
*
|
||||
* Returns: (transfer none): the input method
|
||||
**/
|
||||
ClutterInputMethod *
|
||||
clutter_backend_get_input_method (ClutterBackend *backend)
|
||||
{
|
||||
return backend->input_method;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_backend_set_input_method:
|
||||
* @backend: the #ClutterBackend
|
||||
* @method: the input method
|
||||
*
|
||||
* Sets the input method to be used by Clutter
|
||||
**/
|
||||
void
|
||||
clutter_backend_set_input_method (ClutterBackend *backend,
|
||||
ClutterInputMethod *method)
|
||||
{
|
||||
g_set_object (&backend->input_method, method);
|
||||
}
|
||||
|
@ -77,6 +77,12 @@ CoglContext * clutter_backend_get_cogl_context (Clutter
|
||||
CLUTTER_AVAILABLE_IN_ALL
|
||||
void clutter_backend_bell_notify (ClutterBackend *backend);
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
ClutterInputMethod * clutter_backend_get_input_method (ClutterBackend *backend);
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_backend_set_input_method (ClutterBackend *backend,
|
||||
ClutterInputMethod *method);
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_BACKEND_H__ */
|
||||
|
@ -767,8 +767,9 @@ typedef enum { /*< prefix=CLUTTER_DRAG >*/
|
||||
* Since: 0.6
|
||||
*/
|
||||
typedef enum { /*< flags prefix=CLUTTER_EVENT >*/
|
||||
CLUTTER_EVENT_NONE = 0,
|
||||
CLUTTER_EVENT_FLAG_SYNTHETIC = 1 << 0
|
||||
CLUTTER_EVENT_NONE = 0,
|
||||
CLUTTER_EVENT_FLAG_SYNTHETIC = 1 << 0,
|
||||
CLUTTER_EVENT_FLAG_INPUT_METHOD = 1 << 1
|
||||
} ClutterEventFlags;
|
||||
|
||||
/**
|
||||
@ -1573,6 +1574,41 @@ typedef enum {
|
||||
CLUTTER_INPUT_DEVICE_MAPPING_RELATIVE,
|
||||
} ClutterInputDeviceMapping;
|
||||
|
||||
typedef enum {
|
||||
CLUTTER_INPUT_CONTENT_HINT_COMPLETION = 1 << 0,
|
||||
CLUTTER_INPUT_CONTENT_HINT_SPELLCHECK = 1 << 1,
|
||||
CLUTTER_INPUT_CONTENT_HINT_AUTO_CAPITALIZATION = 1 << 2,
|
||||
CLUTTER_INPUT_CONTENT_HINT_LOWERCASE = 1 << 3,
|
||||
CLUTTER_INPUT_CONTENT_HINT_UPPERCASE = 1 << 4,
|
||||
CLUTTER_INPUT_CONTENT_HINT_TITLECASE = 1 << 5,
|
||||
CLUTTER_INPUT_CONTENT_HINT_HIDDEN_TEXT = 1 << 6,
|
||||
CLUTTER_INPUT_CONTENT_HINT_SENSITIVE_DATA = 1 << 7,
|
||||
CLUTTER_INPUT_CONTENT_HINT_LATIN = 1 << 8,
|
||||
CLUTTER_INPUT_CONTENT_HINT_MULTILINE = 1 << 9,
|
||||
} ClutterInputContentHintFlags;
|
||||
|
||||
typedef enum {
|
||||
CLUTTER_INPUT_CONTENT_PURPOSE_NORMAL,
|
||||
CLUTTER_INPUT_CONTENT_PURPOSE_ALPHA,
|
||||
CLUTTER_INPUT_CONTENT_PURPOSE_DIGITS,
|
||||
CLUTTER_INPUT_CONTENT_PURPOSE_NUMBER,
|
||||
CLUTTER_INPUT_CONTENT_PURPOSE_PHONE,
|
||||
CLUTTER_INPUT_CONTENT_PURPOSE_URL,
|
||||
CLUTTER_INPUT_CONTENT_PURPOSE_EMAIL,
|
||||
CLUTTER_INPUT_CONTENT_PURPOSE_NAME,
|
||||
CLUTTER_INPUT_CONTENT_PURPOSE_PASSWORD,
|
||||
CLUTTER_INPUT_CONTENT_PURPOSE_DATE,
|
||||
CLUTTER_INPUT_CONTENT_PURPOSE_TIME,
|
||||
CLUTTER_INPUT_CONTENT_PURPOSE_DATETIME,
|
||||
CLUTTER_INPUT_CONTENT_PURPOSE_TERMINAL,
|
||||
} ClutterInputContentPurpose;
|
||||
|
||||
typedef enum {
|
||||
CLUTTER_INPUT_PANEL_STATE_OFF,
|
||||
CLUTTER_INPUT_PANEL_STATE_ON,
|
||||
CLUTTER_INPUT_PANEL_STATE_TOGGLE,
|
||||
} ClutterInputPanelState;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_ENUMS_H__ */
|
||||
|
229
clutter/clutter/clutter-input-focus.c
Normal file
229
clutter/clutter/clutter-input-focus.c
Normal file
@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Red Hat
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Author: Carlos Garnacho <carlosg@gnome.org>
|
||||
*/
|
||||
|
||||
#include "clutter-build-config.h"
|
||||
|
||||
#include "clutter/clutter-input-focus.h"
|
||||
|
||||
enum {
|
||||
FOCUS_IN,
|
||||
FOCUS_OUT,
|
||||
COMMIT,
|
||||
DELETE_SURROUNDING,
|
||||
REQUEST_SURROUNDING,
|
||||
SET_PREEDIT_TEXT,
|
||||
N_SIGNALS,
|
||||
};
|
||||
|
||||
static guint signals[N_SIGNALS] = { 0 };
|
||||
|
||||
G_DEFINE_INTERFACE (ClutterInputFocus, clutter_input_focus, G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
clutter_input_focus_default_init (ClutterInputFocusInterface *iface)
|
||||
{
|
||||
signals[FOCUS_IN] =
|
||||
g_signal_new ("focus-in",
|
||||
CLUTTER_TYPE_INPUT_FOCUS,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ClutterInputFocusInterface, focus_in),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1, CLUTTER_TYPE_INPUT_METHOD);
|
||||
signals[FOCUS_OUT] =
|
||||
g_signal_new ("focus-out",
|
||||
CLUTTER_TYPE_INPUT_FOCUS,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ClutterInputFocusInterface, focus_out),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
signals[COMMIT] =
|
||||
g_signal_new ("commit",
|
||||
CLUTTER_TYPE_INPUT_FOCUS,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ClutterInputFocusInterface, commit_text),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1, G_TYPE_STRING);
|
||||
signals[DELETE_SURROUNDING] =
|
||||
g_signal_new ("delete-surrounding",
|
||||
CLUTTER_TYPE_INPUT_FOCUS,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ClutterInputFocusInterface, delete_surrounding),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
|
||||
signals[REQUEST_SURROUNDING] =
|
||||
g_signal_new ("request-surrounding",
|
||||
CLUTTER_TYPE_INPUT_FOCUS,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ClutterInputFocusInterface, request_surrounding),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
signals[SET_PREEDIT_TEXT] =
|
||||
g_signal_new ("set-preedit-text",
|
||||
CLUTTER_TYPE_INPUT_FOCUS,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ClutterInputFocusInterface, set_preedit_text),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_UINT);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_focus_reset (ClutterInputFocus *focus)
|
||||
{
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
ClutterInputMethod *method = clutter_backend_get_input_method (backend);
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (method));
|
||||
|
||||
if (clutter_input_method_get_focus (method) != focus)
|
||||
return;
|
||||
|
||||
CLUTTER_INPUT_METHOD_GET_CLASS (method)->reset (method);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_focus_set_cursor_location (ClutterInputFocus *focus,
|
||||
const ClutterRect *rect)
|
||||
{
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
ClutterInputMethod *method = clutter_backend_get_input_method (backend);
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (method));
|
||||
|
||||
if (clutter_input_method_get_focus (method) != focus)
|
||||
return;
|
||||
|
||||
CLUTTER_INPUT_METHOD_GET_CLASS (method)->set_cursor_location (method, rect);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_focus_set_surrounding (ClutterInputFocus *focus,
|
||||
const gchar *text,
|
||||
guint cursor,
|
||||
guint anchor)
|
||||
{
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
ClutterInputMethod *method = clutter_backend_get_input_method (backend);
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (method));
|
||||
|
||||
if (clutter_input_method_get_focus (method) != focus)
|
||||
return;
|
||||
|
||||
CLUTTER_INPUT_METHOD_GET_CLASS (method)->set_surrounding (method, text, cursor, anchor);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_focus_set_content_hints (ClutterInputFocus *focus,
|
||||
ClutterInputContentHintFlags hints)
|
||||
{
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
ClutterInputMethod *method = clutter_backend_get_input_method (backend);
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (method));
|
||||
|
||||
if (clutter_input_method_get_focus (method) != focus)
|
||||
return;
|
||||
|
||||
g_object_set (G_OBJECT (method), "content-hints", hints, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_focus_set_content_purpose (ClutterInputFocus *focus,
|
||||
ClutterInputContentPurpose purpose)
|
||||
{
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
ClutterInputMethod *method = clutter_backend_get_input_method (backend);
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (method));
|
||||
|
||||
if (clutter_input_method_get_focus (method) != focus)
|
||||
return;
|
||||
|
||||
g_object_set (G_OBJECT (method), "content-purpose", purpose, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_focus_focus_in (ClutterInputFocus *focus)
|
||||
{
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
ClutterInputMethod *method = clutter_backend_get_input_method (backend);
|
||||
|
||||
clutter_input_method_focus_in (method, focus);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_focus_focus_out (ClutterInputFocus *focus)
|
||||
{
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
ClutterInputMethod *method = clutter_backend_get_input_method (backend);
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (method));
|
||||
|
||||
if (clutter_input_method_get_focus (method) == focus)
|
||||
clutter_input_method_focus_out (method);
|
||||
}
|
||||
|
||||
gboolean
|
||||
clutter_input_focus_filter_key_event (ClutterInputFocus *focus,
|
||||
const ClutterKeyEvent *key)
|
||||
{
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
ClutterInputMethod *method = clutter_backend_get_input_method (backend);
|
||||
|
||||
g_return_val_if_fail (CLUTTER_IS_INPUT_METHOD (method), FALSE);
|
||||
|
||||
if (clutter_event_get_flags ((ClutterEvent *) key) & CLUTTER_EVENT_FLAG_INPUT_METHOD)
|
||||
return FALSE;
|
||||
|
||||
if (clutter_input_method_get_focus (method) == focus)
|
||||
{
|
||||
ClutterInputMethodClass *im_class = CLUTTER_INPUT_METHOD_GET_CLASS (method);
|
||||
|
||||
if (im_class->filter_key_event)
|
||||
return im_class->filter_key_event (method, (const ClutterEvent *) key);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_focus_set_can_show_preedit (ClutterInputFocus *focus,
|
||||
gboolean can_show_preedit)
|
||||
{
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
ClutterInputMethod *method = clutter_backend_get_input_method (backend);
|
||||
|
||||
if (clutter_input_method_get_focus (method) == focus)
|
||||
g_object_set (G_OBJECT (method), "can-show-preedit", can_show_preedit, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_focus_request_toggle_input_panel (ClutterInputFocus *focus)
|
||||
{
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
ClutterInputMethod *method = clutter_backend_get_input_method (backend);
|
||||
|
||||
if (clutter_input_method_get_focus (method) == focus)
|
||||
{
|
||||
g_signal_emit_by_name (method, "input-panel-state",
|
||||
CLUTTER_INPUT_PANEL_STATE_TOGGLE);
|
||||
}
|
||||
}
|
86
clutter/clutter/clutter-input-focus.h
Normal file
86
clutter/clutter/clutter-input-focus.h
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Red Hat
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Author: Carlos Garnacho <carlosg@gnome.org>
|
||||
*/
|
||||
|
||||
#ifndef __CLUTTER_INPUT_FOCUS_H__
|
||||
#define __CLUTTER_INPUT_FOCUS_H__
|
||||
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#define CLUTTER_TYPE_INPUT_FOCUS (clutter_input_focus_get_type ())
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
G_DECLARE_INTERFACE (ClutterInputFocus, clutter_input_focus,
|
||||
CLUTTER, INPUT_FOCUS, GObject)
|
||||
|
||||
typedef struct _ClutterInputFocusInterface ClutterInputFocusInterface;
|
||||
|
||||
struct _ClutterInputFocusInterface
|
||||
{
|
||||
GTypeInterface iface;
|
||||
|
||||
void (* focus_in) (ClutterInputFocus *focus,
|
||||
ClutterInputMethod *input_method);
|
||||
void (* focus_out) (ClutterInputFocus *focus);
|
||||
|
||||
void (* request_surrounding) (ClutterInputFocus *focus);
|
||||
void (* delete_surrounding) (ClutterInputFocus *focus,
|
||||
guint offset,
|
||||
guint len);
|
||||
void (* commit_text) (ClutterInputFocus *focus,
|
||||
const gchar *text);
|
||||
|
||||
void (* set_preedit_text) (ClutterInputFocus *focus,
|
||||
const gchar *preedit,
|
||||
guint cursor);
|
||||
};
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_focus_focus_in (ClutterInputFocus *focus);
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_focus_focus_out (ClutterInputFocus *focus);
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_focus_reset (ClutterInputFocus *focus);
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_focus_set_cursor_location (ClutterInputFocus *focus,
|
||||
const ClutterRect *rect);
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_focus_set_surrounding (ClutterInputFocus *focus,
|
||||
const gchar *text,
|
||||
guint cursor,
|
||||
guint anchor);
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_focus_set_content_hints (ClutterInputFocus *focus,
|
||||
ClutterInputContentHintFlags hint);
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_focus_set_content_purpose (ClutterInputFocus *focus,
|
||||
ClutterInputContentPurpose purpose);
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
gboolean clutter_input_focus_filter_key_event (ClutterInputFocus *focus,
|
||||
const ClutterKeyEvent *key);
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_focus_set_can_show_preedit (ClutterInputFocus *focus,
|
||||
gboolean can_show_preedit);
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_focus_request_toggle_input_panel (ClutterInputFocus *focus);
|
||||
|
||||
#endif /* __CLUTTER_INPUT_FOCUS_H__ */
|
359
clutter/clutter/clutter-input-method.c
Normal file
359
clutter/clutter/clutter-input-method.c
Normal file
@ -0,0 +1,359 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Red Hat
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Author: Carlos Garnacho <carlosg@gnome.org>
|
||||
*/
|
||||
|
||||
#include "clutter-build-config.h"
|
||||
|
||||
#include "clutter-private.h"
|
||||
#include "clutter/clutter-input-method.h"
|
||||
|
||||
typedef struct _ClutterInputMethodPrivate ClutterInputMethodPrivate;
|
||||
|
||||
struct _ClutterInputMethodPrivate
|
||||
{
|
||||
ClutterInputFocus *focus;
|
||||
ClutterInputContentHintFlags content_hints;
|
||||
ClutterInputContentPurpose content_purpose;
|
||||
gboolean can_show_preedit;
|
||||
};
|
||||
|
||||
enum {
|
||||
COMMIT,
|
||||
DELETE_SURROUNDING,
|
||||
REQUEST_SURROUNDING,
|
||||
INPUT_PANEL_STATE,
|
||||
N_SIGNALS,
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_CONTENT_HINTS,
|
||||
PROP_CONTENT_PURPOSE,
|
||||
PROP_CAN_SHOW_PREEDIT,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
static guint signals[N_SIGNALS] = { 0 };
|
||||
static GParamSpec *pspecs[N_PROPS] = { 0 };
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ClutterInputMethod, clutter_input_method, G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
set_content_hints (ClutterInputMethod *method,
|
||||
ClutterInputContentHintFlags content_hints)
|
||||
{
|
||||
ClutterInputMethodPrivate *priv;
|
||||
|
||||
priv = clutter_input_method_get_instance_private (method);
|
||||
priv->content_hints = content_hints;
|
||||
CLUTTER_INPUT_METHOD_GET_CLASS (method)->update_content_hints (method,
|
||||
content_hints);
|
||||
}
|
||||
|
||||
static void
|
||||
set_content_purpose (ClutterInputMethod *method,
|
||||
ClutterInputContentPurpose content_purpose)
|
||||
{
|
||||
ClutterInputMethodPrivate *priv;
|
||||
|
||||
priv = clutter_input_method_get_instance_private (method);
|
||||
priv->content_purpose = content_purpose;
|
||||
CLUTTER_INPUT_METHOD_GET_CLASS (method)->update_content_purpose (method,
|
||||
content_purpose);
|
||||
}
|
||||
|
||||
static void
|
||||
set_can_show_preedit (ClutterInputMethod *method,
|
||||
gboolean can_show_preedit)
|
||||
{
|
||||
ClutterInputMethodPrivate *priv;
|
||||
|
||||
priv = clutter_input_method_get_instance_private (method);
|
||||
priv->can_show_preedit = can_show_preedit;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_input_method_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONTENT_HINTS:
|
||||
set_content_hints (CLUTTER_INPUT_METHOD (object),
|
||||
g_value_get_flags (value));
|
||||
break;
|
||||
case PROP_CONTENT_PURPOSE:
|
||||
set_content_purpose (CLUTTER_INPUT_METHOD (object),
|
||||
g_value_get_enum (value));
|
||||
break;
|
||||
case PROP_CAN_SHOW_PREEDIT:
|
||||
set_can_show_preedit (CLUTTER_INPUT_METHOD (object),
|
||||
g_value_get_boolean (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_input_method_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ClutterInputMethodPrivate *priv;
|
||||
ClutterInputMethod *method;
|
||||
|
||||
method = CLUTTER_INPUT_METHOD (object);
|
||||
priv = clutter_input_method_get_instance_private (method);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONTENT_HINTS:
|
||||
g_value_set_flags (value, priv->content_hints);
|
||||
break;
|
||||
case PROP_CONTENT_PURPOSE:
|
||||
g_value_set_enum (value, priv->content_purpose);
|
||||
break;
|
||||
case PROP_CAN_SHOW_PREEDIT:
|
||||
g_value_set_boolean (value, priv->can_show_preedit);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_input_method_class_init (ClutterInputMethodClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->set_property = clutter_input_method_set_property;
|
||||
object_class->get_property = clutter_input_method_get_property;
|
||||
|
||||
signals[COMMIT] =
|
||||
g_signal_new ("commit",
|
||||
G_TYPE_FROM_CLASS (object_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0, NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1, G_TYPE_STRING);
|
||||
signals[DELETE_SURROUNDING] =
|
||||
g_signal_new ("delete-surrounding",
|
||||
G_TYPE_FROM_CLASS (object_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0, NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
|
||||
signals[REQUEST_SURROUNDING] =
|
||||
g_signal_new ("request-surrounding",
|
||||
G_TYPE_FROM_CLASS (object_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0, NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
signals[INPUT_PANEL_STATE] =
|
||||
g_signal_new ("input-panel-state",
|
||||
G_TYPE_FROM_CLASS (object_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0, NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
CLUTTER_TYPE_INPUT_PANEL_STATE);
|
||||
|
||||
pspecs[PROP_CONTENT_HINTS] =
|
||||
g_param_spec_flags ("content-hints",
|
||||
P_("Content hints"),
|
||||
P_("Content hints"),
|
||||
CLUTTER_TYPE_INPUT_CONTENT_HINT_FLAGS, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
pspecs[PROP_CONTENT_PURPOSE] =
|
||||
g_param_spec_enum ("content-purpose",
|
||||
P_("Content purpose"),
|
||||
P_("Content purpose"),
|
||||
CLUTTER_TYPE_INPUT_CONTENT_PURPOSE, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
pspecs[PROP_CAN_SHOW_PREEDIT] =
|
||||
g_param_spec_boolean ("can-show-preedit",
|
||||
P_("Can show preedit"),
|
||||
P_("Can show preedit"),
|
||||
FALSE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, pspecs);
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_input_method_init (ClutterInputMethod *method)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_method_focus_in (ClutterInputMethod *method,
|
||||
ClutterInputFocus *focus)
|
||||
{
|
||||
ClutterInputMethodPrivate *priv;
|
||||
ClutterInputMethodClass *klass;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (method));
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_FOCUS (focus));
|
||||
|
||||
priv = clutter_input_method_get_instance_private (method);
|
||||
|
||||
if (priv->focus == focus)
|
||||
return;
|
||||
|
||||
if (priv->focus)
|
||||
clutter_input_method_focus_out (method);
|
||||
|
||||
g_set_object (&priv->focus, focus);
|
||||
|
||||
if (focus)
|
||||
{
|
||||
klass = CLUTTER_INPUT_METHOD_GET_CLASS (method);
|
||||
klass->focus_in (method, focus);
|
||||
|
||||
g_signal_emit_by_name (priv->focus, "focus-in", method);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_method_focus_out (ClutterInputMethod *method)
|
||||
{
|
||||
ClutterInputMethodPrivate *priv;
|
||||
ClutterInputMethodClass *klass;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (method));
|
||||
|
||||
priv = clutter_input_method_get_instance_private (method);
|
||||
|
||||
if (!priv->focus)
|
||||
return;
|
||||
|
||||
g_signal_emit_by_name (priv->focus, "focus-out");
|
||||
g_clear_object (&priv->focus);
|
||||
|
||||
klass = CLUTTER_INPUT_METHOD_GET_CLASS (method);
|
||||
klass->focus_out (method);
|
||||
|
||||
g_signal_emit (method, signals[INPUT_PANEL_STATE],
|
||||
0, CLUTTER_INPUT_PANEL_STATE_OFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_input_method_get_focus:
|
||||
* @method: the #ClutterInputMethod
|
||||
*
|
||||
* Retrieves the current focus of the input method, or %NULL
|
||||
* if there is none.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): the current focus
|
||||
**/
|
||||
ClutterInputFocus *
|
||||
clutter_input_method_get_focus (ClutterInputMethod *method)
|
||||
{
|
||||
ClutterInputMethodPrivate *priv;
|
||||
|
||||
priv = clutter_input_method_get_instance_private (method);
|
||||
return priv->focus;
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_method_commit (ClutterInputMethod *method,
|
||||
const gchar *text)
|
||||
{
|
||||
ClutterInputMethodPrivate *priv;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (method));
|
||||
|
||||
priv = clutter_input_method_get_instance_private (method);
|
||||
if (priv->focus)
|
||||
g_signal_emit_by_name (priv->focus, "commit", text);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_method_delete_surrounding (ClutterInputMethod *method,
|
||||
guint offset,
|
||||
guint len)
|
||||
{
|
||||
ClutterInputMethodPrivate *priv;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (method));
|
||||
|
||||
priv = clutter_input_method_get_instance_private (method);
|
||||
if (priv->focus)
|
||||
g_signal_emit_by_name (priv->focus, "delete-surrounding", offset, len);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_method_request_surrounding (ClutterInputMethod *method)
|
||||
{
|
||||
ClutterInputMethodPrivate *priv;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (method));
|
||||
|
||||
priv = clutter_input_method_get_instance_private (method);
|
||||
if (priv->focus)
|
||||
g_signal_emit_by_name (priv->focus, "request-surrounding");
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_input_method_set_preedit_text:
|
||||
* @method: a #ClutterInputMethod
|
||||
* @preedit: (nullable): the preedit text, or %NULL
|
||||
*
|
||||
* Sets the preedit text on the current input focus.
|
||||
**/
|
||||
void
|
||||
clutter_input_method_set_preedit_text (ClutterInputMethod *method,
|
||||
const gchar *preedit,
|
||||
guint cursor)
|
||||
{
|
||||
ClutterInputMethodPrivate *priv;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_METHOD (method));
|
||||
|
||||
priv = clutter_input_method_get_instance_private (method);
|
||||
if (priv->focus)
|
||||
g_signal_emit_by_name (priv->focus, "set-preedit-text", preedit, cursor);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_input_method_notify_key_event (ClutterInputMethod *method,
|
||||
const ClutterEvent *event,
|
||||
gboolean filtered)
|
||||
{
|
||||
if (!filtered)
|
||||
{
|
||||
ClutterEvent *copy;
|
||||
|
||||
/* XXX: we rely on the IM implementation to notify back of
|
||||
* key events in the exact same order they were given.
|
||||
*/
|
||||
copy = clutter_event_copy (event);
|
||||
clutter_event_set_flags (copy, clutter_event_get_flags (event) |
|
||||
CLUTTER_EVENT_FLAG_INPUT_METHOD);
|
||||
clutter_event_put (copy);
|
||||
clutter_event_free (copy);
|
||||
}
|
||||
}
|
89
clutter/clutter/clutter-input-method.h
Normal file
89
clutter/clutter/clutter-input-method.h
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Red Hat
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Author: Carlos Garnacho <carlosg@gnome.org>
|
||||
*/
|
||||
|
||||
#ifndef __CLUTTER_INPUT_METHOD_H__
|
||||
#define __CLUTTER_INPUT_METHOD_H__
|
||||
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#define CLUTTER_TYPE_INPUT_METHOD (clutter_input_method_get_type ())
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
G_DECLARE_DERIVABLE_TYPE (ClutterInputMethod, clutter_input_method,
|
||||
CLUTTER, INPUT_METHOD, GObject)
|
||||
|
||||
typedef struct _ClutterInputMethodClass ClutterInputMethodClass;
|
||||
|
||||
struct _ClutterInputMethodClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
void (* focus_in) (ClutterInputMethod *method,
|
||||
ClutterInputFocus *actor);
|
||||
void (* focus_out) (ClutterInputMethod *method);
|
||||
|
||||
void (* reset) (ClutterInputMethod *method);
|
||||
|
||||
void (* set_cursor_location) (ClutterInputMethod *method,
|
||||
const ClutterRect *rect);
|
||||
void (* set_surrounding) (ClutterInputMethod *method,
|
||||
const gchar *text,
|
||||
guint cursor,
|
||||
guint anchor);
|
||||
void (* update_content_hints) (ClutterInputMethod *method,
|
||||
ClutterInputContentHintFlags hint);
|
||||
void (* update_content_purpose) (ClutterInputMethod *method,
|
||||
ClutterInputContentPurpose purpose);
|
||||
|
||||
gboolean (* filter_key_event) (ClutterInputMethod *method,
|
||||
const ClutterEvent *key);
|
||||
};
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_method_focus_in (ClutterInputMethod *method,
|
||||
ClutterInputFocus *focus);
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_method_focus_out (ClutterInputMethod *method);
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
ClutterInputFocus * clutter_input_method_get_focus (ClutterInputMethod *method);
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_method_commit (ClutterInputMethod *method,
|
||||
const gchar *text);
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_method_delete_surrounding (ClutterInputMethod *method,
|
||||
guint offset,
|
||||
guint len);
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_method_request_surrounding (ClutterInputMethod *method);
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_method_set_preedit_text (ClutterInputMethod *method,
|
||||
const gchar *preedit,
|
||||
guint cursor);
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_input_method_notify_key_event (ClutterInputMethod *method,
|
||||
const ClutterEvent *event,
|
||||
gboolean filtered);
|
||||
|
||||
#endif /* __CLUTTER_INPUT_METHOD_H__ */
|
@ -63,6 +63,7 @@
|
||||
#include "clutter-units.h"
|
||||
#include "clutter-paint-volume-private.h"
|
||||
#include "clutter-scriptable.h"
|
||||
#include "clutter-input-focus.h"
|
||||
|
||||
/* cursor width in pixels */
|
||||
#define DEFAULT_CURSOR_SIZE 2
|
||||
@ -176,6 +177,9 @@ struct _ClutterTextPrivate
|
||||
/* Signal handler for when the :text-direction changes */
|
||||
guint direction_changed_id;
|
||||
|
||||
ClutterInputContentHintFlags input_hints;
|
||||
ClutterInputContentPurpose input_purpose;
|
||||
|
||||
/* bitfields */
|
||||
guint alignment : 2;
|
||||
guint wrap : 1;
|
||||
@ -236,6 +240,8 @@ enum
|
||||
PROP_SINGLE_LINE_MODE,
|
||||
PROP_SELECTED_TEXT_COLOR,
|
||||
PROP_SELECTED_TEXT_COLOR_SET,
|
||||
PROP_INPUT_HINTS,
|
||||
PROP_INPUT_PURPOSE,
|
||||
|
||||
PROP_LAST
|
||||
};
|
||||
@ -269,6 +275,7 @@ static const ClutterColor default_selected_text_color = { 0, 0, 0, 255 };
|
||||
static ClutterAnimatableIface *parent_animatable_iface = NULL;
|
||||
static ClutterScriptableIface *parent_scriptable_iface = NULL;
|
||||
|
||||
static void clutter_input_focus_iface_init (ClutterInputFocusInterface *iface);
|
||||
static void clutter_scriptable_iface_init (ClutterScriptableIface *iface);
|
||||
static void clutter_animatable_iface_init (ClutterAnimatableIface *iface);
|
||||
|
||||
@ -276,11 +283,91 @@ G_DEFINE_TYPE_WITH_CODE (ClutterText,
|
||||
clutter_text,
|
||||
CLUTTER_TYPE_ACTOR,
|
||||
G_ADD_PRIVATE (ClutterText)
|
||||
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_INPUT_FOCUS,
|
||||
clutter_input_focus_iface_init)
|
||||
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE,
|
||||
clutter_scriptable_iface_init)
|
||||
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_ANIMATABLE,
|
||||
clutter_animatable_iface_init));
|
||||
|
||||
static void
|
||||
clutter_text_input_focus_request_surrounding (ClutterInputFocus *focus)
|
||||
{
|
||||
ClutterText *clutter_text = CLUTTER_TEXT (focus);
|
||||
ClutterTextBuffer *buffer;
|
||||
const gchar *text;
|
||||
gint anchor_pos, cursor_pos;
|
||||
|
||||
buffer = clutter_text_get_buffer (clutter_text);
|
||||
text = clutter_text_buffer_get_text (buffer);
|
||||
|
||||
cursor_pos = clutter_text_get_cursor_position (clutter_text);
|
||||
if (cursor_pos < 0)
|
||||
cursor_pos = clutter_text_buffer_get_length (buffer);
|
||||
|
||||
anchor_pos = clutter_text_get_selection_bound (clutter_text);
|
||||
if (anchor_pos < 0)
|
||||
anchor_pos = cursor_pos;
|
||||
|
||||
clutter_input_focus_set_surrounding (focus, text,
|
||||
g_utf8_offset_to_pointer (text, cursor_pos) - text,
|
||||
g_utf8_offset_to_pointer (text, anchor_pos) - text);
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_text_input_focus_delete_surrounding (ClutterInputFocus *focus,
|
||||
guint offset,
|
||||
guint len)
|
||||
{
|
||||
ClutterText *clutter_text = CLUTTER_TEXT (focus);
|
||||
|
||||
if (clutter_text_get_editable (clutter_text))
|
||||
clutter_text_delete_text (clutter_text, offset, len);
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_text_input_focus_commit_text (ClutterInputFocus *focus,
|
||||
const gchar *text)
|
||||
{
|
||||
ClutterText *clutter_text = CLUTTER_TEXT (focus);
|
||||
|
||||
if (clutter_text_get_editable (clutter_text))
|
||||
{
|
||||
clutter_text_delete_selection (clutter_text);
|
||||
clutter_text_insert_text (clutter_text, text,
|
||||
clutter_text_get_cursor_position (clutter_text));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_text_input_focus_set_preedit_text (ClutterInputFocus *focus,
|
||||
const gchar *preedit_text,
|
||||
guint cursor_pos)
|
||||
{
|
||||
ClutterText *clutter_text = CLUTTER_TEXT (focus);
|
||||
|
||||
if (clutter_text_get_editable (clutter_text))
|
||||
{
|
||||
PangoAttrList *list;
|
||||
|
||||
list = pango_attr_list_new ();
|
||||
pango_attr_list_insert (list, pango_attr_underline_new (PANGO_UNDERLINE_SINGLE));
|
||||
clutter_text_set_preedit_string (clutter_text,
|
||||
preedit_text, list,
|
||||
cursor_pos);
|
||||
pango_attr_list_unref (list);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_input_focus_iface_init (ClutterInputFocusInterface *iface)
|
||||
{
|
||||
iface->request_surrounding = clutter_text_input_focus_request_surrounding;
|
||||
iface->delete_surrounding = clutter_text_input_focus_delete_surrounding;
|
||||
iface->commit_text = clutter_text_input_focus_commit_text;
|
||||
iface->set_preedit_text = clutter_text_input_focus_set_preedit_text;
|
||||
}
|
||||
|
||||
static inline void
|
||||
clutter_text_dirty_paint_volume (ClutterText *text)
|
||||
{
|
||||
@ -1009,6 +1096,22 @@ clutter_text_position_to_coords (ClutterText *self,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static inline void
|
||||
update_cursor_location (ClutterText *self)
|
||||
{
|
||||
ClutterTextPrivate *priv = self->priv;
|
||||
ClutterRect rect;
|
||||
float x, y;
|
||||
|
||||
if (!priv->editable)
|
||||
return;
|
||||
|
||||
rect = priv->cursor_rect;
|
||||
clutter_actor_get_transformed_position (CLUTTER_ACTOR (self), &x, &y);
|
||||
clutter_rect_offset (&rect, x, y);
|
||||
clutter_input_focus_set_cursor_location (CLUTTER_INPUT_FOCUS (self), &rect);
|
||||
}
|
||||
|
||||
static inline void
|
||||
clutter_text_ensure_cursor_position (ClutterText *self)
|
||||
{
|
||||
@ -1057,6 +1160,8 @@ clutter_text_ensure_cursor_position (ClutterText *self)
|
||||
g_signal_emit (self, text_signals[CURSOR_EVENT], 0, &cursor_pos);
|
||||
|
||||
g_signal_emit (self, text_signals[CURSOR_CHANGED], 0);
|
||||
|
||||
update_cursor_location (self);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1859,6 +1964,7 @@ clutter_text_press (ClutterActor *actor,
|
||||
return CLUTTER_EVENT_PROPAGATE;
|
||||
|
||||
clutter_actor_grab_key_focus (actor);
|
||||
clutter_input_focus_request_toggle_input_panel (CLUTTER_INPUT_FOCUS (self));
|
||||
|
||||
/* if the actor is empty we just reset everything and not
|
||||
* set up the dragging of the selection since there's nothing
|
||||
@ -2085,9 +2191,11 @@ clutter_text_key_press (ClutterActor *actor,
|
||||
g_assert (pool != NULL);
|
||||
|
||||
/* we allow passing synthetic events that only contain
|
||||
* the Unicode value and not the key symbol
|
||||
* the Unicode value and not the key symbol, unless they
|
||||
* contain the input method flag.
|
||||
*/
|
||||
if (event->keyval == 0 && (event->flags & CLUTTER_EVENT_FLAG_SYNTHETIC))
|
||||
if (event->keyval == 0 && (event->flags & CLUTTER_EVENT_FLAG_SYNTHETIC) &&
|
||||
!(event->flags & CLUTTER_EVENT_FLAG_INPUT_METHOD))
|
||||
res = FALSE;
|
||||
else
|
||||
res = clutter_binding_pool_activate (pool, event->keyval,
|
||||
@ -2105,6 +2213,9 @@ clutter_text_key_press (ClutterActor *actor,
|
||||
{
|
||||
gunichar key_unichar;
|
||||
|
||||
if (clutter_input_focus_filter_key_event (CLUTTER_INPUT_FOCUS (actor), event))
|
||||
return CLUTTER_EVENT_STOP;
|
||||
|
||||
/* Skip keys when control is pressed */
|
||||
key_unichar = clutter_event_get_key_unicode ((ClutterEvent *) event);
|
||||
|
||||
@ -2141,6 +2252,16 @@ clutter_text_key_press (ClutterActor *actor,
|
||||
return CLUTTER_EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
clutter_text_key_release (ClutterActor *actor,
|
||||
ClutterKeyEvent *event)
|
||||
{
|
||||
if (clutter_input_focus_filter_key_event (CLUTTER_INPUT_FOCUS (actor), event))
|
||||
return CLUTTER_EVENT_STOP;
|
||||
|
||||
return CLUTTER_EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_text_compute_layout_offsets (ClutterText *self,
|
||||
PangoLayout *layout,
|
||||
@ -2664,6 +2785,9 @@ clutter_text_key_focus_in (ClutterActor *actor)
|
||||
{
|
||||
ClutterTextPrivate *priv = CLUTTER_TEXT (actor)->priv;
|
||||
|
||||
if (priv->editable)
|
||||
clutter_input_focus_focus_in (CLUTTER_INPUT_FOCUS (actor));
|
||||
|
||||
priv->has_focus = TRUE;
|
||||
|
||||
clutter_text_queue_redraw (actor);
|
||||
@ -2676,6 +2800,9 @@ clutter_text_key_focus_out (ClutterActor *actor)
|
||||
|
||||
priv->has_focus = FALSE;
|
||||
|
||||
if (priv->editable)
|
||||
clutter_input_focus_focus_out (CLUTTER_INPUT_FOCUS (actor));
|
||||
|
||||
clutter_text_queue_redraw (actor);
|
||||
}
|
||||
|
||||
@ -3369,6 +3496,7 @@ clutter_text_class_init (ClutterTextClass *klass)
|
||||
actor_class->get_preferred_height = clutter_text_get_preferred_height;
|
||||
actor_class->allocate = clutter_text_allocate;
|
||||
actor_class->key_press_event = clutter_text_key_press;
|
||||
actor_class->key_release_event = clutter_text_key_release;
|
||||
actor_class->button_press_event = clutter_text_button_press;
|
||||
actor_class->button_release_event = clutter_text_button_release;
|
||||
actor_class->motion_event = clutter_text_motion;
|
||||
@ -3869,6 +3997,22 @@ clutter_text_class_init (ClutterTextClass *klass)
|
||||
obj_props[PROP_SELECTED_TEXT_COLOR_SET] = pspec;
|
||||
g_object_class_install_property (gobject_class, PROP_SELECTED_TEXT_COLOR_SET, pspec);
|
||||
|
||||
pspec = g_param_spec_flags ("input-hints",
|
||||
P_("Input hints"),
|
||||
P_("Input hints"),
|
||||
CLUTTER_TYPE_INPUT_CONTENT_HINT_FLAGS,
|
||||
0, CLUTTER_PARAM_READWRITE);
|
||||
obj_props[PROP_INPUT_HINTS] = pspec;
|
||||
g_object_class_install_property (gobject_class, PROP_INPUT_HINTS, pspec);
|
||||
|
||||
pspec = g_param_spec_enum ("input-purpose",
|
||||
P_("Input purpose"),
|
||||
P_("Input purpose"),
|
||||
CLUTTER_TYPE_INPUT_CONTENT_PURPOSE,
|
||||
0, CLUTTER_PARAM_READWRITE);
|
||||
obj_props[PROP_INPUT_PURPOSE] = pspec;
|
||||
g_object_class_install_property (gobject_class, PROP_INPUT_PURPOSE, pspec);
|
||||
|
||||
/**
|
||||
* ClutterText::text-changed:
|
||||
* @self: the #ClutterText that emitted the signal
|
||||
@ -4469,6 +4613,11 @@ clutter_text_set_editable (ClutterText *self,
|
||||
{
|
||||
priv->editable = editable;
|
||||
|
||||
if (!priv->editable)
|
||||
clutter_input_focus_focus_out (CLUTTER_INPUT_FOCUS (self));
|
||||
else if (priv->has_focus)
|
||||
clutter_input_focus_focus_in (CLUTTER_INPUT_FOCUS (self));
|
||||
|
||||
clutter_text_queue_redraw (CLUTTER_ACTOR (self));
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_EDITABLE]);
|
||||
@ -6298,3 +6447,49 @@ clutter_text_get_cursor_rect (ClutterText *self,
|
||||
|
||||
*rect = self->priv->cursor_rect;
|
||||
}
|
||||
|
||||
void
|
||||
clutter_text_set_input_hints (ClutterText *self,
|
||||
ClutterInputContentHintFlags hints)
|
||||
{
|
||||
g_return_if_fail (CLUTTER_IS_TEXT (self));
|
||||
|
||||
self->priv->input_hints = hints;
|
||||
clutter_input_focus_set_content_hints (CLUTTER_INPUT_FOCUS (self), hints);
|
||||
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_INPUT_HINTS]);
|
||||
}
|
||||
|
||||
ClutterInputContentHintFlags
|
||||
clutter_text_get_input_hints (ClutterText *self)
|
||||
{
|
||||
g_return_val_if_fail (CLUTTER_IS_TEXT (self), 0);
|
||||
|
||||
return self->priv->input_hints;
|
||||
}
|
||||
|
||||
void
|
||||
clutter_text_set_input_purpose (ClutterText *self,
|
||||
ClutterInputContentPurpose purpose)
|
||||
{
|
||||
g_return_if_fail (CLUTTER_IS_TEXT (self));
|
||||
|
||||
self->priv->input_purpose = purpose;
|
||||
clutter_input_focus_set_content_purpose (CLUTTER_INPUT_FOCUS (self), purpose);
|
||||
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_INPUT_PURPOSE]);
|
||||
}
|
||||
|
||||
ClutterInputContentPurpose
|
||||
clutter_text_get_input_purpose (ClutterText *self)
|
||||
{
|
||||
g_return_val_if_fail (CLUTTER_IS_TEXT (self), 0);
|
||||
|
||||
return self->priv->input_purpose;
|
||||
}
|
||||
|
||||
gboolean
|
||||
clutter_text_has_preedit (ClutterText *self)
|
||||
{
|
||||
g_return_val_if_fail (CLUTTER_IS_TEXT (self), FALSE);
|
||||
|
||||
return self->priv->preedit_set;
|
||||
}
|
||||
|
@ -302,6 +302,20 @@ void clutter_text_get_layout_offsets (ClutterText *
|
||||
gint *x,
|
||||
gint *y);
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_text_set_input_hints (ClutterText *self,
|
||||
ClutterInputContentHintFlags hints);
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
void clutter_text_set_input_purpose (ClutterText *self,
|
||||
ClutterInputContentPurpose purpose);
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
ClutterInputContentHintFlags clutter_text_get_input_hints (ClutterText *self);
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
ClutterInputContentPurpose clutter_text_get_input_purpose (ClutterText *self);
|
||||
|
||||
CLUTTER_AVAILABLE_IN_MUTTER
|
||||
gboolean clutter_text_has_preedit (ClutterText *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_TEXT_H__ */
|
||||
|
@ -97,6 +97,9 @@ typedef struct _ClutterInputDeviceTool ClutterInputDeviceTool;
|
||||
typedef struct _ClutterInputDevice ClutterInputDevice;
|
||||
typedef struct _ClutterVirtualInputDevice ClutterVirtualInputDevice;
|
||||
|
||||
typedef struct _ClutterInputMethod ClutterInputMethod;
|
||||
typedef struct _ClutterInputFocus ClutterInputFocus;
|
||||
|
||||
typedef CoglMatrix ClutterMatrix;
|
||||
|
||||
typedef union _ClutterEvent ClutterEvent;
|
||||
|
@ -72,6 +72,8 @@
|
||||
#include "clutter-image.h"
|
||||
#include "clutter-input-device.h"
|
||||
#include "clutter-input-device-tool.h"
|
||||
#include "clutter-input-method.h"
|
||||
#include "clutter-input-focus.h"
|
||||
#include "clutter-interval.h"
|
||||
#include "clutter-keyframe-transition.h"
|
||||
#include "clutter-keysyms.h"
|
||||
|
@ -86,6 +86,8 @@ mutter_built_sources += \
|
||||
xdg-output-unstable-v1-server-protocol.h \
|
||||
xwayland-keyboard-grab-unstable-v1-protocol.c \
|
||||
xwayland-keyboard-grab-unstable-v1-server-protocol.h \
|
||||
gtk-text-input-protocol.c \
|
||||
gtk-text-input-server-protocol.h \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
@ -431,6 +433,8 @@ libmutter_@LIBMUTTER_API_VERSION@_la_SOURCES += \
|
||||
wayland/meta-wayland-surface-role-cursor.h \
|
||||
wayland/meta-wayland-surface-role-tablet-cursor.c \
|
||||
wayland/meta-wayland-surface-role-tablet-cursor.h \
|
||||
wayland/meta-wayland-text-input.c \
|
||||
wayland/meta-wayland-text-input.h \
|
||||
wayland/meta-wayland-types.h \
|
||||
wayland/meta-wayland-versions.h \
|
||||
wayland/meta-wayland-outputs.c \
|
||||
|
@ -643,7 +643,8 @@ default_grab_key (MetaWaylandKeyboardGrab *grab,
|
||||
|
||||
/* Synthetic key events are for autorepeat. Ignore those, as
|
||||
* autorepeat in Wayland is done on the client side. */
|
||||
if (event->key.flags & CLUTTER_EVENT_FLAG_SYNTHETIC)
|
||||
if ((event->key.flags & CLUTTER_EVENT_FLAG_SYNTHETIC) &&
|
||||
!(event->key.flags & CLUTTER_EVENT_FLAG_INPUT_METHOD))
|
||||
return FALSE;
|
||||
|
||||
#ifdef HAVE_NATIVE_BACKEND
|
||||
@ -786,7 +787,8 @@ meta_wayland_keyboard_handle_event (MetaWaylandKeyboard *keyboard,
|
||||
|
||||
/* Synthetic key events are for autorepeat. Ignore those, as
|
||||
* autorepeat in Wayland is done on the client side. */
|
||||
if (event->flags & CLUTTER_EVENT_FLAG_SYNTHETIC)
|
||||
if ((event->flags & CLUTTER_EVENT_FLAG_SYNTHETIC) &&
|
||||
!(event->flags & CLUTTER_EVENT_FLAG_INPUT_METHOD))
|
||||
return FALSE;
|
||||
|
||||
meta_verbose ("Handling key %s event code %d\n",
|
||||
|
@ -225,6 +225,8 @@ meta_wayland_seat_new (MetaWaylandCompositor *compositor,
|
||||
"seat", seat,
|
||||
NULL);
|
||||
|
||||
seat->text_input = meta_wayland_text_input_new (seat);
|
||||
|
||||
meta_wayland_data_device_init (&seat->data_device);
|
||||
|
||||
device_manager = clutter_device_manager_get_default ();
|
||||
@ -260,6 +262,7 @@ meta_wayland_seat_free (MetaWaylandSeat *seat)
|
||||
g_object_unref (seat->pointer);
|
||||
g_object_unref (seat->keyboard);
|
||||
g_object_unref (seat->touch);
|
||||
g_object_unref (seat->text_input);
|
||||
|
||||
g_slice_free (MetaWaylandSeat, seat);
|
||||
}
|
||||
@ -376,6 +379,11 @@ meta_wayland_seat_handle_event (MetaWaylandSeat *seat,
|
||||
|
||||
case CLUTTER_KEY_PRESS:
|
||||
case CLUTTER_KEY_RELEASE:
|
||||
if (seat->text_input &&
|
||||
clutter_input_focus_filter_key_event (CLUTTER_INPUT_FOCUS (seat->text_input),
|
||||
(const ClutterKeyEvent *) event))
|
||||
return TRUE;
|
||||
|
||||
if (meta_wayland_seat_has_keyboard (seat))
|
||||
return meta_wayland_keyboard_handle_event (seat->keyboard,
|
||||
(const ClutterKeyEvent *) event);
|
||||
@ -416,6 +424,8 @@ meta_wayland_seat_set_input_focus (MetaWaylandSeat *seat,
|
||||
|
||||
tablet_seat = meta_wayland_tablet_manager_ensure_seat (compositor->tablet_manager, seat);
|
||||
meta_wayland_tablet_seat_set_pad_focus (tablet_seat, surface);
|
||||
|
||||
meta_wayland_text_input_set_focus (seat->text_input, surface);
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "meta-wayland-touch.h"
|
||||
#include "meta-wayland-data-device.h"
|
||||
#include "meta-wayland-tablet-tool.h"
|
||||
#include "meta-wayland-text-input.h"
|
||||
|
||||
struct _MetaWaylandSeat
|
||||
{
|
||||
@ -42,6 +43,8 @@ struct _MetaWaylandSeat
|
||||
MetaWaylandKeyboard *keyboard;
|
||||
MetaWaylandTouch *touch;
|
||||
|
||||
MetaWaylandTextInput *text_input;
|
||||
|
||||
MetaWaylandDataDevice data_device;
|
||||
|
||||
guint capabilities;
|
||||
|
644
src/wayland/meta-wayland-text-input.c
Normal file
644
src/wayland/meta-wayland-text-input.c
Normal file
@ -0,0 +1,644 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Red Hat
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Author: Carlos Garnacho <carlosg@gnome.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <wayland-server.h>
|
||||
|
||||
#include "gtk-text-input-server-protocol.h"
|
||||
#include "wayland/meta-wayland-private.h"
|
||||
#include "wayland/meta-wayland-seat.h"
|
||||
#include "wayland/meta-wayland-text-input.h"
|
||||
#include "wayland/meta-wayland-versions.h"
|
||||
|
||||
static void meta_wayland_text_input_input_focus_iface_init (ClutterInputFocusInterface *iface);
|
||||
|
||||
typedef struct _MetaWaylandTextInput MetaWaylandTextInput;
|
||||
|
||||
struct _MetaWaylandTextInput
|
||||
{
|
||||
GObject parent_instance;
|
||||
|
||||
MetaWaylandSeat *seat;
|
||||
|
||||
struct wl_list resource_list;
|
||||
struct wl_list focus_resource_list;
|
||||
MetaWaylandSurface *surface;
|
||||
struct wl_listener surface_listener;
|
||||
uint32_t focus_serial;
|
||||
|
||||
guint pending_state;
|
||||
|
||||
struct {
|
||||
gchar *text;
|
||||
guint cursor;
|
||||
guint anchor;
|
||||
} surrounding;
|
||||
|
||||
cairo_rectangle_int_t cursor_rect;
|
||||
|
||||
guint content_type_hint;
|
||||
guint content_type_purpose;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_SEAT,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
enum {
|
||||
PENDING_STATE_NONE = 0,
|
||||
PENDING_STATE_INPUT_RECT = 1 << 0,
|
||||
PENDING_STATE_CONTENT_TYPE = 1 << 1,
|
||||
PENDING_STATE_SURROUNDING_TEXT = 1 << 2,
|
||||
};
|
||||
|
||||
static GParamSpec *props[N_PROPS] = { 0 };
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (MetaWaylandTextInput, meta_wayland_text_input,
|
||||
G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_INPUT_FOCUS,
|
||||
meta_wayland_text_input_input_focus_iface_init))
|
||||
|
||||
static void
|
||||
text_input_handle_focus_surface_destroy (struct wl_listener *listener,
|
||||
void *data)
|
||||
{
|
||||
MetaWaylandTextInput *text_input = wl_container_of (listener, text_input,
|
||||
surface_listener);
|
||||
|
||||
meta_wayland_text_input_set_focus (text_input, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_focus_in (ClutterInputFocus *focus,
|
||||
ClutterInputMethod *method)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_focus_out (ClutterInputFocus *focus)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_request_surrounding (ClutterInputFocus *focus)
|
||||
{
|
||||
MetaWaylandTextInput *text_input = META_WAYLAND_TEXT_INPUT (focus);
|
||||
|
||||
clutter_input_focus_set_surrounding (focus,
|
||||
text_input->surrounding.text,
|
||||
text_input->surrounding.cursor,
|
||||
text_input->surrounding.anchor);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_delete_surrounding (ClutterInputFocus *focus,
|
||||
guint cursor,
|
||||
guint len)
|
||||
{
|
||||
MetaWaylandTextInput *input = META_WAYLAND_TEXT_INPUT (focus);
|
||||
struct wl_resource *resource;
|
||||
|
||||
wl_resource_for_each (resource, &input->focus_resource_list)
|
||||
{
|
||||
gtk_text_input_send_delete_surrounding_text (resource, cursor, len);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_commit_text (ClutterInputFocus *focus,
|
||||
const gchar *text)
|
||||
{
|
||||
MetaWaylandTextInput *input = META_WAYLAND_TEXT_INPUT (focus);
|
||||
struct wl_resource *resource;
|
||||
|
||||
wl_resource_for_each (resource, &input->focus_resource_list)
|
||||
{
|
||||
gtk_text_input_send_preedit_string (resource, NULL, 0);
|
||||
gtk_text_input_send_commit (resource, text);
|
||||
}
|
||||
|
||||
clutter_input_focus_reset (focus);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_set_preedit_text (ClutterInputFocus *focus,
|
||||
const gchar *text,
|
||||
guint cursor)
|
||||
{
|
||||
MetaWaylandTextInput *input = META_WAYLAND_TEXT_INPUT (focus);
|
||||
struct wl_resource *resource;
|
||||
|
||||
wl_resource_for_each (resource, &input->focus_resource_list)
|
||||
{
|
||||
gtk_text_input_send_preedit_string (resource, text, cursor);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_input_focus_iface_init (ClutterInputFocusInterface *iface)
|
||||
{
|
||||
iface->focus_in = meta_wayland_text_input_focus_in;
|
||||
iface->focus_out = meta_wayland_text_input_focus_out;
|
||||
iface->request_surrounding = meta_wayland_text_input_request_surrounding;
|
||||
iface->delete_surrounding = meta_wayland_text_input_delete_surrounding;
|
||||
iface->commit_text = meta_wayland_text_input_commit_text;
|
||||
iface->set_preedit_text = meta_wayland_text_input_set_preedit_text;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MetaWaylandTextInput *text_input = META_WAYLAND_TEXT_INPUT (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_SEAT:
|
||||
text_input->seat = g_value_get_pointer (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MetaWaylandTextInput *text_input = META_WAYLAND_TEXT_INPUT (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_SEAT:
|
||||
g_value_set_pointer (value, text_input->seat);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_finalize (GObject *object)
|
||||
{
|
||||
MetaWaylandTextInput *text_input = META_WAYLAND_TEXT_INPUT (object);
|
||||
|
||||
meta_wayland_text_input_set_focus (text_input, NULL);
|
||||
|
||||
G_OBJECT_CLASS (meta_wayland_text_input_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_class_init (MetaWaylandTextInputClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->set_property = meta_wayland_text_input_set_property;
|
||||
object_class->get_property = meta_wayland_text_input_get_property;
|
||||
object_class->finalize = meta_wayland_text_input_finalize;
|
||||
|
||||
props[PROP_SEAT] = g_param_spec_pointer ("seat",
|
||||
"MetaWaylandSeat",
|
||||
"The seat",
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS |
|
||||
G_PARAM_CONSTRUCT_ONLY);
|
||||
g_object_class_install_properties (object_class, N_PROPS, props);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_init (MetaWaylandTextInput *text_input)
|
||||
{
|
||||
wl_list_init (&text_input->resource_list);
|
||||
wl_list_init (&text_input->focus_resource_list);
|
||||
text_input->surface_listener.notify = text_input_handle_focus_surface_destroy;
|
||||
}
|
||||
|
||||
static void
|
||||
move_resources (struct wl_list *destination, struct wl_list *source)
|
||||
{
|
||||
wl_list_insert_list (destination, source);
|
||||
wl_list_init (source);
|
||||
}
|
||||
|
||||
static void
|
||||
move_resources_for_client (struct wl_list *destination,
|
||||
struct wl_list *source,
|
||||
struct wl_client *client)
|
||||
{
|
||||
struct wl_resource *resource, *tmp;
|
||||
wl_resource_for_each_safe (resource, tmp, source)
|
||||
{
|
||||
if (wl_resource_get_client (resource) == client)
|
||||
{
|
||||
wl_list_remove (wl_resource_get_link (resource));
|
||||
wl_list_insert (destination, wl_resource_get_link (resource));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
meta_wayland_text_input_set_focus (MetaWaylandTextInput *text_input,
|
||||
MetaWaylandSurface *surface)
|
||||
{
|
||||
if (text_input->surface == surface)
|
||||
return;
|
||||
|
||||
text_input->pending_state = PENDING_STATE_NONE;
|
||||
|
||||
if (text_input->surface)
|
||||
{
|
||||
if (!wl_list_empty (&text_input->focus_resource_list))
|
||||
{
|
||||
struct wl_resource *resource;
|
||||
uint32_t serial;
|
||||
|
||||
clutter_input_focus_focus_out (CLUTTER_INPUT_FOCUS (text_input));
|
||||
serial = wl_display_next_serial (text_input->seat->wl_display);
|
||||
|
||||
wl_resource_for_each (resource, &text_input->focus_resource_list)
|
||||
{
|
||||
gtk_text_input_send_preedit_string (resource, NULL, 0);
|
||||
gtk_text_input_send_leave (resource, serial,
|
||||
text_input->surface->resource);
|
||||
}
|
||||
|
||||
move_resources (&text_input->resource_list,
|
||||
&text_input->focus_resource_list);
|
||||
}
|
||||
|
||||
wl_list_remove (&text_input->surface_listener.link);
|
||||
text_input->surface = NULL;
|
||||
}
|
||||
|
||||
if (surface)
|
||||
{
|
||||
struct wl_resource *focus_surface_resource;
|
||||
|
||||
text_input->surface = surface;
|
||||
focus_surface_resource = text_input->surface->resource;
|
||||
wl_resource_add_destroy_listener (focus_surface_resource,
|
||||
&text_input->surface_listener);
|
||||
|
||||
move_resources_for_client (&text_input->focus_resource_list,
|
||||
&text_input->resource_list,
|
||||
wl_resource_get_client (focus_surface_resource));
|
||||
|
||||
if (!wl_list_empty (&text_input->focus_resource_list))
|
||||
{
|
||||
struct wl_resource *resource;
|
||||
|
||||
text_input->focus_serial =
|
||||
wl_display_next_serial (text_input->seat->wl_display);
|
||||
|
||||
wl_resource_for_each (resource, &text_input->focus_resource_list)
|
||||
{
|
||||
gtk_text_input_send_enter (resource, text_input->focus_serial,
|
||||
surface->resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
unbind_resource (struct wl_resource *resource)
|
||||
{
|
||||
wl_list_remove (wl_resource_get_link (resource));
|
||||
}
|
||||
|
||||
static void
|
||||
text_input_destroy (struct wl_client *client,
|
||||
struct wl_resource *resource)
|
||||
{
|
||||
wl_resource_destroy (resource);
|
||||
}
|
||||
|
||||
static void
|
||||
text_input_enable (struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
uint32_t serial,
|
||||
uint32_t flags)
|
||||
{
|
||||
MetaWaylandTextInput *text_input = wl_resource_get_user_data (resource);
|
||||
ClutterInputFocus *focus = CLUTTER_INPUT_FOCUS (text_input);
|
||||
gboolean show_preedit;
|
||||
|
||||
if (serial != text_input->focus_serial)
|
||||
return;
|
||||
|
||||
show_preedit = (flags & GTK_TEXT_INPUT_ENABLE_FLAGS_CAN_SHOW_PREEDIT) != 0;
|
||||
clutter_input_focus_set_can_show_preedit (focus, show_preedit);
|
||||
|
||||
clutter_input_focus_focus_in (CLUTTER_INPUT_FOCUS (text_input));
|
||||
|
||||
if (flags & GTK_TEXT_INPUT_ENABLE_FLAGS_TOGGLE_INPUT_PANEL)
|
||||
clutter_input_focus_request_toggle_input_panel (focus);
|
||||
}
|
||||
|
||||
static void
|
||||
text_input_disable (struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
uint32_t serial)
|
||||
{
|
||||
MetaWaylandTextInput *text_input = wl_resource_get_user_data (resource);
|
||||
|
||||
if (serial != text_input->focus_serial)
|
||||
return;
|
||||
|
||||
clutter_input_focus_reset (CLUTTER_INPUT_FOCUS (text_input));
|
||||
clutter_input_focus_focus_out (CLUTTER_INPUT_FOCUS (text_input));
|
||||
text_input->pending_state = PENDING_STATE_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
text_input_set_surrounding_text (struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
const char *text,
|
||||
int32_t cursor,
|
||||
int32_t anchor)
|
||||
{
|
||||
MetaWaylandTextInput *text_input = wl_resource_get_user_data (resource);
|
||||
|
||||
g_free (text_input->surrounding.text);
|
||||
text_input->surrounding.text = g_strdup (text);
|
||||
text_input->surrounding.cursor = cursor;
|
||||
text_input->surrounding.anchor = anchor;
|
||||
text_input->pending_state |= PENDING_STATE_SURROUNDING_TEXT;
|
||||
}
|
||||
|
||||
static ClutterInputContentHintFlags
|
||||
translate_hints (uint32_t hints)
|
||||
{
|
||||
ClutterInputContentHintFlags clutter_hints = 0;
|
||||
|
||||
if (hints & GTK_TEXT_INPUT_CONTENT_HINT_COMPLETION)
|
||||
clutter_hints |= CLUTTER_INPUT_CONTENT_HINT_COMPLETION;
|
||||
if (hints & GTK_TEXT_INPUT_CONTENT_HINT_SPELLCHECK)
|
||||
clutter_hints |= CLUTTER_INPUT_CONTENT_HINT_SPELLCHECK;
|
||||
if (hints & GTK_TEXT_INPUT_CONTENT_HINT_AUTO_CAPITALIZATION)
|
||||
clutter_hints |= CLUTTER_INPUT_CONTENT_HINT_AUTO_CAPITALIZATION;
|
||||
if (hints & GTK_TEXT_INPUT_CONTENT_HINT_LOWERCASE)
|
||||
clutter_hints |= CLUTTER_INPUT_CONTENT_HINT_LOWERCASE;
|
||||
if (hints & GTK_TEXT_INPUT_CONTENT_HINT_UPPERCASE)
|
||||
clutter_hints |= CLUTTER_INPUT_CONTENT_HINT_UPPERCASE;
|
||||
if (hints & GTK_TEXT_INPUT_CONTENT_HINT_TITLECASE)
|
||||
clutter_hints |= CLUTTER_INPUT_CONTENT_HINT_TITLECASE;
|
||||
if (hints & GTK_TEXT_INPUT_CONTENT_HINT_HIDDEN_TEXT)
|
||||
clutter_hints |= CLUTTER_INPUT_CONTENT_HINT_HIDDEN_TEXT;
|
||||
if (hints & GTK_TEXT_INPUT_CONTENT_HINT_SENSITIVE_DATA)
|
||||
clutter_hints |= CLUTTER_INPUT_CONTENT_HINT_SENSITIVE_DATA;
|
||||
if (hints & GTK_TEXT_INPUT_CONTENT_HINT_LATIN)
|
||||
clutter_hints |= CLUTTER_INPUT_CONTENT_HINT_LATIN;
|
||||
if (hints & GTK_TEXT_INPUT_CONTENT_HINT_MULTILINE)
|
||||
clutter_hints |= CLUTTER_INPUT_CONTENT_HINT_MULTILINE;
|
||||
|
||||
return clutter_hints;
|
||||
}
|
||||
|
||||
static ClutterInputContentPurpose
|
||||
translate_purpose (uint32_t purpose)
|
||||
{
|
||||
switch (purpose)
|
||||
{
|
||||
case GTK_TEXT_INPUT_CONTENT_PURPOSE_NORMAL:
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_NORMAL;
|
||||
case GTK_TEXT_INPUT_CONTENT_PURPOSE_ALPHA:
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_ALPHA;
|
||||
case GTK_TEXT_INPUT_CONTENT_PURPOSE_DIGITS:
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_DIGITS;
|
||||
case GTK_TEXT_INPUT_CONTENT_PURPOSE_NUMBER:
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_NUMBER;
|
||||
case GTK_TEXT_INPUT_CONTENT_PURPOSE_PHONE:
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_PHONE;
|
||||
case GTK_TEXT_INPUT_CONTENT_PURPOSE_URL:
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_URL;
|
||||
case GTK_TEXT_INPUT_CONTENT_PURPOSE_EMAIL:
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_EMAIL;
|
||||
case GTK_TEXT_INPUT_CONTENT_PURPOSE_NAME:
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_NAME;
|
||||
case GTK_TEXT_INPUT_CONTENT_PURPOSE_PASSWORD:
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_PASSWORD;
|
||||
case GTK_TEXT_INPUT_CONTENT_PURPOSE_DATE:
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_DATE;
|
||||
case GTK_TEXT_INPUT_CONTENT_PURPOSE_TIME:
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_TIME;
|
||||
case GTK_TEXT_INPUT_CONTENT_PURPOSE_DATETIME:
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_DATETIME;
|
||||
case GTK_TEXT_INPUT_CONTENT_PURPOSE_TERMINAL:
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_TERMINAL;
|
||||
}
|
||||
|
||||
g_warn_if_reached ();
|
||||
return CLUTTER_INPUT_CONTENT_PURPOSE_NORMAL;
|
||||
}
|
||||
|
||||
static void
|
||||
text_input_set_content_type (struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
uint32_t hint,
|
||||
uint32_t purpose)
|
||||
{
|
||||
MetaWaylandTextInput *text_input = wl_resource_get_user_data (resource);
|
||||
|
||||
if (!text_input->surface)
|
||||
return;
|
||||
|
||||
text_input->content_type_hint = hint;
|
||||
text_input->content_type_purpose = purpose;
|
||||
text_input->pending_state |= PENDING_STATE_CONTENT_TYPE;
|
||||
}
|
||||
|
||||
static void
|
||||
text_input_set_cursor_rectangle (struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
int32_t x,
|
||||
int32_t y,
|
||||
int32_t width,
|
||||
int32_t height)
|
||||
{
|
||||
MetaWaylandTextInput *text_input = wl_resource_get_user_data (resource);
|
||||
|
||||
if (!text_input->surface)
|
||||
return;
|
||||
|
||||
text_input->cursor_rect = (cairo_rectangle_int_t) { x, y, width, height };
|
||||
text_input->pending_state |= PENDING_STATE_INPUT_RECT;
|
||||
}
|
||||
|
||||
static void
|
||||
text_input_commit_state (struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
uint32_t serial)
|
||||
{
|
||||
MetaWaylandTextInput *text_input = wl_resource_get_user_data (resource);
|
||||
|
||||
if (text_input->surface == NULL)
|
||||
return;
|
||||
if (serial != text_input->focus_serial)
|
||||
return;
|
||||
|
||||
if (text_input->pending_state & PENDING_STATE_CONTENT_TYPE)
|
||||
{
|
||||
clutter_input_focus_set_content_hints (CLUTTER_INPUT_FOCUS (text_input),
|
||||
translate_hints (text_input->content_type_hint));
|
||||
clutter_input_focus_set_content_purpose (CLUTTER_INPUT_FOCUS (text_input),
|
||||
translate_purpose (text_input->content_type_purpose));
|
||||
}
|
||||
|
||||
if (text_input->pending_state & PENDING_STATE_SURROUNDING_TEXT)
|
||||
{
|
||||
clutter_input_focus_set_surrounding (CLUTTER_INPUT_FOCUS (text_input),
|
||||
text_input->surrounding.text,
|
||||
text_input->surrounding.cursor,
|
||||
text_input->surrounding.anchor);
|
||||
}
|
||||
|
||||
if (text_input->pending_state & PENDING_STATE_INPUT_RECT)
|
||||
{
|
||||
ClutterRect cursor_rect;
|
||||
float x1, y1, x2, y2;
|
||||
cairo_rectangle_int_t rect;
|
||||
|
||||
rect = text_input->cursor_rect;
|
||||
meta_wayland_surface_get_absolute_coordinates (text_input->surface,
|
||||
rect.x, rect.y, &x1, &y1);
|
||||
meta_wayland_surface_get_absolute_coordinates (text_input->surface,
|
||||
rect.x + rect.width,
|
||||
rect.y + rect.height,
|
||||
&x2, &y2);
|
||||
|
||||
clutter_rect_init (&cursor_rect, x1, y1, x2 - x1, y2 - y1);
|
||||
clutter_input_focus_set_cursor_location (CLUTTER_INPUT_FOCUS (text_input),
|
||||
&cursor_rect);
|
||||
}
|
||||
|
||||
text_input->pending_state = PENDING_STATE_NONE;
|
||||
}
|
||||
|
||||
static struct gtk_text_input_interface meta_text_input_interface = {
|
||||
text_input_destroy,
|
||||
text_input_enable,
|
||||
text_input_disable,
|
||||
text_input_set_surrounding_text,
|
||||
text_input_set_content_type,
|
||||
text_input_set_cursor_rectangle,
|
||||
text_input_commit_state,
|
||||
};
|
||||
|
||||
MetaWaylandTextInput *
|
||||
meta_wayland_text_input_new (MetaWaylandSeat *seat)
|
||||
{
|
||||
return g_object_new (META_TYPE_WAYLAND_TEXT_INPUT,
|
||||
"seat", seat,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_create_new_resource (MetaWaylandTextInput *text_input,
|
||||
struct wl_client *client,
|
||||
struct wl_resource *seat_resource,
|
||||
uint32_t id)
|
||||
{
|
||||
struct wl_resource *text_input_resource;
|
||||
|
||||
text_input_resource = wl_resource_create (client,
|
||||
>k_text_input_interface,
|
||||
META_GTK_TEXT_INPUT_VERSION,
|
||||
id);
|
||||
|
||||
wl_resource_set_implementation (text_input_resource,
|
||||
&meta_text_input_interface,
|
||||
text_input, unbind_resource);
|
||||
|
||||
if (text_input->surface &&
|
||||
wl_resource_get_client (text_input->surface->resource) == client)
|
||||
{
|
||||
wl_list_insert (&text_input->focus_resource_list,
|
||||
wl_resource_get_link (text_input_resource));
|
||||
|
||||
gtk_text_input_send_enter (text_input_resource,
|
||||
text_input->focus_serial,
|
||||
text_input->surface->resource);
|
||||
}
|
||||
else
|
||||
{
|
||||
wl_list_insert (&text_input->resource_list,
|
||||
wl_resource_get_link (text_input_resource));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
text_input_manager_destroy (struct wl_client *client,
|
||||
struct wl_resource *resource)
|
||||
{
|
||||
wl_resource_destroy (resource);
|
||||
}
|
||||
|
||||
static void
|
||||
text_input_manager_get_text_input (struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
uint32_t id,
|
||||
struct wl_resource *seat_resource)
|
||||
{
|
||||
MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
|
||||
|
||||
meta_wayland_text_input_create_new_resource (seat->text_input,
|
||||
client, seat_resource, id);
|
||||
}
|
||||
|
||||
static struct gtk_text_input_manager_interface meta_text_input_manager_interface = {
|
||||
text_input_manager_destroy,
|
||||
text_input_manager_get_text_input,
|
||||
};
|
||||
|
||||
static void
|
||||
bind_text_input (struct wl_client *client,
|
||||
void *data,
|
||||
uint32_t version,
|
||||
uint32_t id)
|
||||
{
|
||||
struct wl_resource *resource;
|
||||
|
||||
resource = wl_resource_create (client,
|
||||
>k_text_input_manager_interface,
|
||||
META_GTK_TEXT_INPUT_VERSION,
|
||||
id);
|
||||
wl_resource_set_implementation (resource,
|
||||
&meta_text_input_manager_interface,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_wayland_text_input_init_global (MetaWaylandCompositor *compositor)
|
||||
{
|
||||
return (wl_global_create (compositor->wayland_display,
|
||||
>k_text_input_manager_interface,
|
||||
META_GTK_TEXT_INPUT_VERSION, NULL,
|
||||
bind_text_input) != NULL);
|
||||
}
|
42
src/wayland/meta-wayland-text-input.h
Normal file
42
src/wayland/meta-wayland-text-input.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Red Hat
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Author: Carlos Garnacho <carlosg@gnome.org>
|
||||
*/
|
||||
|
||||
#ifndef META_WAYLAND_TEXT_INPUT_H
|
||||
#define META_WAYLAND_TEXT_INPUT_H
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include "wayland/meta-wayland-types.h"
|
||||
#include "meta/window.h"
|
||||
|
||||
#define META_TYPE_WAYLAND_TEXT_INPUT (meta_wayland_text_input_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (MetaWaylandTextInput,
|
||||
meta_wayland_text_input,
|
||||
META, WAYLAND_TEXT_INPUT,
|
||||
GObject);
|
||||
|
||||
MetaWaylandTextInput * meta_wayland_text_input_new (MetaWaylandSeat *seat);
|
||||
|
||||
gboolean meta_wayland_text_input_init_global (MetaWaylandCompositor *compositor);
|
||||
|
||||
void meta_wayland_text_input_set_focus (MetaWaylandTextInput *text_input,
|
||||
MetaWaylandSurface *surface);
|
||||
|
||||
#endif /* META_WAYLAND_TEXT_INPUT_H */
|
@ -51,5 +51,6 @@
|
||||
#define META_ZWP_KEYBOARD_SHORTCUTS_INHIBIT_V1_VERSION 1
|
||||
#define META_ZXDG_OUTPUT_V1_VERSION 1
|
||||
#define META_ZWP_XWAYLAND_KEYBOARD_GRAB_V1_VERSION 1
|
||||
#define META_GTK_TEXT_INPUT_VERSION 1
|
||||
|
||||
#endif
|
||||
|
@ -384,6 +384,7 @@ meta_wayland_init (void)
|
||||
meta_wayland_dma_buf_init (compositor);
|
||||
meta_wayland_keyboard_shortcuts_inhibit_init (compositor);
|
||||
meta_wayland_surface_inhibit_shortcuts_dialog_init ();
|
||||
meta_wayland_text_input_init_global (compositor);
|
||||
|
||||
/* Xwayland specific protocol, needs to be filtered out for all other clients */
|
||||
if (meta_xwayland_grab_keyboard_init (compositor))
|
||||
|
304
src/wayland/protocol/gtk-text-input.xml
Normal file
304
src/wayland/protocol/gtk-text-input.xml
Normal file
@ -0,0 +1,304 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<protocol name="gtk_text_input">
|
||||
<copyright>
|
||||
Copyright © 2012, 2013 Intel Corporation
|
||||
Copyright © 2015, 2016 Jan Arne Petersen
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that copyright notice and this permission
|
||||
notice appear in supporting documentation, and that the name of
|
||||
the copyright holders not be used in advertising or publicity
|
||||
pertaining to distribution of the software without specific,
|
||||
written prior permission. The copyright holders make no
|
||||
representations about the suitability of this software for any
|
||||
purpose. It is provided "as is" without express or implied
|
||||
warranty.
|
||||
|
||||
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
||||
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
</copyright>
|
||||
|
||||
<interface name="gtk_text_input" version="1">
|
||||
<description summary="text input">
|
||||
The gtk_text_input interface represents text input and input methods
|
||||
associated with a seat. It provides enter/leave events to follow the
|
||||
text input focus for a seat.
|
||||
|
||||
Requests are used to enable/disable the text-input object and set
|
||||
state information like surrounding and selected text or the content type.
|
||||
The information about the entered text is sent to the text-input object
|
||||
via the pre-edit and commit events. Using this interface removes the need
|
||||
for applications to directly process hardware key events and compose text
|
||||
out of them.
|
||||
|
||||
Text is valid UTF-8 encoded, indices and lengths are in bytes. Indices
|
||||
have to always point to the first byte of an UTF-8 encoded code point.
|
||||
Lengths are not allowed to contain just a part of an UTF-8 encoded code
|
||||
point.
|
||||
|
||||
Focus moving throughout surfaces will result in the emission of
|
||||
gtk_text_input.enter and gtk_text_input.leave events. The focused
|
||||
surface must perform gtk_text_input.enable and
|
||||
gtk_text_input.disable requests as the keyboard focus moves across
|
||||
editable and non-editable elements of the UI. Those two requests are not
|
||||
expected to be paired with each other, the compositor must be able to
|
||||
handle consecutive series of the same request.
|
||||
|
||||
State is sent by the state requests (set_surrounding_text,
|
||||
set_content_type and set_cursor_rectangle) and an commit_state request.
|
||||
After an enter event or disable request all state information is
|
||||
invalidated and needs to be resent by the client.
|
||||
|
||||
This protocol defines requests and events necessary for regular clients
|
||||
to communicate with an input method. The gtk_input_method protocol
|
||||
defines the interfaces necessary to implement standalone input methods.
|
||||
If a compositor implements both interfaces, it will be the arbiter of the
|
||||
communication between both.
|
||||
|
||||
Warning! The protocol described in this file is experimental and
|
||||
backward incompatible changes may be made. Backward compatible changes
|
||||
may be added together with the corresponding interface version bump.
|
||||
Backward incompatible changes are done by bumping the version number in
|
||||
the protocol and interface names and resetting the interface version.
|
||||
Once the protocol is to be declared stable, the 'z' prefix and the
|
||||
version number in the protocol and interface names are removed and the
|
||||
interface version number is reset.
|
||||
</description>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="Destroy the wp_text_input">
|
||||
Destroy the wp_text_input object. Also disables all surfaces enabled
|
||||
through this wp_text_input object
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<enum name="enable_flags" bitfield="true">
|
||||
<description summary="enable flags">
|
||||
Content hint is a bitmask to allow to modify the behavior of the text
|
||||
input.
|
||||
</description>
|
||||
<entry name="none" value="0x0" summary="no special behaviour"/>
|
||||
<entry name="can_show_preedit" value="0x1" summary="hints that the UI is capable of showing pre-edit text"/>
|
||||
<entry name="toggle_input_panel" value="0x2" summary="requests toggling input panel (eg. on-screen keyboard)"/>
|
||||
</enum>
|
||||
|
||||
<request name="enable">
|
||||
<description summary="Request text input to be enabled">
|
||||
Requests text input on a surface. The surface must have keyboard
|
||||
focus, and the serial provided must be the one received on
|
||||
gtk_text_input.enter.
|
||||
</description>
|
||||
<arg name="serial" type="uint" summary="serial of enter event"/>
|
||||
<arg name="show_input_panel" type="uint" summary="details of the enable request"/>
|
||||
</request>
|
||||
|
||||
<request name="disable">
|
||||
<description summary="Disable text input on a surface">
|
||||
Explicitly disable text input in a surface (typically when there is no
|
||||
focus on any text entry inside the surface).
|
||||
</description>
|
||||
<arg name="serial" type="uint" summary="serial of enter event"/>
|
||||
</request>
|
||||
|
||||
<request name="set_surrounding_text">
|
||||
<description summary="sets the surrounding text">
|
||||
Sets the plain surrounding text around the input position. Text is
|
||||
UTF-8 encoded. Cursor is the byte offset within the surrounding text.
|
||||
Anchor is the byte offset of the selection anchor within the
|
||||
surrounding text. If there is no selected text, anchor is the same as
|
||||
cursor.
|
||||
|
||||
Make sure to always send some text before and after the cursor
|
||||
except when the cursor is at the beginning or end of text.
|
||||
|
||||
When there was a configure_surrounding_text event take the
|
||||
before_cursor and after_cursor arguments into account for picking how
|
||||
much surrounding text to send.
|
||||
|
||||
There is a maximum length of wayland messages so text can not be
|
||||
longer than 4000 bytes.
|
||||
</description>
|
||||
<arg name="text" type="string"/>
|
||||
<arg name="cursor" type="int"/>
|
||||
<arg name="anchor" type="int"/>
|
||||
</request>
|
||||
|
||||
<enum name="content_hint" bitfield="true">
|
||||
<description summary="content hint">
|
||||
Content hint is a bitmask to allow to modify the behavior of the text
|
||||
input.
|
||||
</description>
|
||||
<entry name="none" value="0x0" summary="no special behaviour"/>
|
||||
<entry name="completion" value="0x1" summary="suggest word completions"/>
|
||||
<entry name="spellcheck" value="0x2" summary="suggest word corrections"/>
|
||||
<entry name="auto_capitalization" value="0x4" summary="switch to uppercase letters at the start of a sentence"/>
|
||||
<entry name="lowercase" value="0x8" summary="prefer lowercase letters"/>
|
||||
<entry name="uppercase" value="0x10" summary="prefer uppercase letters"/>
|
||||
<entry name="titlecase" value="0x20" summary="prefer casing for titles and headings (can be language dependent)"/>
|
||||
<entry name="hidden_text" value="0x40" summary="characters should be hidden"/>
|
||||
<entry name="sensitive_data" value="0x80" summary="typed text should not be stored"/>
|
||||
<entry name="latin" value="0x100" summary="just latin characters should be entered"/>
|
||||
<entry name="multiline" value="0x200" summary="the text input is multiline"/>
|
||||
</enum>
|
||||
|
||||
<enum name="content_purpose">
|
||||
<description summary="content purpose">
|
||||
The content purpose allows to specify the primary purpose of a text
|
||||
input.
|
||||
|
||||
This allows an input method to show special purpose input panels with
|
||||
extra characters or to disallow some characters.
|
||||
</description>
|
||||
<entry name="normal" value="0" summary="default input, allowing all characters"/>
|
||||
<entry name="alpha" value="1" summary="allow only alphabetic characters"/>
|
||||
<entry name="digits" value="2" summary="allow only digits"/>
|
||||
<entry name="number" value="3" summary="input a number (including decimal separator and sign)"/>
|
||||
<entry name="phone" value="4" summary="input a phone number"/>
|
||||
<entry name="url" value="5" summary="input an URL"/>
|
||||
<entry name="email" value="6" summary="input an email address"/>
|
||||
<entry name="name" value="7" summary="input a name of a person"/>
|
||||
<entry name="password" value="8" summary="input a password (combine with password or sensitive_data hint)"/>
|
||||
<entry name="pin" value="9" summary="input is a numeric password (combine with password or sensitive_data hint)"/>
|
||||
<entry name="date" value="10" summary="input a date"/>
|
||||
<entry name="time" value="11" summary="input a time"/>
|
||||
<entry name="datetime" value="12" summary="input a date and time"/>
|
||||
<entry name="terminal" value="13" summary="input for a terminal"/>
|
||||
</enum>
|
||||
|
||||
<request name="set_content_type">
|
||||
<description summary="set content purpose and hint">
|
||||
Sets the content purpose and content hint. While the purpose is the
|
||||
basic purpose of an input field, the hint flags allow to modify some
|
||||
of the behavior.
|
||||
|
||||
When no content type is explicitly set, a normal content purpose with
|
||||
none hint should be assumed.
|
||||
</description>
|
||||
<arg name="hint" type="uint" enum="content_hint"/>
|
||||
<arg name="purpose" type="uint" enum="content_purpose"/>
|
||||
</request>
|
||||
|
||||
<request name="set_cursor_rectangle">
|
||||
<description summary="set cursor position">
|
||||
Sets the cursor outline as a x, y, width, height rectangle in surface
|
||||
local coordinates.
|
||||
|
||||
Allows the compositor to put a window with word suggestions near the
|
||||
cursor.
|
||||
</description>
|
||||
<arg name="x" type="int"/>
|
||||
<arg name="y" type="int"/>
|
||||
<arg name="width" type="int"/>
|
||||
<arg name="height" type="int"/>
|
||||
</request>
|
||||
|
||||
<request name="commit_state">
|
||||
<description summary="commit state">
|
||||
Allows to atomically send state updates from client. The previous
|
||||
set_surrounding_text, set_content_type and set_cursor_rectangle
|
||||
become effective after this call.
|
||||
|
||||
Serial should be set to the serial from the last wp_text_input.enter
|
||||
event.
|
||||
|
||||
To make sure to not receive outdated input method events after a
|
||||
state update, wl_display_sync() should be called after making this
|
||||
request.
|
||||
</description>
|
||||
<arg name="serial" type="uint" summary="serial of the enter event"/>
|
||||
</request>
|
||||
|
||||
<event name="enter">
|
||||
<description summary="enter event">
|
||||
Notification that this seat's text-input focus is on a certain surface.
|
||||
|
||||
When the seat has the keyboard capability the text-input focus follows
|
||||
the keyboard focus.
|
||||
</description>
|
||||
<arg name="serial" type="uint" summary="serial"/>
|
||||
<arg name="surface" type="object" interface="wl_surface"/>
|
||||
</event>
|
||||
|
||||
<event name="leave">
|
||||
<description summary="leave event">
|
||||
Notification that this seat's text-input focus is no longer on
|
||||
a certain surface.
|
||||
|
||||
The leave notification is sent before the enter notification
|
||||
for the new focus.
|
||||
|
||||
When the seat has the keyboard capability the text-input focus follows
|
||||
the keyboard focus.
|
||||
</description>
|
||||
<arg name="serial" type="uint"/>
|
||||
<arg name="surface" type="object" interface="wl_surface"/>
|
||||
</event>
|
||||
|
||||
<event name="preedit_string">
|
||||
<description summary="pre-edit">
|
||||
Notify when a new composing text (pre-edit) should be set around the
|
||||
current cursor position. Any previously set composing text should
|
||||
be removed.
|
||||
</description>
|
||||
<arg name="text" type="string" allow-null="true"/>
|
||||
<arg name="cursor" type="uint"/>
|
||||
</event>
|
||||
|
||||
<event name="commit">
|
||||
<description summary="commit">
|
||||
Notify when text should be inserted into the editor widget. The text to
|
||||
commit could be either just a single character after a key press or the
|
||||
result of some composing (pre-edit).
|
||||
|
||||
The text argument could be also null if some text is removed (see
|
||||
gtk_text_input.delete_surrounding_text).
|
||||
|
||||
Any previously set composing text should be removed.
|
||||
</description>
|
||||
<arg name="text" type="string" allow-null="true"/>
|
||||
</event>
|
||||
|
||||
<event name="delete_surrounding_text">
|
||||
<description summary="delete surrounding text">
|
||||
Notify when the text around the current cursor position should be
|
||||
deleted. Before_length and after_length is the length (in bytes) of text
|
||||
before and after the current cursor position (excluding the selection)
|
||||
to delete.
|
||||
|
||||
This event should be handled as part of a following commit_string
|
||||
or preedit_string event.
|
||||
</description>
|
||||
<arg name="before_length" type="uint" summary="length of text before current cursor position"/>
|
||||
<arg name="after_length" type="uint" summary="length of text after current cursor position"/>
|
||||
</event>
|
||||
</interface>
|
||||
|
||||
<interface name="gtk_text_input_manager" version="1">
|
||||
<description summary="text input manager">
|
||||
A factory for text-input objects. This object is a global singleton.
|
||||
</description>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="Destroy the wp_text_input_manager">
|
||||
Destroy the wp_text_input_manager object.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<request name="get_text_input">
|
||||
<description summary="create a new text input object">
|
||||
Creates a new text-input object for a given seat.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="gtk_text_input"/>
|
||||
<arg name="seat" type="object" interface="wl_seat"/>
|
||||
</request>
|
||||
</interface>
|
||||
</protocol>
|
Reference in New Issue
Block a user