Commit 2831d58d authored by Daiki Ueno's avatar Daiki Ueno
Browse files

Reimplement keystroke listener.

parent eb646ff7
......@@ -42,6 +42,8 @@ Access to the D-Bus server:
KeyPressed XXXXX
KeyReleased XXXXX
$ ./src/eekboard-client --set-group 1
$ ./src/eekboard-client --press-key 65
$ ./src/eekboard-client --release-key 65
Listen and follow the system events:
......
......@@ -25,6 +25,8 @@ static gchar *opt_set_keyboard = NULL;
static gint opt_set_group = -1;
static gboolean opt_show = FALSE;
static gboolean opt_hide = FALSE;
static gint opt_press_key = -1;
static gint opt_release_key = -1;
static gboolean opt_listen = FALSE;
static const GOptionEntry options[] = {
......@@ -36,6 +38,10 @@ static const GOptionEntry options[] = {
"Show keyboard"},
{"hide", '\0', 0, G_OPTION_ARG_NONE, &opt_hide,
"Hide keyboard"},
{"press-key", '\0', 0, G_OPTION_ARG_INT, &opt_press_key,
"Press key"},
{"release-key", '\0', 0, G_OPTION_ARG_INT, &opt_release_key,
"Release key"},
{"listen", '\0', 0, G_OPTION_ARG_NONE, &opt_listen,
"Listen events"},
{NULL}
......@@ -127,6 +133,14 @@ main (int argc, char **argv)
eekboard_proxy_hide (proxy);
}
if (opt_press_key >= 0) {
eekboard_proxy_press_key (proxy, opt_press_key);
}
if (opt_release_key >= 0) {
eekboard_proxy_release_key (proxy, opt_release_key);
}
if (opt_listen) {
g_signal_connect (proxy, "key-pressed",
G_CALLBACK(on_key_pressed), NULL);
......
......@@ -142,9 +142,9 @@ proxy_call_async_ready_cb (GObject *source_object,
result = g_dbus_proxy_call_finish (G_DBUS_PROXY(source_object),
res,
&error);
g_assert_no_error (error);
g_assert (result != NULL);
g_variant_unref (result);
// g_assert_no_error (error);
if (result)
g_variant_unref (result);
}
void
......@@ -210,3 +210,31 @@ eekboard_proxy_hide (EekboardProxy *proxy)
proxy_call_async_ready_cb,
NULL);
}
void
eekboard_proxy_press_key (EekboardProxy *proxy,
guint keycode)
{
g_dbus_proxy_call (G_DBUS_PROXY(proxy),
"PressKey",
g_variant_new ("(u)", keycode),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
NULL);
}
void
eekboard_proxy_release_key (EekboardProxy *proxy,
guint keycode)
{
g_dbus_proxy_call (G_DBUS_PROXY(proxy),
"ReleaseKey",
g_variant_new ("(u)", keycode),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
NULL);
}
......@@ -43,6 +43,10 @@ void eekboard_proxy_set_group (EekboardProxy *proxy,
gint group);
void eekboard_proxy_show (EekboardProxy *proxy);
void eekboard_proxy_hide (EekboardProxy *proxy);
void eekboard_proxy_press_key (EekboardProxy *proxy,
guint keycode);
void eekboard_proxy_release_key (EekboardProxy *proxy,
guint keycode);
G_END_DECLS
#endif /* EEKBOARD_PROXY_H */
......@@ -53,10 +53,10 @@ static const gchar introspection_xml[] =
" <method name='Show'/>"
" <method name='Hide'/>"
" <method name='PressKey'>"
" <arg type='s' name='key_id' direction='in'/>"
" <arg type='u' name='keycode'/>"
" </method>"
" <method name='ReleaseKey'>"
" <arg type='s' name='key_id' direction='in'/>"
" <arg type='u' name='keycode'/>"
" </method>"
" <signal name='KeyPressed'>"
" <arg type='u' name='keycode'/>"
......@@ -401,6 +401,49 @@ handle_method_call (GDBusConnection *connection,
return;
}
if (g_strcmp0 (method_name, "PressKey") == 0 ||
g_strcmp0 (method_name, "ReleaseKey") == 0) {
EekKey *key;
guint keycode;
if (!server->keyboard) {
g_dbus_method_invocation_return_error (invocation,
G_IO_ERROR,
G_IO_ERROR_FAILED_HANDLED,
"keyboard is not set");
return;
}
g_variant_get (parameters, "(u)", &keycode);
key = eek_keyboard_find_key_by_keycode (server->keyboard, keycode);
if (!key) {
g_dbus_method_invocation_return_error (invocation,
G_IO_ERROR,
G_IO_ERROR_FAILED_HANDLED,
"key for %u is not found",
keycode);
return;
}
if (g_strcmp0 (method_name, "PressKey") == 0) {
g_signal_handler_block (server->keyboard,
server->key_pressed_handler);
g_signal_emit_by_name (key, "pressed");
g_signal_handler_unblock (server->keyboard,
server->key_pressed_handler);
} else {
g_signal_handler_block (server->keyboard,
server->key_released_handler);
g_signal_emit_by_name (key, "released");
g_signal_handler_unblock (server->keyboard,
server->key_released_handler);
}
g_dbus_method_invocation_return_value (invocation, NULL);
return;
}
g_return_if_reached ();
}
......
......@@ -339,29 +339,11 @@ keystroke_listener_cb (const AccessibleKeystroke *stroke,
void *user_data)
{
EekboardSystemClient *client = user_data;
EekKey *key;
EekSymbol *symbol;
return FALSE;
key = eek_keyboard_find_key_by_keycode (client->keyboard,
stroke->keycode);
if (!key)
return FALSE;
symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
if (!symbol)
return FALSE;
/* XXX: Ignore modifier keys since there is no way to receive
SPI_KEY_RELEASED event for them. */
if (eek_symbol_is_modifier (symbol))
return FALSE;
if (stroke->type == SPI_KEY_PRESSED)
g_signal_emit_by_name (key, "pressed");
eekboard_proxy_press_key (client->proxy, stroke->keycode);
else
g_signal_emit_by_name (key, "released");
eekboard_proxy_release_key (client->proxy, stroke->keycode);
return TRUE;
}
......
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