Support key repeat.

This commit is contained in:
Daiki Ueno
2011-08-15 15:18:52 +09:00
parent 20c1f8cbe3
commit 0e0fe9ed51
2 changed files with 79 additions and 0 deletions

View File

@ -120,6 +120,9 @@ struct _ServerContext {
gulong key_released_handler;
gulong notify_visible_handler;
EekKey *repeat_key;
guint repeat_timeout_id;
GSettings *settings;
ServerContextUIToolkitType ui_toolkit;
};
@ -584,6 +587,9 @@ server_context_init (ServerContext *context)
context->key_pressed_handler = 0;
context->key_released_handler = 0;
context->repeat_key = NULL;
context->repeat_timeout_id = 0;
context->ui_toolkit = UI_TOOLKIT_DEFAULT;
context->settings = g_settings_new ("org.fedorahosted.eekboard");
@ -598,6 +604,45 @@ server_context_init (ServerContext *context)
context);
}
static gboolean on_repeat_timeout (ServerContext *context);
static gboolean
on_repeat_timeout (ServerContext *context)
{
if (context->connection && context->enabled) {
guint keycode = eek_key_get_keycode (context->repeat_key);
GError *error;
error = NULL;
g_dbus_connection_emit_signal (context->connection,
NULL,
context->object_path,
SERVER_CONTEXT_INTERFACE,
"KeyPressed",
g_variant_new ("(u)", keycode),
&error);
g_assert_no_error (error);
error = NULL;
g_dbus_connection_emit_signal (context->connection,
NULL,
context->object_path,
SERVER_CONTEXT_INTERFACE,
"KeyReleased",
g_variant_new ("(u)", keycode),
&error);
g_assert_no_error (error);
gint delay = g_settings_get_int (context->settings, "repeat-interval");
context->repeat_timeout_id =
g_timeout_add (delay,
(GSourceFunc)on_repeat_timeout,
context);
}
return FALSE;
}
static void
on_key_pressed (EekKeyboard *keyboard,
EekKey *key,
@ -605,6 +650,11 @@ on_key_pressed (EekKeyboard *keyboard,
{
ServerContext *context = user_data;
if (context->repeat_timeout_id) {
g_source_remove (context->repeat_timeout_id);
context->repeat_timeout_id = 0;
}
if (context->connection && context->enabled) {
guint keycode = eek_key_get_keycode (key);
GError *error;
@ -618,6 +668,15 @@ on_key_pressed (EekKeyboard *keyboard,
g_variant_new ("(u)", keycode),
&error);
g_assert_no_error (error);
if (g_settings_get_boolean (context->settings, "repeat")) {
gint delay = g_settings_get_int (context->settings, "repeat-delay");
context->repeat_key = key;
context->repeat_timeout_id =
g_timeout_add (delay,
(GSourceFunc)on_repeat_timeout,
context);
}
}
}
@ -628,6 +687,11 @@ on_key_released (EekKeyboard *keyboard,
{
ServerContext *context = user_data;
if (context->repeat_timeout_id) {
g_source_remove (context->repeat_timeout_id);
context->repeat_timeout_id = 0;
}
if (context->connection && context->enabled) {
guint keycode = eek_key_get_keycode (key);
GError *error;