Make input context have multiple keyboards.
This commit is contained in:
@ -51,8 +51,14 @@ class Context(gobject.GObject):
|
|||||||
def get_giobject(self):
|
def get_giobject(self):
|
||||||
return self.__giobject
|
return self.__giobject
|
||||||
|
|
||||||
def set_keyboard(self, keyboard):
|
def add_keyboard(self, keyboard):
|
||||||
self.__giobject.set_keyboard(keyboard, None)
|
return self.__giobject.add_keyboard(keyboard, None)
|
||||||
|
|
||||||
|
def remove_keyboard(self, keyboard_id):
|
||||||
|
return self.__giobject.remove_keyboard(keyboard_id, None)
|
||||||
|
|
||||||
|
def set_keyboard(self, keyboard_id):
|
||||||
|
self.__giobject.set_keyboard(keyboard_id, None)
|
||||||
|
|
||||||
def show_keyboard(self):
|
def show_keyboard(self):
|
||||||
self.__giobject.show_keyboard(None)
|
self.__giobject.show_keyboard(None)
|
||||||
|
|||||||
@ -56,6 +56,7 @@ G_DEFINE_TYPE (EekboardContext, eekboard_context, G_TYPE_DBUS_PROXY);
|
|||||||
struct _EekboardContextPrivate
|
struct _EekboardContextPrivate
|
||||||
{
|
{
|
||||||
EekKeyboard *keyboard;
|
EekKeyboard *keyboard;
|
||||||
|
GHashTable *keyboard_hash;
|
||||||
gboolean keyboard_visible;
|
gboolean keyboard_visible;
|
||||||
gboolean enabled;
|
gboolean enabled;
|
||||||
};
|
};
|
||||||
@ -173,6 +174,11 @@ eekboard_context_dispose (GObject *self)
|
|||||||
g_object_unref (priv->keyboard);
|
g_object_unref (priv->keyboard);
|
||||||
priv->keyboard = NULL;
|
priv->keyboard = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (priv->keyboard_hash) {
|
||||||
|
g_hash_table_destroy (priv->keyboard_hash);
|
||||||
|
priv->keyboard_hash = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -293,6 +299,11 @@ eekboard_context_init (EekboardContext *self)
|
|||||||
priv->keyboard = NULL;
|
priv->keyboard = NULL;
|
||||||
priv->keyboard_visible = FALSE;
|
priv->keyboard_visible = FALSE;
|
||||||
priv->enabled = FALSE;
|
priv->enabled = FALSE;
|
||||||
|
priv->keyboard_hash =
|
||||||
|
g_hash_table_new_full (g_direct_hash,
|
||||||
|
g_direct_equal,
|
||||||
|
NULL,
|
||||||
|
(GDestroyNotify)g_object_unref);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -347,39 +358,127 @@ context_async_ready_callback (GObject *source_object,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* eekboard_context_set_keyboard:
|
* eekboard_context_add_keyboard:
|
||||||
* @context: an #EekboardContext
|
* @context: an #EekboardContext
|
||||||
* @keyboard: an #EekKeyboard
|
* @keyboard: an #EekKeyboard
|
||||||
* @cancellable: a #GCancellable
|
* @cancellable: a #GCancellable
|
||||||
*
|
*
|
||||||
* Set the keyboard description of @context to @keyboard.
|
* Register @keyboard in @context.
|
||||||
*/
|
*/
|
||||||
void
|
guint
|
||||||
eekboard_context_set_keyboard (EekboardContext *context,
|
eekboard_context_add_keyboard (EekboardContext *context,
|
||||||
EekKeyboard *keyboard,
|
EekKeyboard *keyboard,
|
||||||
GCancellable *cancellable)
|
GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
EekboardContextPrivate *priv;
|
EekboardContextPrivate *priv;
|
||||||
GVariant *variant;
|
GVariant *variant, *result;
|
||||||
|
GError *error;
|
||||||
|
|
||||||
|
g_return_val_if_fail (EEKBOARD_IS_CONTEXT(context), 0);
|
||||||
|
g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), 0);
|
||||||
|
|
||||||
|
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
|
||||||
|
|
||||||
|
variant = eek_serializable_serialize (EEK_SERIALIZABLE(keyboard));
|
||||||
|
|
||||||
|
error = NULL;
|
||||||
|
result = g_dbus_proxy_call_sync (G_DBUS_PROXY(context),
|
||||||
|
"AddKeyboard",
|
||||||
|
g_variant_new ("(v)", variant),
|
||||||
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
|
-1,
|
||||||
|
cancellable,
|
||||||
|
&error);
|
||||||
|
g_variant_unref (variant);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
guint keyboard_id;
|
||||||
|
|
||||||
|
g_variant_get (result, "(u)", &keyboard_id);
|
||||||
|
g_variant_unref (result);
|
||||||
|
|
||||||
|
if (keyboard_id != 0) {
|
||||||
|
g_hash_table_insert (priv->keyboard_hash,
|
||||||
|
GUINT_TO_POINTER(keyboard_id),
|
||||||
|
g_object_ref (keyboard));
|
||||||
|
}
|
||||||
|
return keyboard_id;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* eekboard_context_remove_keyboard:
|
||||||
|
* @context: an #EekboardContext
|
||||||
|
* @keyboard_id: keyboard ID
|
||||||
|
* @cancellable: a #GCancellable
|
||||||
|
*
|
||||||
|
* Unregister the keyboard with @keyboard_id in @context.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
eekboard_context_remove_keyboard (EekboardContext *context,
|
||||||
|
guint keyboard_id,
|
||||||
|
GCancellable *cancellable)
|
||||||
|
{
|
||||||
|
EekboardContextPrivate *priv;
|
||||||
|
EekKeyboard *keyboard;
|
||||||
|
|
||||||
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
|
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
|
||||||
g_return_if_fail (EEK_IS_KEYBOARD(keyboard));
|
|
||||||
|
|
||||||
priv = EEKBOARD_CONTEXT_GET_PRIVATE(context);
|
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
|
||||||
if (priv->keyboard)
|
|
||||||
g_object_unref (priv->keyboard);
|
keyboard = g_hash_table_lookup (priv->keyboard_hash,
|
||||||
priv->keyboard = g_object_ref (keyboard);
|
GUINT_TO_POINTER(keyboard_id));
|
||||||
|
if (keyboard == priv->keyboard)
|
||||||
|
priv->keyboard = NULL;
|
||||||
|
|
||||||
|
g_hash_table_remove (priv->keyboard_hash, GUINT_TO_POINTER(keyboard_id));
|
||||||
|
|
||||||
variant = eek_serializable_serialize (EEK_SERIALIZABLE(priv->keyboard));
|
|
||||||
g_dbus_proxy_call (G_DBUS_PROXY(context),
|
g_dbus_proxy_call (G_DBUS_PROXY(context),
|
||||||
"SetKeyboard",
|
"RemoveKeyboard",
|
||||||
g_variant_new ("(v)", variant),
|
g_variant_new ("(u)", keyboard_id),
|
||||||
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
|
-1,
|
||||||
|
cancellable,
|
||||||
|
context_async_ready_callback,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* eekboard_context_set_keyboard:
|
||||||
|
* @context: an #EekboardContext
|
||||||
|
* @keyboard_id: keyboard ID
|
||||||
|
* @cancellable: a #GCancellable
|
||||||
|
*
|
||||||
|
* Select a keyboard with ID @keyboard_id in @context.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
eekboard_context_set_keyboard (EekboardContext *context,
|
||||||
|
guint keyboard_id,
|
||||||
|
GCancellable *cancellable)
|
||||||
|
{
|
||||||
|
EekboardContextPrivate *priv;
|
||||||
|
EekKeyboard *keyboard;
|
||||||
|
|
||||||
|
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
|
||||||
|
|
||||||
|
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
|
||||||
|
|
||||||
|
keyboard = g_hash_table_lookup (priv->keyboard_hash,
|
||||||
|
GUINT_TO_POINTER(keyboard_id));
|
||||||
|
if (!keyboard || keyboard == priv->keyboard)
|
||||||
|
return;
|
||||||
|
|
||||||
|
priv->keyboard = keyboard;
|
||||||
|
|
||||||
|
g_dbus_proxy_call (G_DBUS_PROXY(context),
|
||||||
|
"SetKeyboard",
|
||||||
|
g_variant_new ("(u)", keyboard_id),
|
||||||
G_DBUS_CALL_FLAGS_NONE,
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
-1,
|
-1,
|
||||||
cancellable,
|
cancellable,
|
||||||
context_async_ready_callback,
|
context_async_ready_callback,
|
||||||
NULL);
|
NULL);
|
||||||
g_variant_unref (variant);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -77,9 +77,16 @@ GType eekboard_context_get_type (void) G_GNUC_CONST;
|
|||||||
EekboardContext *eekboard_context_new (GDBusConnection *connection,
|
EekboardContext *eekboard_context_new (GDBusConnection *connection,
|
||||||
const gchar *object_path,
|
const gchar *object_path,
|
||||||
GCancellable *cancellable);
|
GCancellable *cancellable);
|
||||||
void eekboard_context_set_keyboard (EekboardContext *context,
|
guint eekboard_context_add_keyboard (EekboardContext *context,
|
||||||
EekKeyboard *keyboard,
|
EekKeyboard *keyboard,
|
||||||
GCancellable *cancellable);
|
GCancellable *cancellable);
|
||||||
|
void eekboard_context_remove_keyboard
|
||||||
|
(EekboardContext *context,
|
||||||
|
guint keyboard_id,
|
||||||
|
GCancellable *cancellable);
|
||||||
|
void eekboard_context_set_keyboard (EekboardContext *context,
|
||||||
|
guint keyboard_id,
|
||||||
|
GCancellable *cancellable);
|
||||||
void eekboard_context_show_keyboard (EekboardContext *context,
|
void eekboard_context_show_keyboard (EekboardContext *context,
|
||||||
GCancellable *cancellable);
|
GCancellable *cancellable);
|
||||||
void eekboard_context_hide_keyboard (EekboardContext *context,
|
void eekboard_context_hide_keyboard (EekboardContext *context,
|
||||||
|
|||||||
@ -151,6 +151,7 @@ main (int argc, char **argv)
|
|||||||
GFileInputStream *input;
|
GFileInputStream *input;
|
||||||
EekLayout *layout;
|
EekLayout *layout;
|
||||||
EekKeyboard *keyboard;
|
EekKeyboard *keyboard;
|
||||||
|
guint keyboard_id;
|
||||||
|
|
||||||
file = g_file_new_for_path (opt_set_keyboard);
|
file = g_file_new_for_path (opt_set_keyboard);
|
||||||
|
|
||||||
@ -168,8 +169,10 @@ main (int argc, char **argv)
|
|||||||
keyboard = eek_keyboard_new (layout, 640, 480);
|
keyboard = eek_keyboard_new (layout, 640, 480);
|
||||||
g_object_unref (layout);
|
g_object_unref (layout);
|
||||||
|
|
||||||
eekboard_context_set_keyboard (context, keyboard, NULL);
|
keyboard_id = eekboard_context_add_keyboard (context, keyboard, NULL);
|
||||||
g_object_unref (keyboard);
|
g_object_unref (keyboard);
|
||||||
|
|
||||||
|
eekboard_context_set_keyboard (context, keyboard_id, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt_set_group >= 0) {
|
if (opt_set_group >= 0) {
|
||||||
|
|||||||
@ -474,6 +474,7 @@ set_keyboard (EekboardDesktopClient *client,
|
|||||||
EekLayout *layout;
|
EekLayout *layout;
|
||||||
gchar *keyboard_name;
|
gchar *keyboard_name;
|
||||||
static gint keyboard_serial = 0;
|
static gint keyboard_serial = 0;
|
||||||
|
guint keyboard_id;
|
||||||
|
|
||||||
if (client->keyboard)
|
if (client->keyboard)
|
||||||
g_object_unref (client->keyboard);
|
g_object_unref (client->keyboard);
|
||||||
@ -485,7 +486,10 @@ set_keyboard (EekboardDesktopClient *client,
|
|||||||
keyboard_name = g_strdup_printf ("keyboard%d", keyboard_serial++);
|
keyboard_name = g_strdup_printf ("keyboard%d", keyboard_serial++);
|
||||||
eek_element_set_name (EEK_ELEMENT(client->keyboard), keyboard_name);
|
eek_element_set_name (EEK_ELEMENT(client->keyboard), keyboard_name);
|
||||||
|
|
||||||
eekboard_context_set_keyboard (client->context, client->keyboard, NULL);
|
keyboard_id = eekboard_context_add_keyboard (client->context,
|
||||||
|
client->keyboard,
|
||||||
|
NULL);
|
||||||
|
eekboard_context_set_keyboard (client->context, keyboard_id, NULL);
|
||||||
if (show)
|
if (show)
|
||||||
eekboard_context_show_keyboard (client->context, NULL);
|
eekboard_context_show_keyboard (client->context, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,8 +46,15 @@ enum {
|
|||||||
static const gchar introspection_xml[] =
|
static const gchar introspection_xml[] =
|
||||||
"<node>"
|
"<node>"
|
||||||
" <interface name='com.redhat.Eekboard.Context'>"
|
" <interface name='com.redhat.Eekboard.Context'>"
|
||||||
|
" <method name='AddKeyboard'>"
|
||||||
|
" <arg direction='in' type='v' name='keyboard'/>"
|
||||||
|
" <arg direction='out' type='u' name='keyboard_id'/>"
|
||||||
|
" </method>"
|
||||||
|
" <method name='RemoveKeyboard'>"
|
||||||
|
" <arg direction='in' type='u' name='keyboard_id'/>"
|
||||||
|
" </method>"
|
||||||
" <method name='SetKeyboard'>"
|
" <method name='SetKeyboard'>"
|
||||||
" <arg type='v' name='keyboard'/>"
|
" <arg type='u' name='keyboard_id'/>"
|
||||||
" </method>"
|
" </method>"
|
||||||
" <method name='ShowKeyboard'/>"
|
" <method name='ShowKeyboard'/>"
|
||||||
" <method name='HideKeyboard'/>"
|
" <method name='HideKeyboard'/>"
|
||||||
@ -90,7 +97,9 @@ struct _ServerContext {
|
|||||||
|
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
|
guint keyboard_id;
|
||||||
EekKeyboard *keyboard;
|
EekKeyboard *keyboard;
|
||||||
|
GHashTable *keyboard_hash;
|
||||||
|
|
||||||
gulong key_pressed_handler;
|
gulong key_pressed_handler;
|
||||||
gulong key_released_handler;
|
gulong key_released_handler;
|
||||||
@ -264,10 +273,14 @@ server_context_dispose (GObject *object)
|
|||||||
|
|
||||||
if (context->keyboard) {
|
if (context->keyboard) {
|
||||||
disconnect_keyboard_signals (context);
|
disconnect_keyboard_signals (context);
|
||||||
g_object_unref (context->keyboard);
|
|
||||||
context->keyboard = NULL;
|
context->keyboard = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context->keyboard_hash) {
|
||||||
|
g_hash_table_destroy (context->keyboard_hash);
|
||||||
|
context->keyboard_hash = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (context->window) {
|
if (context->window) {
|
||||||
gtk_widget_destroy (context->window);
|
gtk_widget_destroy (context->window);
|
||||||
context->window = NULL;
|
context->window = NULL;
|
||||||
@ -367,6 +380,12 @@ server_context_init (ServerContext *context)
|
|||||||
context->last_keyboard_visible = FALSE;
|
context->last_keyboard_visible = FALSE;
|
||||||
|
|
||||||
context->keyboard = NULL;
|
context->keyboard = NULL;
|
||||||
|
context->keyboard_hash =
|
||||||
|
g_hash_table_new_full (g_direct_hash,
|
||||||
|
g_direct_equal,
|
||||||
|
NULL,
|
||||||
|
(GDestroyNotify)g_object_unref);
|
||||||
|
|
||||||
context->widget = NULL;
|
context->widget = NULL;
|
||||||
context->window = NULL;
|
context->window = NULL;
|
||||||
context->key_pressed_handler = 0;
|
context->key_pressed_handler = 0;
|
||||||
@ -444,11 +463,13 @@ handle_method_call (GDBusConnection *connection,
|
|||||||
{
|
{
|
||||||
ServerContext *context = user_data;
|
ServerContext *context = user_data;
|
||||||
|
|
||||||
if (g_strcmp0 (method_name, "SetKeyboard") == 0) {
|
if (g_strcmp0 (method_name, "AddKeyboard") == 0) {
|
||||||
EekSerializable *serializable;
|
|
||||||
GVariant *variant;
|
GVariant *variant;
|
||||||
|
EekSerializable *serializable;
|
||||||
|
static guint keyboard_id = 0;
|
||||||
|
|
||||||
g_variant_get (parameters, "(v)", &variant);
|
g_variant_get (parameters, "(v)", &variant);
|
||||||
|
|
||||||
serializable = eek_serializable_deserialize (variant);
|
serializable = eek_serializable_deserialize (variant);
|
||||||
if (!EEK_IS_KEYBOARD(serializable)) {
|
if (!EEK_IS_KEYBOARD(serializable)) {
|
||||||
g_dbus_method_invocation_return_error (invocation,
|
g_dbus_method_invocation_return_error (invocation,
|
||||||
@ -457,9 +478,65 @@ handle_method_call (GDBusConnection *connection,
|
|||||||
"not a keyboard");
|
"not a keyboard");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
eek_keyboard_set_modifier_behavior (EEK_KEYBOARD(serializable),
|
||||||
|
EEK_MODIFIER_BEHAVIOR_LATCH);
|
||||||
|
|
||||||
|
g_hash_table_insert (context->keyboard_hash,
|
||||||
|
GUINT_TO_POINTER(++keyboard_id),
|
||||||
|
g_object_ref (serializable));
|
||||||
|
g_dbus_method_invocation_return_value (invocation,
|
||||||
|
g_variant_new ("(u)",
|
||||||
|
keyboard_id));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_strcmp0 (method_name, "RemoveKeyboard") == 0) {
|
||||||
|
guint keyboard_id;
|
||||||
|
|
||||||
|
g_variant_get (parameters, "(u)", &keyboard_id);
|
||||||
|
|
||||||
|
if (keyboard_id == context->keyboard_id) {
|
||||||
|
disconnect_keyboard_signals (context);
|
||||||
|
if (context->window) {
|
||||||
|
gtk_widget_hide (context->window);
|
||||||
|
gtk_widget_destroy (context->widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
context->keyboard = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_hash_table_remove (context->keyboard_hash,
|
||||||
|
GUINT_TO_POINTER(keyboard_id));
|
||||||
|
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_strcmp0 (method_name, "SetKeyboard") == 0) {
|
||||||
|
EekKeyboard *keyboard;
|
||||||
|
guint keyboard_id;
|
||||||
|
|
||||||
|
g_variant_get (parameters, "(u)", &keyboard_id);
|
||||||
|
|
||||||
|
keyboard = g_hash_table_lookup (context->keyboard_hash,
|
||||||
|
GUINT_TO_POINTER(keyboard_id));
|
||||||
|
if (!keyboard) {
|
||||||
|
g_dbus_method_invocation_return_error (invocation,
|
||||||
|
G_IO_ERROR,
|
||||||
|
G_IO_ERROR_FAILED_HANDLED,
|
||||||
|
"no such keyboard");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyboard == context->keyboard) {
|
||||||
|
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context->keyboard)
|
||||||
|
disconnect_keyboard_signals (context);
|
||||||
|
|
||||||
|
context->keyboard = keyboard;
|
||||||
|
|
||||||
context->keyboard = EEK_KEYBOARD(serializable);
|
|
||||||
disconnect_keyboard_signals (context);
|
|
||||||
context->key_pressed_handler =
|
context->key_pressed_handler =
|
||||||
g_signal_connect (context->keyboard, "key-pressed",
|
g_signal_connect (context->keyboard, "key-pressed",
|
||||||
G_CALLBACK(on_key_pressed),
|
G_CALLBACK(on_key_pressed),
|
||||||
@ -468,8 +545,6 @@ handle_method_call (GDBusConnection *connection,
|
|||||||
g_signal_connect (context->keyboard, "key-released",
|
g_signal_connect (context->keyboard, "key-released",
|
||||||
G_CALLBACK(on_key_released),
|
G_CALLBACK(on_key_released),
|
||||||
context);
|
context);
|
||||||
eek_keyboard_set_modifier_behavior (context->keyboard,
|
|
||||||
EEK_MODIFIER_BEHAVIOR_LATCH);
|
|
||||||
|
|
||||||
if (context->window) {
|
if (context->window) {
|
||||||
gboolean was_visible = gtk_widget_get_visible (context->window);
|
gboolean was_visible = gtk_widget_get_visible (context->window);
|
||||||
|
|||||||
Reference in New Issue
Block a user