From: billh Date: Sat, 13 Apr 2002 18:41:43 +0000 (+0000) Subject: Added a new test for our key notification API X-Git-Tag: AT_SPI2_CORE_0_1_3~933 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c02690c39fec73fda035399dd6e0271d0e16c8db;p=platform%2Fupstream%2Fat-spi2-core.git Added a new test for our key notification API (test/key-listener-test), and fixed some possible Makefile.am breakage. git-svn-id: http://svn.gnome.org/svn/at-spi/trunk@267 e2bd861d-eb25-0410-b326-f6ed22b6b98c --- diff --git a/ChangeLog b/ChangeLog index d8418f8..f500afc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,10 @@ now kill an existing magnifier via ./mag_control q, from the util directory. + * test/key-listener-test.c: + * test/Makefile.am: + Added a new test, for our key listener API. + 2002-04-11 Bill Haneman * test/app.c, test/keysynth-demo.c: diff --git a/registryd/deviceeventcontroller.c b/registryd/deviceeventcontroller.c index cb1db9e..d240b76 100644 --- a/registryd/deviceeventcontroller.c +++ b/registryd/deviceeventcontroller.c @@ -500,7 +500,10 @@ spi_notify_keylisteners (GList **key_listeners, } g_slist_free (notify); - + +#ifdef SPI_DEBUG + if (is_consumed) g_message ("consumed\n"); +#endif return is_consumed; } diff --git a/test/Makefile.am b/test/Makefile.am index 8c6c202..f07563c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,8 +1,8 @@ NULL= -noinst_PROGRAMS = test-simple at app simple-at keysynth-demo accessx-gui wm_test +noinst_PROGRAMS = test-simple at app simple-at keysynth-demo accessx-gui key-listener-test -wm_test_SOURCES = wm_mode_test.c +key_listener_test_SOURCES = key-listener-test.c at_SOURCES = at.c diff --git a/test/key-listener-test.c b/test/key-listener-test.c new file mode 100644 index 0000000..9fdeb62 --- /dev/null +++ b/test/key-listener-test.c @@ -0,0 +1,149 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) + * + * Copyright 2001 Sun Microsystems Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static SPIBoolean report_command_key_event (const AccessibleKeystroke *stroke, void *user_data); +static SPIBoolean report_ordinary_key_event (const AccessibleKeystroke *stroke, void *user_data); +static SPIBoolean report_synchronous_key_event (const AccessibleKeystroke *stroke, void *user_data); + +static AccessibleKeystrokeListener *command_key_listener; +static AccessibleKeystrokeListener *ordinary_key_listener; +static AccessibleKeystrokeListener *synchronous_key_listener; +static AccessibleKeySet *command_keyset; +static AccessibleKeySet *async_keyset; +static AccessibleKeySet *sync_keyset; + +int +main (int argc, char **argv) +{ + + SPI_init (); + + /* prepare the keyboard snoopers */ + command_key_listener = SPI_createAccessibleKeystrokeListener (report_command_key_event, NULL); + ordinary_key_listener = SPI_createAccessibleKeystrokeListener (report_ordinary_key_event, NULL); + synchronous_key_listener = SPI_createAccessibleKeystrokeListener (report_synchronous_key_event, NULL); + + command_keyset = SPI_createAccessibleKeySet (11, "q", NULL, NULL); + async_keyset = SPI_createAccessibleKeySet (11, "abc", NULL, NULL); + sync_keyset = SPI_createAccessibleKeySet (11, "def", NULL, NULL); + + SPI_registerAccessibleKeystrokeListener(command_key_listener, + command_keyset, + SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL, + (unsigned long) ( SPI_KEY_PRESSED ), + SPI_KEYLISTENER_ALL_WINDOWS); + + SPI_registerAccessibleKeystrokeListener(ordinary_key_listener, + async_keyset, + SPI_KEYMASK_UNMODIFIED, + (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ), + SPI_KEYLISTENER_NOSYNC); + + SPI_registerAccessibleKeystrokeListener(synchronous_key_listener, + sync_keyset, + SPI_KEYMASK_UNMODIFIED, + (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ), + SPI_KEYLISTENER_CANCONSUME); + + SPI_event_main (); + + putenv ("AT_BRIDGE_SHUTDOWN=1"); + + return SPI_exit (); +} + +static void +simple_at_exit () +{ + SPI_deregisterAccessibleKeystrokeListener (command_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL); + AccessibleKeystrokeListener_unref (command_key_listener); + SPI_freeAccessibleKeySet (command_keyset); + + SPI_deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL); + AccessibleKeystrokeListener_unref (ordinary_key_listener); + SPI_freeAccessibleKeySet (async_keyset); + + SPI_deregisterAccessibleKeystrokeListener (synchronous_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL); + AccessibleKeystrokeListener_unref (synchronous_key_listener); + SPI_freeAccessibleKeySet (sync_keyset); + + SPI_event_quit (); +} + +static SPIBoolean +is_command_key (const AccessibleKeystroke *key) +{ + switch (key->keyID) + { + case 'Q': + case 'q': + simple_at_exit(); + return TRUE; /* not reached */ + default: + return FALSE; + } +} + +static void +print_key_event (const AccessibleKeystroke *key, char *prefix) +{ + fprintf (stderr, "%s KeyEvent %s%c (keycode %d); string=%s; time=%lx\n", + prefix, + (key->modifiers & SPI_KEYMASK_ALT)?"Alt-":"", + ((key->modifiers & SPI_KEYMASK_SHIFT)^(key->modifiers & SPI_KEYMASK_SHIFTLOCK))? + (char) toupper((int) key->keyID) : (char) tolower((int) key->keyID), + (int) key->keycode, + key->keystring, + (long int) key->timestamp); +} + +static SPIBoolean +report_command_key_event (const AccessibleKeystroke *key, void *user_data) +{ + print_key_event (key, "command"); + return is_command_key (key); +} + +static SPIBoolean +report_ordinary_key_event (const AccessibleKeystroke *key, void *user_data) +{ + print_key_event (key, "ordinary"); + return FALSE; +} + +static SPIBoolean +report_synchronous_key_event (const AccessibleKeystroke *key, void *user_data) +{ + /* consume 'd' key, let others pass through */ + print_key_event (key, "synchronous (consumable) "); + return ( key->keyID == 'd' ) ? TRUE : FALSE; +} +