Search
lxdream.org :: lxdream/src/display.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/display.c
changeset 608:4f588e52bce0
prev561:533f6b478071
next614:a2d239d4438a
author nkeynes
date Sat Jan 26 02:45:27 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Bug #50: Implement mouse and keyboard
file annotate diff log raw
1.1 --- a/src/display.c Tue Jan 01 05:08:38 2008 +0000
1.2 +++ b/src/display.c Sat Jan 26 02:45:27 2008 +0000
1.3 @@ -36,8 +36,16 @@
1.4 input_key_callback_t callback;
1.5 void *data;
1.6 uint32_t value;
1.7 + struct keymap_entry *next; // allow chaining
1.8 } *keymap_entry_t;
1.9
1.10 +typedef struct mouse_entry {
1.11 + gboolean relative;
1.12 + input_mouse_callback_t callback;
1.13 + void *data;
1.14 + struct mouse_entry *next;
1.15 +} *mouse_entry_t;
1.16 +
1.17 /**
1.18 * Colour format information
1.19 */
1.20 @@ -59,7 +67,8 @@
1.21 * FIXME: make this more memory efficient
1.22 */
1.23 struct keymap_entry *keymap[65536];
1.24 -
1.25 +struct keymap_entry *keyhooks = NULL;
1.26 +struct mouse_entry *mousehooks = NULL;
1.27
1.28 static struct keymap_entry *input_create_key( uint16_t keycode )
1.29 {
1.30 @@ -113,14 +122,85 @@
1.31 void input_unregister_key( const gchar *keysym, input_key_callback_t callback,
1.32 void *data, uint32_t value )
1.33 {
1.34 - if( display_driver == NULL || keysym == NULL )
1.35 + if( display_driver == NULL || keysym == NULL || display_driver->resolve_keysym == NULL )
1.36 return;
1.37 uint16_t keycode = display_driver->resolve_keysym(keysym);
1.38 if( keycode == 0 )
1.39 return;
1.40 input_delete_key( keycode, callback, data, value );
1.41 }
1.42 -
1.43 +
1.44 +gboolean input_register_hook( input_key_callback_t callback,
1.45 + void *data )
1.46 +{
1.47 + keymap_entry_t key = malloc( sizeof( struct keymap_entry ) );
1.48 + assert( key != NULL );
1.49 + key->callback = callback;
1.50 + key->data = data;
1.51 + key->next = keyhooks;
1.52 + keyhooks = key;
1.53 + return TRUE;
1.54 +}
1.55 +
1.56 +void input_unregister_hook( input_key_callback_t callback,
1.57 + void *data )
1.58 +{
1.59 + keymap_entry_t key = keyhooks;
1.60 + if( key != NULL ) {
1.61 + keymap_entry_t next = key->next;
1.62 + if( key->callback == callback && key->data == data ) {
1.63 + free(key);
1.64 + keyhooks = next;
1.65 + return;
1.66 + }
1.67 + while( next != NULL ) {
1.68 + if( next->callback == callback && next->data == data ) {
1.69 + key->next = next->next;
1.70 + free(next);
1.71 + }
1.72 + }
1.73 + }
1.74 +}
1.75 +
1.76 +gboolean input_register_mouse_hook( gboolean relative, input_mouse_callback_t callback,
1.77 + void *data )
1.78 +{
1.79 + mouse_entry_t ent = malloc( sizeof( struct mouse_entry ) );
1.80 + assert( ent != NULL );
1.81 + ent->callback = callback;
1.82 + ent->data = data;
1.83 + ent->next = mousehooks;
1.84 + mousehooks = ent;
1.85 + return TRUE;
1.86 +}
1.87 +
1.88 +void input_unregister_mouse_hook( input_mouse_callback_t callback, void *data )
1.89 +{
1.90 + mouse_entry_t ent = mousehooks;
1.91 + if( ent != NULL ) {
1.92 + mouse_entry_t next = ent->next;
1.93 + if( ent->callback == callback && ent->data == data ) {
1.94 + free(ent);
1.95 + mousehooks = next;
1.96 + return;
1.97 + }
1.98 + while( next != NULL ) {
1.99 + if( next->callback == callback && next->data == data ) {
1.100 + ent->next = next->next;
1.101 + free(next);
1.102 + }
1.103 + }
1.104 + }
1.105 +}
1.106 +
1.107 +void input_event_mouse( uint32_t buttons, int32_t x, int32_t y )
1.108 +{
1.109 + mouse_entry_t ent = mousehooks;
1.110 + while( ent != NULL ) {
1.111 + ent->callback(ent->data, buttons, x, y);
1.112 + ent = ent->next;
1.113 + }
1.114 +}
1.115
1.116 gboolean input_is_key_valid( const gchar *keysym )
1.117 {
1.118 @@ -144,7 +224,12 @@
1.119 struct keymap_entry *key = input_get_key(keycode);
1.120 if( key != NULL ) {
1.121 key->callback( key->data, key->value, TRUE );
1.122 - }
1.123 + }
1.124 + key = keyhooks;
1.125 + while( key != NULL ) {
1.126 + key->callback( key->data, keycode, TRUE );
1.127 + key = key->next;
1.128 + }
1.129 }
1.130
1.131 void input_event_keyup( uint16_t keycode )
1.132 @@ -153,6 +238,16 @@
1.133 if( key != NULL ) {
1.134 key->callback( key->data, key->value, FALSE );
1.135 }
1.136 + key = keyhooks;
1.137 + while( key != NULL ) {
1.138 + key->callback( key->data, keycode, FALSE );
1.139 + key = key->next;
1.140 + }
1.141 +}
1.142 +
1.143 +uint16_t input_keycode_to_dckeysym( uint16_t keycode )
1.144 +{
1.145 + return display_driver->convert_to_dckeysym(keycode);
1.146 }
1.147
1.148 display_driver_t get_display_driver_by_name( const char *name )
.