Quit system-client when user closed a keyboard window.

This commit is contained in:
Daiki Ueno
2011-02-23 14:31:42 +09:00
parent 994d0a9a7e
commit 6747e07166
4 changed files with 119 additions and 39 deletions

11
README
View File

@ -41,18 +41,11 @@ do that with:
** eekboard-system-client ** eekboard-system-client
eekboard-system-client is a client of eekboard-server. It listens eekboard-system-client is a client of eekboard-server. It listens
system events (focus change, keystroke, and keyboard change) and desktop events (keyboard change, focus in/out, and keystroke) and
generates X key events when some keys are pressed on the on-screen generates X key events when some keys are pressed on the on-screen
keyboard. It can be started with: keyboard. It can be started with:
$ eekboard-system-client -kfg $ eekboard-system-client
Where:
-k (--listen-keyboard) is to monitor system keyboard state/config change,
-f (--listen-focus) is to track focus change, and
-g (--generate-key-event) is to generate X key events on virtual
key-press/key-release events.
** eekboard-xml ** eekboard-xml

View File

@ -40,6 +40,12 @@ enum {
static guint signals[LAST_SIGNAL] = { 0, }; static guint signals[LAST_SIGNAL] = { 0, };
enum {
PROP_0,
PROP_KEYBOARD_VISIBLE,
PROP_LAST
};
G_DEFINE_TYPE (EekboardContext, eekboard_context, G_TYPE_DBUS_PROXY); G_DEFINE_TYPE (EekboardContext, eekboard_context, G_TYPE_DBUS_PROXY);
#define EEKBOARD_CONTEXT_GET_PRIVATE(obj) \ #define EEKBOARD_CONTEXT_GET_PRIVATE(obj) \
@ -86,7 +92,13 @@ eekboard_context_real_g_signal (GDBusProxy *self,
} }
if (g_strcmp0 (signal_name, "KeyboardVisibilityChanged") == 0) { if (g_strcmp0 (signal_name, "KeyboardVisibilityChanged") == 0) {
g_variant_get (parameters, "(b)", &priv->keyboard_visible); gboolean keyboard_visible;
g_variant_get (parameters, "(b)", &keyboard_visible);
if (keyboard_visible != priv->keyboard_visible) {
priv->keyboard_visible = keyboard_visible;
g_object_notify (G_OBJECT(context), "keyboard-visible");
}
return; return;
} }
@ -131,6 +143,25 @@ eekboard_context_real_key_released (EekboardContext *self,
} }
} }
static void
eekboard_context_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE(object);
switch (prop_id) {
case PROP_KEYBOARD_VISIBLE:
g_value_set_boolean (value, priv->keyboard_visible);
break;
default:
g_object_get_property (object,
g_param_spec_get_name (pspec),
value);
break;
}
}
static void static void
eekboard_context_dispose (GObject *self) eekboard_context_dispose (GObject *self)
{ {
@ -147,6 +178,7 @@ eekboard_context_class_init (EekboardContextClass *klass)
{ {
GDBusProxyClass *proxy_class = G_DBUS_PROXY_CLASS (klass); GDBusProxyClass *proxy_class = G_DBUS_PROXY_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
g_type_class_add_private (gobject_class, g_type_class_add_private (gobject_class,
sizeof (EekboardContextPrivate)); sizeof (EekboardContextPrivate));
@ -158,8 +190,23 @@ eekboard_context_class_init (EekboardContextClass *klass)
proxy_class->g_signal = eekboard_context_real_g_signal; proxy_class->g_signal = eekboard_context_real_g_signal;
gobject_class->get_property = eekboard_context_get_property;
gobject_class->dispose = eekboard_context_dispose; gobject_class->dispose = eekboard_context_dispose;
/**
* EekboardContext:keyboard-visible:
*
* Flag to indicate if keyboard is visible or not.
*/
pspec = g_param_spec_boolean ("keyboard-visible",
"Keyboard-visible",
"Flag that indicates if keyboard is visible",
FALSE,
G_PARAM_READABLE);
g_object_class_install_property (gobject_class,
PROP_KEYBOARD_VISIBLE,
pspec);
/** /**
* EekboardContext::enabled: * EekboardContext::enabled:
* @context: an #EekboardContext * @context: an #EekboardContext

View File

@ -23,57 +23,59 @@
#include <cspi/spi.h> #include <cspi/spi.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gconf/gconf-client.h> #include <gconf/gconf-client.h>
#include "eekboard/eekboard.h"
#include "system-client.h" #include "system-client.h"
gboolean opt_keyboard = FALSE;
#ifdef HAVE_CSPI #ifdef HAVE_CSPI
gboolean opt_focus = FALSE; gboolean opt_focus = FALSE;
gboolean opt_keystroke = FALSE; gboolean opt_keystroke = FALSE;
#endif /* HAVE_CSPI */ #endif /* HAVE_CSPI */
#ifdef HAVE_FAKEKEY
gboolean opt_fakekey = FALSE;
#endif /* HAVE_FAKEKEY */
gboolean opt_all = FALSE;
static const GOptionEntry options[] = { static const GOptionEntry options[] = {
{"all", 'a', 0, G_OPTION_ARG_NONE, &opt_all,
"Listen all events which can be captured"},
{"listen-keyboard", 'k', 0, G_OPTION_ARG_NONE, &opt_keyboard,
"Listen keyboard change events with libxklavier"},
#ifdef HAVE_CSPI #ifdef HAVE_CSPI
{"listen-focus", 'f', 0, G_OPTION_ARG_NONE, &opt_focus, {"listen-focus", 'f', 0, G_OPTION_ARG_NONE, &opt_focus,
"Listen focus change events with AT-SPI"}, "Listen focus change events with AT-SPI"},
{"listen-keystroke", 's', 0, G_OPTION_ARG_NONE, &opt_keystroke, {"listen-keystroke", 's', 0, G_OPTION_ARG_NONE, &opt_keystroke,
"Listen keystroke events with AT-SPI"}, "Listen keystroke events with AT-SPI"},
#endif /* HAVE_CSPI */ #endif /* HAVE_CSPI */
#ifdef HAVE_FAKEKEY
{"generate-key-event", 'g', 0, G_OPTION_ARG_NONE, &opt_fakekey,
"Generate X key events with libfakekey"},
#endif /* HAVE_FAKEKEY */
{NULL} {NULL}
}; };
static void
on_notify_keyboard_visible (GObject *object,
GParamSpec *spec,
gpointer user_data)
{
GMainLoop *loop = user_data;
gboolean visible;
g_object_get (object, "keyboard-visible", &visible, NULL);
/* user explicitly closed the window */
if (!visible && eekboard_context_is_enabled (EEKBOARD_CONTEXT(object)))
g_main_loop_quit (loop);
}
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
EekboardSystemClient *client; EekboardSystemClient *client;
EekboardContext *context;
GDBusConnection *connection; GDBusConnection *connection;
GError *error; GError *error;
GConfClient *gconfc; GConfClient *gconfc;
GOptionContext *context; GOptionContext *option_context;
GMainLoop *loop;
if (!gtk_init_check (&argc, &argv)) { if (!gtk_init_check (&argc, &argv)) {
g_printerr ("Can't init GTK\n"); g_printerr ("Can't init GTK\n");
exit (1); exit (1);
} }
context = g_option_context_new ("eekboard-system-client"); option_context = g_option_context_new ("eekboard-system-client");
g_option_context_add_main_entries (context, options, NULL); g_option_context_add_main_entries (option_context, options, NULL);
g_option_context_parse (context, &argc, &argv, NULL); g_option_context_parse (option_context, &argc, &argv, NULL);
g_option_context_free (context); g_option_context_free (option_context);
error = NULL; error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
@ -87,7 +89,7 @@ main (int argc, char **argv)
#ifdef HAVE_CSPI #ifdef HAVE_CSPI
error = NULL; error = NULL;
if (opt_all || opt_focus || opt_keystroke) { if (opt_focus || opt_keystroke) {
if (gconf_client_get_bool (gconfc, if (gconf_client_get_bool (gconfc,
"/desktop/gnome/interface/accessibility", "/desktop/gnome/interface/accessibility",
&error) || &error) ||
@ -99,13 +101,13 @@ main (int argc, char **argv)
exit (1); exit (1);
} }
if ((opt_all || opt_focus) && if (opt_focus &&
!eekboard_system_client_enable_cspi_focus (client)) { !eekboard_system_client_enable_cspi_focus (client)) {
g_printerr ("Can't register focus change event listeners\n"); g_printerr ("Can't register focus change event listeners\n");
exit (1); exit (1);
} }
if ((opt_all || opt_keystroke) && if (opt_keystroke &&
!eekboard_system_client_enable_cspi_keystroke (client)) { !eekboard_system_client_enable_cspi_keystroke (client)) {
g_printerr ("Can't register keystroke event listeners\n"); g_printerr ("Can't register keystroke event listeners\n");
exit (1); exit (1);
@ -117,21 +119,28 @@ main (int argc, char **argv)
} }
#endif /* HAVE_CSPI */ #endif /* HAVE_CSPI */
if ((opt_all || opt_keyboard) && if (!eekboard_system_client_enable_xkl (client)) {
!eekboard_system_client_enable_xkl (client)) {
g_printerr ("Can't register xklavier event listeners\n"); g_printerr ("Can't register xklavier event listeners\n");
exit (1); exit (1);
} }
#ifdef HAVE_FAKEKEY #ifdef HAVE_FAKEKEY
if ((opt_all || opt_fakekey) && if (!eekboard_system_client_enable_fakekey (client)) {
!eekboard_system_client_enable_fakekey (client)) {
g_printerr ("Can't init fakekey\n"); g_printerr ("Can't init fakekey\n");
exit (1); exit (1);
} }
#endif /* HAVE_FAKEKEY */ #endif /* HAVE_FAKEKEY */
gtk_main (); loop = g_main_loop_new (NULL, FALSE);
if (opt_focus) {
g_object_get (client, "context", &context, NULL);
g_signal_connect (context, "notify::keyboard-visible",
G_CALLBACK(on_notify_keyboard_visible), loop);
g_object_unref (context);
}
g_main_loop_run (loop);
g_main_loop_unref (loop);
return 0; return 0;
} }

View File

@ -42,6 +42,7 @@
enum { enum {
PROP_0, PROP_0,
PROP_CONNECTION, PROP_CONNECTION,
PROP_CONTEXT,
PROP_LAST PROP_LAST
}; };
@ -137,6 +138,26 @@ eekboard_system_client_set_property (GObject *object,
} }
} }
static void
eekboard_system_client_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
EekboardSystemClient *client = EEKBOARD_SYSTEM_CLIENT(object);
switch (prop_id) {
case PROP_CONTEXT:
g_value_set_object (value, client->context);
break;
default:
g_object_get_property (object,
g_param_spec_get_name (pspec),
value);
break;
}
}
static void static void
eekboard_system_client_dispose (GObject *object) eekboard_system_client_dispose (GObject *object)
{ {
@ -193,6 +214,7 @@ eekboard_system_client_class_init (EekboardSystemClientClass *klass)
GParamSpec *pspec; GParamSpec *pspec;
gobject_class->set_property = eekboard_system_client_set_property; gobject_class->set_property = eekboard_system_client_set_property;
gobject_class->get_property = eekboard_system_client_get_property;
gobject_class->dispose = eekboard_system_client_dispose; gobject_class->dispose = eekboard_system_client_dispose;
pspec = g_param_spec_object ("connection", pspec = g_param_spec_object ("connection",
@ -203,6 +225,15 @@ eekboard_system_client_class_init (EekboardSystemClientClass *klass)
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_CONNECTION, PROP_CONNECTION,
pspec); pspec);
pspec = g_param_spec_object ("context",
"Context",
"Context",
EEKBOARD_TYPE_CONTEXT,
G_PARAM_READABLE);
g_object_class_install_property (gobject_class,
PROP_CONTEXT,
pspec);
} }
static void static void