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

@ -21,6 +21,21 @@
<summary>Delay seconds before hiding keyboard</summary> <summary>Delay seconds before hiding keyboard</summary>
<description>Delay seconds before hiding keyboard. This is useful when focus listener is enabled.</description> <description>Delay seconds before hiding keyboard. This is useful when focus listener is enabled.</description>
</key> </key>
<key type="b" name="repeat">
<default>true</default>
<summary>Key repeat</summary>
<description>Generate key-press/release event repeatedly while a key is held down</description>
</key>
<key type="i" name="repeat-interval">
<default>30</default>
<summary>Key repeat interval</summary>
<description>Delay between repeats in milliseconds.</description>
</key>
<key type="i" name="repeat-delay">
<default>500</default>
<summary>Initial key repeat delay</summary>
<description>Initial key repeat delay in milliseconds.</description>
</key>
<key name="start-fullscreen" type="b"> <key name="start-fullscreen" type="b">
<default>false</default> <default>false</default>
<summary>Switch to fullscreen mode when startup</summary> <summary>Switch to fullscreen mode when startup</summary>

View File

@ -120,6 +120,9 @@ struct _ServerContext {
gulong key_released_handler; gulong key_released_handler;
gulong notify_visible_handler; gulong notify_visible_handler;
EekKey *repeat_key;
guint repeat_timeout_id;
GSettings *settings; GSettings *settings;
ServerContextUIToolkitType ui_toolkit; ServerContextUIToolkitType ui_toolkit;
}; };
@ -584,6 +587,9 @@ server_context_init (ServerContext *context)
context->key_pressed_handler = 0; context->key_pressed_handler = 0;
context->key_released_handler = 0; context->key_released_handler = 0;
context->repeat_key = NULL;
context->repeat_timeout_id = 0;
context->ui_toolkit = UI_TOOLKIT_DEFAULT; context->ui_toolkit = UI_TOOLKIT_DEFAULT;
context->settings = g_settings_new ("org.fedorahosted.eekboard"); context->settings = g_settings_new ("org.fedorahosted.eekboard");
@ -598,6 +604,45 @@ server_context_init (ServerContext *context)
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 static void
on_key_pressed (EekKeyboard *keyboard, on_key_pressed (EekKeyboard *keyboard,
EekKey *key, EekKey *key,
@ -605,6 +650,11 @@ on_key_pressed (EekKeyboard *keyboard,
{ {
ServerContext *context = user_data; 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) { if (context->connection && context->enabled) {
guint keycode = eek_key_get_keycode (key); guint keycode = eek_key_get_keycode (key);
GError *error; GError *error;
@ -618,6 +668,15 @@ on_key_pressed (EekKeyboard *keyboard,
g_variant_new ("(u)", keycode), g_variant_new ("(u)", keycode),
&error); &error);
g_assert_no_error (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; 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) { if (context->connection && context->enabled) {
guint keycode = eek_key_get_keycode (key); guint keycode = eek_key_get_keycode (key);
GError *error; GError *error;