From 926d9346e15eeb021e65defe019483f5bf64334c Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Tue, 19 Apr 2011 14:57:42 +0900 Subject: [PATCH] Use at-spi2 instead of at-spi1. --- configure.ac | 24 ++--- src/Makefile.am | 6 +- src/client-main.c | 39 +++----- src/client.c | 245 ++++++++++++++++++++++++++++------------------ src/client.h | 8 +- 5 files changed, 182 insertions(+), 140 deletions(-) diff --git a/configure.ac b/configure.ac index a53c2d7d..ba3000a0 100644 --- a/configure.ac +++ b/configure.ac @@ -117,20 +117,20 @@ fi AM_CONDITIONAL(ENABLE_FAKEKEY, [test x$enable_fakekey = xyes]) AC_MSG_RESULT($enable_fakekey) -dnl use AT-SPI to capture focus/keystroke events -AC_MSG_CHECKING([whether you enable AT-SPI event handling]) -AC_ARG_ENABLE(cspi, - AS_HELP_STRING([--enable-cspi=no/yes], - [Enable AT-SPI event handling default=no]),, - enable_cspi=no) +dnl use AT-SPI 2 to capture focus/keystroke events +AC_MSG_CHECKING([whether you enable AT-SPI 2 event handling]) +AC_ARG_ENABLE(atspi, + AS_HELP_STRING([--enable-atspi=no/yes], + [Enable AT-SPI 2 event handling default=no]),, + enable_atspi=no) -if test x$enable_cspi = xyes; then - PKG_CHECK_MODULES([CSPI], [cspi-1.0 gconf-2.0], , - [AC_MSG_ERROR([AT-SPI C not found])]) - AC_DEFINE([HAVE_CSPI], [1], [Define if CSPI is found]) +if test x$enable_atspi = xyes; then + PKG_CHECK_MODULES([ATSPI2], [atspi-2 dbus-glib-1], , + [AC_MSG_ERROR([AT-SPI 2 not found])]) + AC_DEFINE([HAVE_ATSPI], [1], [Define if AT-SPI 2 is found]) fi -AC_MSG_RESULT($enable_cspi) -AM_CONDITIONAL(ENABLE_CSPI, [test x$enable_cspi = xyes]) +AC_MSG_RESULT($enable_atspi) +AM_CONDITIONAL(ENABLE_ATSPI, [test x$enable_atspi = xyes]) dnl Python language binding AC_MSG_CHECKING([whether you enable Python language support]) diff --git a/src/Makefile.am b/src/Makefile.am index 0e700cb9..ac29e1da 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -49,11 +49,11 @@ eekboard_LDADD += \ $(FAKEKEY_LIBS) endif -if ENABLE_CSPI +if ENABLE_ATSPI eekboard_CFLAGS += \ - $(CSPI_CFLAGS) + $(ATSPI2_CFLAGS) eekboard_LDADD += \ - $(CSPI_LIBS) + $(ATSPI2_LIBS) endif eekboard_headers = client.h diff --git a/src/client-main.c b/src/client-main.c index 722c0e10..82d44177 100644 --- a/src/client-main.c +++ b/src/client-main.c @@ -20,10 +20,10 @@ #endif /* HAVE_CONFIG_H */ #include -#ifdef HAVE_CSPI -#include -#include -#endif /* HAVE_CSPI */ +#ifdef HAVE_ATSPI +#include +#include +#endif /* HAVE_ATSPI */ #include #include #include "eekboard/eekboard.h" @@ -56,12 +56,12 @@ static const GOptionEntry options[] = { N_("Connect to the given D-Bus address")}, {"use-system-layout", 'x', 0, G_OPTION_ARG_NONE, &opt_use_system_layout, N_("Use system keyboard layout")}, -#ifdef HAVE_CSPI +#ifdef HAVE_ATSPI {"listen-focus", 'f', 0, G_OPTION_ARG_NONE, &opt_focus, N_("Listen focus change events with AT-SPI")}, {"listen-keystroke", 's', 0, G_OPTION_ARG_NONE, &opt_keystroke, N_("Listen keystroke events with AT-SPI")}, -#endif /* HAVE_CSPI */ +#endif /* HAVE_ATSPI */ {"keyboard", 'k', 0, G_OPTION_ARG_STRING, &opt_keyboard, N_("Specify keyboard")}, {"model", '\0', 0, G_OPTION_ARG_STRING, &opt_model, @@ -117,9 +117,6 @@ main (int argc, char **argv) GBusType bus_type; GDBusConnection *connection; GError *error; -#ifdef HAVE_CSPI - GConfClient *gconfc; -#endif /* HAVE_CSPI */ GOptionContext *option_context; GMainLoop *loop; @@ -175,30 +172,24 @@ main (int argc, char **argv) exit (1); } -#ifdef HAVE_CSPI - gconfc = gconf_client_get_default (); - - error = NULL; +#ifdef HAVE_ATSPI if (opt_focus || opt_keystroke) { - if (gconf_client_get_bool (gconfc, - "/desktop/gnome/interface/accessibility", - &error) || - gconf_client_get_bool (gconfc, - "/desktop/gnome/interface/accessibility2", - &error)) { - if (SPI_init () != 0) { - g_printerr ("Can't init CSPI\n"); + GSettings *settings = g_settings_new ("org.gnome.desktop.interface"); + + if (g_settings_get_boolean (settings, "toolkit-accessibility")) { + if (atspi_init () != 0) { + g_printerr ("Can't init AT-SPI 2\n"); exit (1); } if (opt_focus && - !eekboard_client_enable_cspi_focus (client)) { + !eekboard_client_enable_atspi_focus (client)) { g_printerr ("Can't register focus change event listeners\n"); exit (1); } if (opt_keystroke && - !eekboard_client_enable_cspi_keystroke (client)) { + !eekboard_client_enable_atspi_keystroke (client)) { g_printerr ("Can't register keystroke event listeners\n"); exit (1); } @@ -207,7 +198,7 @@ main (int argc, char **argv) exit (1); } } -#endif /* HAVE_CSPI */ +#endif /* HAVE_ATSPI */ if (opt_use_system_layout && (opt_keyboard || opt_model || opt_layouts || opt_options)) { g_printerr ("Can't use --use-system-layout option with keyboard options\n"); diff --git a/src/client.c b/src/client.c index ac6a1c27..2bb01f54 100644 --- a/src/client.c +++ b/src/client.c @@ -21,9 +21,10 @@ #include -#ifdef HAVE_CSPI -#include -#endif /* HAVE_CSPI */ +#ifdef HAVE_ATSPI +#include +#include +#endif /* HAVE_ATSPI */ #include @@ -67,11 +68,11 @@ struct _EekboardClient { gulong key_pressed_handler; gulong key_released_handler; -#ifdef HAVE_CSPI - Accessible *acc; - AccessibleEventListener *focus_listener; - AccessibleEventListener *keystroke_listener; -#endif /* HAVE_CSPI */ +#ifdef HAVE_ATSPI + AtspiAccessible *acc; + gboolean follows_focus; + AtspiDeviceListener *keystroke_listener; +#endif /* HAVE_ATSPI */ #ifdef HAVE_FAKEKEY FakeKey *fakekey; @@ -84,36 +85,33 @@ struct _EekboardClientClass { G_DEFINE_TYPE (EekboardClient, eekboard_client, G_TYPE_OBJECT); -static GdkFilterReturn filter_xkl_event (GdkXEvent *xev, - GdkEvent *event, - gpointer user_data); -static void on_xkl_config_changed - (XklEngine *xklengine, - gpointer user_data); +static GdkFilterReturn filter_xkl_event (GdkXEvent *xev, + GdkEvent *event, + gpointer user_data); +static void on_xkl_config_changed (XklEngine *xklengine, + gpointer user_data); -static void on_xkl_state_changed - (XklEngine *xklengine, - XklEngineStateChange type, - gint value, - gboolean restore, - gpointer user_data); +static void on_xkl_state_changed (XklEngine *xklengine, + XklEngineStateChange type, + gint value, + gboolean restore, + gpointer user_data); -#ifdef HAVE_CSPI -static SPIBoolean focus_listener_cb (const AccessibleEvent *event, - void *user_data); +#ifdef HAVE_ATSPI +static void focus_listener_cb (const AtspiEvent *event, + void *user_data); -static SPIBoolean keystroke_listener_cb - (const AccessibleKeystroke *stroke, - void *user_data); -#endif /* HAVE_CSPI */ -static gboolean set_keyboard (EekboardClient *client, - gboolean show, - EekLayout *layout); -static gboolean set_xkl_keyboard (EekboardClient *client, - gboolean show, - const gchar *model, - const gchar *layouts, - const gchar *options); +static gboolean keystroke_listener_cb (const AtspiDeviceEvent *stroke, + void *user_data); +#endif /* HAVE_ATSPI */ +static gboolean set_keyboard (EekboardClient *client, + gboolean show, + EekLayout *layout); +static gboolean set_xkl_keyboard (EekboardClient *client, + gboolean show, + const gchar *model, + const gchar *layouts, + const gchar *options); static void eekboard_client_set_property (GObject *object, @@ -181,10 +179,10 @@ eekboard_client_dispose (GObject *object) eekboard_client_disable_xkl (client); -#ifdef HAVE_CSPI - eekboard_client_disable_cspi_focus (client); - eekboard_client_disable_cspi_keystroke (client); -#endif /* HAVE_CSPI */ +#ifdef HAVE_ATSPI + eekboard_client_disable_atspi_focus (client); + eekboard_client_disable_atspi_keystroke (client); +#endif /* HAVE_ATSPI */ #ifdef HAVE_FAKEKEY eekboard_client_disable_fakekey (client); @@ -274,10 +272,10 @@ eekboard_client_init (EekboardClient *client) client->key_released_handler = 0; client->xkl_config_changed_handler = 0; client->xkl_state_changed_handler = 0; -#ifdef HAVE_CSPI - client->focus_listener = NULL; +#ifdef HAVE_ATSPI + client->follows_focus = FALSE; client->keystroke_listener = NULL; -#endif /* HAVE_CSPI */ +#endif /* HAVE_ATSPI */ #ifdef HAVE_FAKEKEY client->fakekey = NULL; #endif /* HAVE_FAKEKEY */ @@ -289,9 +287,9 @@ eekboard_client_set_xkl_config (EekboardClient *client, const gchar *layouts, const gchar *options) { -#ifdef HAVE_CSPI +#ifdef HAVE_ATSPI return set_xkl_keyboard (client, - client->focus_listener ? FALSE : TRUE, + !client->follows_focus, model, layouts, options); @@ -340,9 +338,9 @@ eekboard_client_enable_xkl (EekboardClient *client) xkl_engine_start_listen (client->xkl_engine, XKLL_TRACK_KEYBOARD_STATE); -#ifdef HAVE_CSPI +#ifdef HAVE_ATSPI return set_xkl_keyboard (client, - client->focus_listener ? FALSE : TRUE, + !client->follows_focus, NULL, NULL, NULL); @@ -366,80 +364,135 @@ eekboard_client_disable_xkl (EekboardClient *client) client->xkl_state_changed_handler); } -#ifdef HAVE_CSPI +#ifdef HAVE_ATSPI gboolean -eekboard_client_enable_cspi_focus (EekboardClient *client) +eekboard_client_enable_atspi_focus (EekboardClient *client) { - client->focus_listener = SPI_createAccessibleEventListener - ((AccessibleEventListenerCB)focus_listener_cb, - client); + GError *error; - if (!SPI_registerGlobalEventListener (client->focus_listener, - "object:state-changed:focused")) + error = NULL; + if (!atspi_event_listener_register_from_callback + ((AtspiEventListenerCB)focus_listener_cb, + client, + NULL, + "object:state-changed:focused", + &error)) return FALSE; - if (!SPI_registerGlobalEventListener (client->focus_listener, - "focus:")) + error = NULL; + if (!atspi_event_listener_register_from_callback + ((AtspiEventListenerCB)focus_listener_cb, + client, + NULL, + "focus:", + &error)) return FALSE; + client->follows_focus = TRUE; return TRUE; } void -eekboard_client_disable_cspi_focus (EekboardClient *client) +eekboard_client_disable_atspi_focus (EekboardClient *client) { - if (client->focus_listener) { - SPI_deregisterGlobalEventListenerAll (client->focus_listener); - AccessibleEventListener_unref (client->focus_listener); - client->focus_listener = NULL; - } + GError *error; + + client->follows_focus = FALSE; + + error = NULL; + atspi_event_listener_deregister_from_callback + ((AtspiEventListenerCB)focus_listener_cb, + client, + "object:state-changed:focused", + &error); + + error = NULL; + atspi_event_listener_deregister_from_callback + ((AtspiEventListenerCB)focus_listener_cb, + client, + "focus:", + &error); } gboolean -eekboard_client_enable_cspi_keystroke (EekboardClient *client) +eekboard_client_enable_atspi_keystroke (EekboardClient *client) { + GError *error; + client->keystroke_listener = - SPI_createAccessibleKeystrokeListener (keystroke_listener_cb, - client); + atspi_device_listener_new ((AtspiDeviceListenerCB)keystroke_listener_cb, + NULL, + client); - if (!SPI_registerAccessibleKeystrokeListener + error = NULL; + if (!atspi_register_keystroke_listener (client->keystroke_listener, - SPI_KEYSET_ALL_KEYS, + NULL, 0, - SPI_KEY_PRESSED | - SPI_KEY_RELEASED, - SPI_KEYLISTENER_NOSYNC)) + ATSPI_KEY_PRESSED, + ATSPI_KEYLISTENER_NOSYNC, + &error)) + return FALSE; + + error = NULL; + if (!atspi_register_keystroke_listener + (client->keystroke_listener, + NULL, + 0, + ATSPI_KEY_RELEASED, + ATSPI_KEYLISTENER_NOSYNC, + &error)) return FALSE; return TRUE; } void -eekboard_client_disable_cspi_keystroke (EekboardClient *client) +eekboard_client_disable_atspi_keystroke (EekboardClient *client) { if (client->keystroke_listener) { - SPI_deregisterAccessibleKeystrokeListener (client->keystroke_listener, - 0); - AccessibleKeystrokeListener_unref (client->keystroke_listener); + GError *error; + + error = NULL; + atspi_deregister_keystroke_listener (client->keystroke_listener, + NULL, + 0, + ATSPI_KEY_PRESSED, + &error); + + error = NULL; + atspi_deregister_keystroke_listener (client->keystroke_listener, + NULL, + 0, + ATSPI_KEY_RELEASED, + &error); + + g_object_unref (client->keystroke_listener); client->keystroke_listener = NULL; } } -static SPIBoolean -focus_listener_cb (const AccessibleEvent *event, - void *user_data) +static void +focus_listener_cb (const AtspiEvent *event, + void *user_data) { EekboardClient *client = user_data; - Accessible *accessible = event->source; - AccessibleStateSet *state_set = Accessible_getStateSet (accessible); - AccessibleRole role = Accessible_getRole (accessible); + AtspiAccessible *accessible = event->source; + AtspiStateSet *state_set = atspi_accessible_get_state_set (accessible); + AtspiRole role; + GError *error; - if (AccessibleStateSet_contains (state_set, SPI_STATE_EDITABLE) || - role == SPI_ROLE_TERMINAL) { + error = NULL; + role = atspi_accessible_get_role (accessible, &error); + if (error) + return; + + if (atspi_state_set_contains (state_set, ATSPI_STATE_EDITABLE) || + role == ATSPI_ROLE_TERMINAL) { switch (role) { - case SPI_ROLE_TEXT: - case SPI_ROLE_PARAGRAPH: - case SPI_ROLE_PASSWORD_TEXT: - case SPI_ROLE_TERMINAL: + case ATSPI_ROLE_TEXT: + case ATSPI_ROLE_PARAGRAPH: + case ATSPI_ROLE_PASSWORD_TEXT: + case ATSPI_ROLE_TERMINAL: if (strncmp (event->type, "focus", 5) == 0 || event->detail1 == 1) { client->acc = accessible; eekboard_context_show_keyboard (client->context, NULL); @@ -448,7 +501,7 @@ focus_listener_cb (const AccessibleEvent *event, eekboard_context_hide_keyboard (client->context, NULL); } break; - case SPI_ROLE_ENTRY: + case ATSPI_ROLE_ENTRY: if (strncmp (event->type, "focus", 5) == 0 || event->detail1 == 1) { client->acc = accessible; eekboard_context_show_keyboard (client->context, NULL); @@ -464,13 +517,11 @@ focus_listener_cb (const AccessibleEvent *event, } else { eekboard_context_hide_keyboard (client->context, NULL); } - - return FALSE; } -static SPIBoolean -keystroke_listener_cb (const AccessibleKeystroke *stroke, - void *user_data) +static gboolean +keystroke_listener_cb (const AtspiDeviceEvent *stroke, + void *user_data) { EekboardClient *client = user_data; EekKey *key; @@ -478,22 +529,22 @@ keystroke_listener_cb (const AccessibleKeystroke *stroke, /* Ignore modifiers since the keystroke listener does not called when a modifier key is released. */ key = eek_keyboard_find_key_by_keycode (client->keyboard, - stroke->keycode); + stroke->hw_code); if (key) { EekSymbol *symbol = eek_key_get_symbol_with_fallback (key, 0, 0); if (symbol && eek_symbol_is_modifier (symbol)) return FALSE; } - if (stroke->type == SPI_KEY_PRESSED) { - eekboard_context_press_key (client->context, stroke->keycode, NULL); + if (stroke->type == ATSPI_KEY_PRESSED) { + eekboard_context_press_key (client->context, stroke->hw_code, NULL); } else { - eekboard_context_release_key (client->context, stroke->keycode, NULL); + eekboard_context_release_key (client->context, stroke->hw_code, NULL); } return TRUE; } -#endif /* HAVE_CSPI */ +#endif /* HAVE_ATSPI */ EekboardClient * eekboard_client_new (GDBusConnection *connection) @@ -759,7 +810,7 @@ eekboard_client_load_keyboard_from_file (EekboardClient *client, layout = eek_xml_layout_new (G_INPUT_STREAM(input)); g_object_unref (input); - retval = set_keyboard (client, TRUE, layout); + retval = set_keyboard (client, !client->follows_focus, layout); g_object_unref (layout); return retval; } diff --git a/src/client.h b/src/client.h index 09215320..f795ec19 100644 --- a/src/client.h +++ b/src/client.h @@ -44,14 +44,14 @@ gboolean eekboard_client_set_xkl_config (EekboardClient *client, gboolean eekboard_client_enable_xkl (EekboardClient *client); void eekboard_client_disable_xkl (EekboardClient *client); -gboolean eekboard_client_enable_cspi_focus +gboolean eekboard_client_enable_atspi_focus (EekboardClient *client); -void eekboard_client_disable_cspi_focus +void eekboard_client_disable_atspi_focus (EekboardClient *client); -gboolean eekboard_client_enable_cspi_keystroke +gboolean eekboard_client_enable_atspi_keystroke (EekboardClient *client); -void eekboard_client_disable_cspi_keystroke +void eekboard_client_disable_atspi_keystroke (EekboardClient *client); gboolean eekboard_client_enable_fakekey (EekboardClient *client);