Quit system-client when user closed a keyboard window.
This commit is contained in:
11
README
11
README
@ -41,18 +41,11 @@ do that with:
|
||||
** eekboard-system-client
|
||||
|
||||
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
|
||||
keyboard. It can be started with:
|
||||
|
||||
$ eekboard-system-client -kfg
|
||||
|
||||
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-system-client
|
||||
|
||||
** eekboard-xml
|
||||
|
||||
|
||||
@ -40,6 +40,12 @@ enum {
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0, };
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_KEYBOARD_VISIBLE,
|
||||
PROP_LAST
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (EekboardContext, eekboard_context, G_TYPE_DBUS_PROXY);
|
||||
|
||||
#define EEKBOARD_CONTEXT_GET_PRIVATE(obj) \
|
||||
@ -86,7 +92,13 @@ eekboard_context_real_g_signal (GDBusProxy *self,
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
eekboard_context_dispose (GObject *self)
|
||||
{
|
||||
@ -147,6 +178,7 @@ eekboard_context_class_init (EekboardContextClass *klass)
|
||||
{
|
||||
GDBusProxyClass *proxy_class = G_DBUS_PROXY_CLASS (klass);
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GParamSpec *pspec;
|
||||
|
||||
g_type_class_add_private (gobject_class,
|
||||
sizeof (EekboardContextPrivate));
|
||||
@ -158,8 +190,23 @@ eekboard_context_class_init (EekboardContextClass *klass)
|
||||
|
||||
proxy_class->g_signal = eekboard_context_real_g_signal;
|
||||
|
||||
gobject_class->get_property = eekboard_context_get_property;
|
||||
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:
|
||||
* @context: an #EekboardContext
|
||||
|
||||
@ -23,57 +23,59 @@
|
||||
#include <cspi/spi.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gconf/gconf-client.h>
|
||||
#include "eekboard/eekboard.h"
|
||||
#include "system-client.h"
|
||||
|
||||
gboolean opt_keyboard = FALSE;
|
||||
|
||||
#ifdef HAVE_CSPI
|
||||
gboolean opt_focus = FALSE;
|
||||
gboolean opt_keystroke = FALSE;
|
||||
#endif /* HAVE_CSPI */
|
||||
|
||||
#ifdef HAVE_FAKEKEY
|
||||
gboolean opt_fakekey = FALSE;
|
||||
#endif /* HAVE_FAKEKEY */
|
||||
|
||||
gboolean opt_all = FALSE;
|
||||
|
||||
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
|
||||
{"listen-focus", 'f', 0, G_OPTION_ARG_NONE, &opt_focus,
|
||||
"Listen focus change events with AT-SPI"},
|
||||
{"listen-keystroke", 's', 0, G_OPTION_ARG_NONE, &opt_keystroke,
|
||||
"Listen keystroke events with AT-SPI"},
|
||||
#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}
|
||||
};
|
||||
|
||||
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
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
EekboardSystemClient *client;
|
||||
EekboardContext *context;
|
||||
GDBusConnection *connection;
|
||||
GError *error;
|
||||
GConfClient *gconfc;
|
||||
GOptionContext *context;
|
||||
GOptionContext *option_context;
|
||||
GMainLoop *loop;
|
||||
|
||||
if (!gtk_init_check (&argc, &argv)) {
|
||||
g_printerr ("Can't init GTK\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
context = g_option_context_new ("eekboard-system-client");
|
||||
g_option_context_add_main_entries (context, options, NULL);
|
||||
g_option_context_parse (context, &argc, &argv, NULL);
|
||||
g_option_context_free (context);
|
||||
option_context = g_option_context_new ("eekboard-system-client");
|
||||
g_option_context_add_main_entries (option_context, options, NULL);
|
||||
g_option_context_parse (option_context, &argc, &argv, NULL);
|
||||
g_option_context_free (option_context);
|
||||
|
||||
error = NULL;
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
||||
@ -87,7 +89,7 @@ main (int argc, char **argv)
|
||||
|
||||
#ifdef HAVE_CSPI
|
||||
error = NULL;
|
||||
if (opt_all || opt_focus || opt_keystroke) {
|
||||
if (opt_focus || opt_keystroke) {
|
||||
if (gconf_client_get_bool (gconfc,
|
||||
"/desktop/gnome/interface/accessibility",
|
||||
&error) ||
|
||||
@ -99,13 +101,13 @@ main (int argc, char **argv)
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if ((opt_all || opt_focus) &&
|
||||
if (opt_focus &&
|
||||
!eekboard_system_client_enable_cspi_focus (client)) {
|
||||
g_printerr ("Can't register focus change event listeners\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if ((opt_all || opt_keystroke) &&
|
||||
if (opt_keystroke &&
|
||||
!eekboard_system_client_enable_cspi_keystroke (client)) {
|
||||
g_printerr ("Can't register keystroke event listeners\n");
|
||||
exit (1);
|
||||
@ -117,21 +119,28 @@ main (int argc, char **argv)
|
||||
}
|
||||
#endif /* HAVE_CSPI */
|
||||
|
||||
if ((opt_all || opt_keyboard) &&
|
||||
!eekboard_system_client_enable_xkl (client)) {
|
||||
if (!eekboard_system_client_enable_xkl (client)) {
|
||||
g_printerr ("Can't register xklavier event listeners\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
#ifdef HAVE_FAKEKEY
|
||||
if ((opt_all || opt_fakekey) &&
|
||||
!eekboard_system_client_enable_fakekey (client)) {
|
||||
if (!eekboard_system_client_enable_fakekey (client)) {
|
||||
g_printerr ("Can't init fakekey\n");
|
||||
exit (1);
|
||||
}
|
||||
#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;
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_CONNECTION,
|
||||
PROP_CONTEXT,
|
||||
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
|
||||
eekboard_system_client_dispose (GObject *object)
|
||||
{
|
||||
@ -193,6 +214,7 @@ eekboard_system_client_class_init (EekboardSystemClientClass *klass)
|
||||
GParamSpec *pspec;
|
||||
|
||||
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;
|
||||
|
||||
pspec = g_param_spec_object ("connection",
|
||||
@ -203,6 +225,15 @@ eekboard_system_client_class_init (EekboardSystemClientClass *klass)
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_CONNECTION,
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user