From 7b745c913b7a7938d1a32382c330ec6febee26cf Mon Sep 17 00:00:00 2001 From: billh Date: Thu, 22 Nov 2001 14:55:54 +0000 Subject: [PATCH] added use of non-preemptive keylistener to simple-at test. git-svn-id: http://svn.gnome.org/svn/at-spi/trunk@112 e2bd861d-eb25-0410-b326-f6ed22b6b98c --- libspi/deviceeventcontroller.c | 14 +++++---- libspi/keystrokelistener.c | 3 +- registryd/deviceeventcontroller.c | 14 +++++---- test/simple-at.c | 49 ++++++++++++++++++++++++------- 4 files changed, 56 insertions(+), 24 deletions(-) diff --git a/libspi/deviceeventcontroller.c b/libspi/deviceeventcontroller.c index 1356866b..cc88dced 100644 --- a/libspi/deviceeventcontroller.c +++ b/libspi/deviceeventcontroller.c @@ -153,14 +153,15 @@ controller_register_device_listener (SpiDeviceEventController *controller, case SPI_DEVICE_TYPE_KBD: key_listener = (DEControllerKeyListener *) listener; controller->key_listeners = g_list_append (controller->key_listeners, key_listener); - - mask_ptr = (Accessibility_ControllerEventMask *) + if (key_listener->is_system_global) + { + mask_ptr = (Accessibility_ControllerEventMask *) g_list_find_custom (controller->keymask_list, (gpointer) key_listener->mask, _eventmask_compare_value); - if (mask_ptr) + if (mask_ptr) ++(mask_ptr->refcount); - else - { + else + { if (key_listener->mask->refcount != (CORBA_unsigned_short) 1) fprintf (stderr, "mask initial refcount is not 1!\n"); if (key_listener->mask->value > (CORBA_unsigned_long) 2048) @@ -174,7 +175,8 @@ controller_register_device_listener (SpiDeviceEventController *controller, mask_ptr->refcount = (CORBA_unsigned_short) 1; controller->keymask_list = g_list_append (controller->keymask_list, (gpointer) mask_ptr); - } + } + } break; case SPI_DEVICE_TYPE_MOUSE: /* controller->mouse_listeners = g_list_append (controller->mouse_listeners, diff --git a/libspi/keystrokelistener.c b/libspi/keystrokelistener.c index 9ec6a102..506eeb12 100644 --- a/libspi/keystrokelistener.c +++ b/libspi/keystrokelistener.c @@ -89,12 +89,13 @@ impl_key_event (PortableServer_Servant servant, } #endif /* TODO: convert from the CORBA-based struct to a c-type-based one ? */ +#ifdef SPI_KEYSTROKE_DEBUG fprintf (stderr, "Key:\tsym %ld\n\tmods %x\n\tcode %d\n\ttime %ld\n", (long) key->keyID, (unsigned int) key->modifiers, (int) key->keycode, (long int) key->timestamp); - +#endif while (callbacks) { BooleanKeystrokeListenerCB cb = (BooleanKeystrokeListenerCB) callbacks->data; diff --git a/registryd/deviceeventcontroller.c b/registryd/deviceeventcontroller.c index 1356866b..cc88dced 100644 --- a/registryd/deviceeventcontroller.c +++ b/registryd/deviceeventcontroller.c @@ -153,14 +153,15 @@ controller_register_device_listener (SpiDeviceEventController *controller, case SPI_DEVICE_TYPE_KBD: key_listener = (DEControllerKeyListener *) listener; controller->key_listeners = g_list_append (controller->key_listeners, key_listener); - - mask_ptr = (Accessibility_ControllerEventMask *) + if (key_listener->is_system_global) + { + mask_ptr = (Accessibility_ControllerEventMask *) g_list_find_custom (controller->keymask_list, (gpointer) key_listener->mask, _eventmask_compare_value); - if (mask_ptr) + if (mask_ptr) ++(mask_ptr->refcount); - else - { + else + { if (key_listener->mask->refcount != (CORBA_unsigned_short) 1) fprintf (stderr, "mask initial refcount is not 1!\n"); if (key_listener->mask->value > (CORBA_unsigned_long) 2048) @@ -174,7 +175,8 @@ controller_register_device_listener (SpiDeviceEventController *controller, mask_ptr->refcount = (CORBA_unsigned_short) 1; controller->keymask_list = g_list_append (controller->keymask_list, (gpointer) mask_ptr); - } + } + } break; case SPI_DEVICE_TYPE_MOUSE: /* controller->mouse_listeners = g_list_append (controller->mouse_listeners, diff --git a/test/simple-at.c b/test/simple-at.c index 1a532a48..a441877e 100644 --- a/test/simple-at.c +++ b/test/simple-at.c @@ -27,7 +27,8 @@ static void report_focus_event (void *fp); static void report_button_press (void *fp); -static boolean report_key_event (void *fp); +static boolean report_command_key_event (void *fp); +static boolean report_ordinary_key_event (void *fp); static void check_property_change (void *fp); static void get_environment_vars (void); @@ -42,7 +43,8 @@ static boolean festival_chatty = FALSE; static AccessibleEventListener *focus_listener; static AccessibleEventListener *property_listener; static AccessibleEventListener *button_listener; -static AccessibleKeystrokeListener *key_listener; +static AccessibleKeystrokeListener *command_key_listener; +static AccessibleKeystrokeListener *ordinary_key_listener; int main(int argc, char **argv) @@ -84,13 +86,29 @@ main(int argc, char **argv) } /* prepare the keyboard snoopers */ - key_listener = createAccessibleKeystrokeListener(report_key_event); - /* will listen only to Alt-key combinations */ - registerAccessibleKeystrokeListener(key_listener, + command_key_listener = createAccessibleKeystrokeListener(report_command_key_event); + ordinary_key_listener = createAccessibleKeystrokeListener(report_ordinary_key_event); + + /* will listen only to Alt-key combinations, and only to KeyPress events */ + registerAccessibleKeystrokeListener(command_key_listener, (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS, SPI_KEYMASK_ALT, - (unsigned long) ( KeyPress | KeyRelease), + (unsigned long) ( KeyPress ), SPI_KEYLISTENER_ALL_WINDOWS); + + /* will listen only to unshifted key events, both press and release */ + registerAccessibleKeystrokeListener(ordinary_key_listener, + (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS, + SPI_KEYMASK_UNMODIFIED, + (unsigned long) ( KeyPress | KeyRelease), + SPI_KEYLISTENER_NOSYNC); + + /* will listen only to shifted key events, both press and release */ + registerAccessibleKeystrokeListener(ordinary_key_listener, + (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS, + SPI_KEYMASK_SHIFT, + (unsigned long) ( KeyPress | KeyRelease), + SPI_KEYLISTENER_NOSYNC); get_environment_vars(); @@ -206,7 +224,9 @@ simple_at_exit() deregisterGlobalEventListenerAll (focus_listener); deregisterGlobalEventListenerAll (property_listener); deregisterGlobalEventListenerAll (button_listener); - deregisterAccessibleKeystrokeListener (key_listener, SPI_KEYMASK_ALT ); + deregisterAccessibleKeystrokeListener (command_key_listener, SPI_KEYMASK_ALT ); + deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_UNMODIFIED ); + deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_SHIFT ); SPI_exit (); } @@ -234,20 +254,27 @@ is_command_key (AccessibleKeyStroke *key) } static boolean -report_key_event (void *p) +report_command_key_event (void *p) { AccessibleKeyStroke *key = (AccessibleKeyStroke *) p; - fprintf (stderr, "KeyEvent %s%c (keycode %d)\n", + fprintf (stderr, "Command KeyEvent %s%c (keycode %d)\n", (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); - fprintf (stderr, "Key:\tsym %ld\n\tmods %x\n\tcode %d\n\ttime %ld\n", + return is_command_key (key); +} + + +static boolean +report_ordinary_key_event (void *p) +{ + AccessibleKeyStroke *key = (AccessibleKeyStroke *) p; + fprintf (stderr, "Received key event:\tsym %ld\n\tmods %x\n\tcode %d\n\ttime %ld\n", (long) key->keyID, (unsigned int) key->modifiers, (int) key->keycode, (long int) key->timestamp); - return is_command_key (key); } static int _festival_init () -- 2.34.1