Quit system-client when user closed a keyboard window.
This commit is contained in:
@ -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