Commit 0e0fe9ed authored by Daiki Ueno's avatar Daiki Ueno
Browse files

Support key repeat.

parent 20c1f8cb
......@@ -21,6 +21,21 @@
<summary>Delay seconds before hiding keyboard</summary>
<description>Delay seconds before hiding keyboard. This is useful when focus listener is enabled.</description>
</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">
<default>false</default>
<summary>Switch to fullscreen mode when startup</summary>
......
......@@ -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;
......
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