Commit 50e9f318 authored by Daiki Ueno's avatar Daiki Ueno
Browse files

Tune input context suspend/resume behavior.

parent d25114b3
......@@ -415,3 +415,14 @@ eekboard_context_set_enabled (EekboardContext *context,
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
priv->enabled = enabled;
}
gboolean
eekboard_context_is_enabled (EekboardContext *context)
{
EekboardContextPrivate *priv;
g_assert (EEKBOARD_IS_CONTEXT(context));
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
return priv->enabled;
}
......@@ -76,6 +76,7 @@ gboolean eekboard_context_is_keyboard_visible
(EekboardContext *context);
void eekboard_context_set_enabled (EekboardContext *context,
gboolean enabled);
gboolean eekboard_context_is_enabled (EekboardContext *context);
G_END_DECLS
#endif /* EEKBOARD_CONTEXT_H */
......@@ -29,30 +29,18 @@ G_DEFINE_TYPE (EekboardServer, eekboard_server, G_TYPE_DBUS_PROXY);
struct _EekboardServerPrivate
{
GHashTable *context_hash;
GSList *context_stack;
/* used in eekboard_server_push_context and
eekboard_server_destroy_context as a callback data */
EekboardContext *context;
};
static void
eekboard_server_dispose (GObject *object)
{
EekboardServerPrivate *priv = EEKBOARD_SERVER_GET_PRIVATE(object);
GSList *head;
if (priv->context_hash) {
g_hash_table_destroy (priv->context_hash);
priv->context_hash = NULL;
}
for (head = priv->context_stack; head; head = priv->context_stack) {
g_object_unref (head->data);
priv->context_stack = g_slist_next (head);
g_slist_free1 (head);
}
G_OBJECT_CLASS (eekboard_server_parent_class)->dispose (object);
}
......@@ -78,8 +66,6 @@ eekboard_server_init (EekboardServer *self)
g_str_equal,
(GDestroyNotify)g_free,
(GDestroyNotify)g_object_unref);
priv->context_stack = NULL;
priv->context = NULL;
}
EekboardServer *
......@@ -141,33 +127,25 @@ eekboard_server_create_context (EekboardServer *server,
}
priv = EEKBOARD_SERVER_GET_PRIVATE(server);
g_hash_table_insert (priv->context_hash, g_strdup (object_path), context);
g_hash_table_insert (priv->context_hash,
g_strdup (object_path),
g_object_ref (context));
return context;
}
static void
push_context_async_ready_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
server_async_ready_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
EekboardServer *server = user_data;
EekboardServerPrivate *priv = EEKBOARD_SERVER_GET_PRIVATE(server);
GError *error = NULL;
GVariant *result;
result = g_dbus_proxy_call_finish (G_DBUS_PROXY(source_object),
res,
&error);
if (result) {
if (result)
g_variant_unref (result);
if (priv->context_stack)
eekboard_context_set_enabled (priv->context_stack->data, FALSE);
priv->context_stack = g_slist_prepend (priv->context_stack,
priv->context);
g_object_ref (priv->context);
eekboard_context_set_enabled (priv->context, TRUE);
}
}
void
......@@ -188,43 +166,15 @@ eekboard_server_push_context (EekboardServer *server,
if (!context)
return;
priv->context = context;
eekboard_context_set_enabled (context, TRUE);
g_dbus_proxy_call (G_DBUS_PROXY(server),
"PushContext",
g_variant_new ("(s)", object_path),
G_DBUS_CALL_FLAGS_NONE,
-1,
cancellable,
push_context_async_ready_callback,
server);
}
static void
pop_context_async_ready_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
EekboardServer *server = user_data;
EekboardServerPrivate *priv = EEKBOARD_SERVER_GET_PRIVATE(server);
GError *error = NULL;
GVariant *result;
result = g_dbus_proxy_call_finish (G_DBUS_PROXY(source_object),
res,
&error);
if (result) {
g_variant_unref (result);
if (priv->context_stack) {
EekboardContext *context = priv->context_stack->data;
eekboard_context_set_enabled (context, FALSE);
priv->context_stack = g_slist_next (priv->context_stack);
g_object_unref (context);
if (priv->context_stack)
eekboard_context_set_enabled (priv->context_stack->data, TRUE);
}
}
server_async_ready_callback,
NULL);
}
void
......@@ -239,39 +189,8 @@ eekboard_server_pop_context (EekboardServer *server,
G_DBUS_CALL_FLAGS_NONE,
-1,
cancellable,
pop_context_async_ready_callback,
server);
}
static void
destroy_context_async_ready_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
EekboardServer *server = user_data;
EekboardServerPrivate *priv = EEKBOARD_SERVER_GET_PRIVATE(server);
GError *error = NULL;
GVariant *result;
const gchar *object_path;
GSList *head;
result = g_dbus_proxy_call_finish (G_DBUS_PROXY(source_object),
res,
&error);
if (result) {
g_variant_unref (result);
head = g_slist_find (priv->context_stack, priv->context);
if (head) {
priv->context_stack = g_slist_remove_link (priv->context_stack,
head);
g_slist_free1 (head);
}
object_path =
g_dbus_proxy_get_object_path (G_DBUS_PROXY(priv->context));
g_hash_table_remove (priv->context_hash, object_path);
}
server_async_ready_callback,
NULL);
}
void
......@@ -285,16 +204,17 @@ eekboard_server_destroy_context (EekboardServer *server,
g_return_if_fail (EEKBOARD_IS_SERVER(server));
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
priv = EEKBOARD_SERVER_GET_PRIVATE(server);
object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY(context));
g_hash_table_remove (priv->context_hash, object_path);
priv = EEKBOARD_SERVER_GET_PRIVATE(server);
priv->context = context;
g_dbus_proxy_call (G_DBUS_PROXY(server),
"DestroyContext",
g_variant_new ("(s)", object_path),
G_DBUS_CALL_FLAGS_NONE,
-1,
cancellable,
destroy_context_async_ready_callback,
server);
server_async_ready_callback,
NULL);
}
......@@ -84,6 +84,7 @@ struct _ServerContext {
char *object_path;
gboolean enabled;
gboolean last_keyboard_visible;
GtkWidget *window;
GtkWidget *widget;
......@@ -347,6 +348,9 @@ server_context_init (ServerContext *context)
context->registration_id = 0;
context->object_path = NULL;
context->enabled = FALSE;
context->last_keyboard_visible = FALSE;
context->keyboard = NULL;
context->widget = NULL;
context->window = NULL;
......@@ -429,11 +433,6 @@ handle_method_call (GDBusConnection *connection,
EekSerializable *serializable;
GVariant *variant;
if (!context->enabled) {
g_dbus_method_invocation_return_value (invocation, NULL);
return;
}
g_variant_get (parameters, "(v)", &variant);
serializable = eek_serializable_deserialize (variant);
if (!EEK_IS_KEYBOARD(serializable)) {
......@@ -471,11 +470,6 @@ handle_method_call (GDBusConnection *connection,
if (g_strcmp0 (method_name, "SetGroup") == 0) {
gint group;
if (!context->enabled) {
g_dbus_method_invocation_return_value (invocation, NULL);
return;
}
if (!context->keyboard) {
g_dbus_method_invocation_return_error (invocation,
G_IO_ERROR,
......@@ -527,11 +521,6 @@ handle_method_call (GDBusConnection *connection,
EekKey *key;
guint keycode;
if (!context->enabled) {
g_dbus_method_invocation_return_value (invocation, NULL);
return;
}
if (!context->keyboard) {
g_dbus_method_invocation_return_error (invocation,
G_IO_ERROR,
......@@ -604,6 +593,8 @@ server_context_set_enabled (ServerContext *context, gboolean enabled)
NULL,
&error);
g_assert_no_error (error);
if (context->last_keyboard_visible && context->window)
gtk_widget_show_all (context->window);
} else {
error = NULL;
g_dbus_connection_emit_signal (context->connection,
......@@ -614,6 +605,11 @@ server_context_set_enabled (ServerContext *context, gboolean enabled)
NULL,
&error);
g_assert_no_error (error);
if (context->window) {
context->last_keyboard_visible =
gtk_widget_get_visible (context->window);
gtk_widget_hide (context->window);
}
}
context->enabled = enabled;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment