Search
lxdream.org :: lxdream/src/display.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/display.c
changeset 849:bbe26d798fc2
prev839:51f1c4195790
next1010:a506a2f66180
author nkeynes
date Fri Oct 31 02:57:59 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Declare mem_copy_* functions as FASTCALL
Split sh4_flush_store_queue into TLB/non-TLB versions, and optimize
slightly based on that
file annotate diff log raw
1.1 --- a/src/display.c Tue Sep 02 03:34:00 2008 +0000
1.2 +++ b/src/display.c Fri Oct 31 02:57:59 2008 +0000
1.3 @@ -94,7 +94,6 @@
1.4 */
1.5 static struct keymap_entry *root_keymap[65535];
1.6 static struct keymap_entry *keyhooks = NULL;
1.7 -static struct mouse_entry *mousehooks = NULL;
1.8 static gboolean display_focused = TRUE;
1.9 static GList *input_drivers= NULL;
1.10 static display_keysym_callback_t display_keysym_hook = NULL;
1.11 @@ -169,6 +168,7 @@
1.12 return NULL;
1.13 }
1.14 return &root_keymap[keycode-1];
1.15 +
1.16 } else {
1.17 char *id = g_strstrip(strv[0]);
1.18 GList *ptr;
1.19 @@ -284,7 +284,7 @@
1.20 g_strfreev(strv);
1.21 }
1.22
1.23 -gboolean input_register_hook( input_key_callback_t callback,
1.24 +gboolean input_register_keyboard_hook( input_key_callback_t callback,
1.25 void *data )
1.26 {
1.27 keymap_entry_t key = malloc( sizeof( struct keymap_entry ) );
1.28 @@ -296,7 +296,7 @@
1.29 return TRUE;
1.30 }
1.31
1.32 -void input_unregister_hook( input_key_callback_t callback,
1.33 +void input_unregister_keyboard_hook( input_key_callback_t callback,
1.34 void *data )
1.35 {
1.36 keymap_entry_t key = keyhooks;
1.37 @@ -318,6 +318,97 @@
1.38 }
1.39 }
1.40
1.41 +gboolean input_is_key_valid( const gchar *keysym )
1.42 +{
1.43 + keymap_entry_t *ptr = input_entry_from_keysym(keysym);
1.44 + return ptr != NULL;
1.45 +}
1.46 +
1.47 +gboolean input_is_key_registered( const gchar *keysym )
1.48 +{
1.49 + keymap_entry_t *ptr = input_entry_from_keysym(keysym);
1.50 + return ptr != NULL && *ptr != NULL;
1.51 +}
1.52 +
1.53 +void input_event_keydown( input_driver_t driver, uint16_t keycode, uint32_t pressure )
1.54 +{
1.55 + if( display_focused ) {
1.56 + keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);
1.57 + if( entryp != NULL && *entryp != NULL ) {
1.58 + (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, TRUE );
1.59 + }
1.60 + if( driver == NULL ) {
1.61 + keymap_entry_t key = keyhooks;
1.62 + while( key != NULL ) {
1.63 + key->callback( key->data, keycode, pressure, TRUE );
1.64 + key = key->next;
1.65 + }
1.66 + }
1.67 + }
1.68 + if( display_keysym_hook != NULL ) {
1.69 + gchar *sym = input_keycode_to_keysym( driver, keycode );
1.70 + if( sym != NULL ) {
1.71 + display_keysym_hook(display_keysym_hook_data, sym);
1.72 + g_free(sym);
1.73 + }
1.74 + }
1.75 +}
1.76 +
1.77 +void input_event_keyup( input_driver_t driver, uint16_t keycode, uint32_t pressure )
1.78 +{
1.79 + if( display_focused ) {
1.80 + keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);
1.81 + if( entryp != NULL && *entryp != NULL ) {
1.82 + (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, FALSE );
1.83 + }
1.84 +
1.85 + if( driver == NULL ) {
1.86 + keymap_entry_t key = keyhooks;
1.87 + while( key != NULL ) {
1.88 + key->callback( key->data, keycode, pressure, FALSE );
1.89 + key = key->next;
1.90 + }
1.91 + }
1.92 + }
1.93 +}
1.94 +
1.95 +uint16_t input_keycode_to_dckeysym( uint16_t keycode )
1.96 +{
1.97 + return display_driver->convert_to_dckeysym(keycode);
1.98 +}
1.99 +
1.100 +void input_set_keysym_hook( display_keysym_callback_t hook, void *data )
1.101 +{
1.102 + display_keysym_hook = hook;
1.103 + display_keysym_hook_data = data;
1.104 +}
1.105 +
1.106 +/***************** System mouse driver ****************/
1.107 +
1.108 +static struct keymap_entry *mouse_keymap[MAX_MOUSE_BUTTONS];
1.109 +static struct mouse_entry *mousehooks = NULL;
1.110 +static uint32_t mouse_x = -1, mouse_y = -1, mouse_buttons = 0;
1.111 +
1.112 +uint16_t mouse_resolve_keysym( struct input_driver *driver, const gchar *keysym )
1.113 +{
1.114 + if( strncasecmp( keysym, "Button", 6 ) == 0 ){
1.115 + unsigned long button = strtoul( keysym+6, NULL, 10 );
1.116 + if( button > MAX_MOUSE_BUTTONS ) {
1.117 + return 0;
1.118 + }
1.119 + return (uint16_t)button;
1.120 + }
1.121 + return 0;
1.122 +}
1.123 +
1.124 +gchar *mouse_get_keysym( struct input_driver *driver, uint16_t keycode )
1.125 +{
1.126 + return g_strdup_printf( "Button%d", (keycode) );
1.127 +}
1.128 +
1.129 +struct input_driver system_mouse_driver = { "Mouse", mouse_resolve_keysym, NULL, mouse_get_keysym, NULL };
1.130 +
1.131 +
1.132 gboolean input_register_mouse_hook( gboolean relative, input_mouse_callback_t callback,
1.133 void *data )
1.134 {
1.135 @@ -351,7 +442,7 @@
1.136 }
1.137 }
1.138
1.139 -void input_event_mouse( uint32_t buttons, int32_t x, int32_t y, gboolean absolute )
1.140 +void input_event_run_mouse_hooks( uint32_t buttons, int32_t x, int32_t y, gboolean absolute )
1.141 {
1.142 mouse_entry_t ent = mousehooks;
1.143 while( ent != NULL ) {
1.144 @@ -360,60 +451,38 @@
1.145 }
1.146 }
1.147
1.148 -gboolean input_is_key_valid( const gchar *keysym )
1.149 +void input_event_mousedown( uint16_t button, int32_t x, int32_t y, gboolean absolute )
1.150 {
1.151 - keymap_entry_t *ptr = input_entry_from_keysym(keysym);
1.152 - return ptr != NULL;
1.153 + if( absolute ) {
1.154 + mouse_x = x;
1.155 + mouse_y = y;
1.156 + }
1.157 + mouse_buttons |= (1<<button);
1.158 + input_event_keydown( &system_mouse_driver, button+1, 1 );
1.159 + input_event_run_mouse_hooks( mouse_buttons, x, y, absolute );
1.160 +}
1.161 +
1.162 +void input_event_mouseup( uint16_t button, int32_t x, int32_t y, gboolean absolute )
1.163 +{
1.164 + if( absolute ) {
1.165 + mouse_x = x;
1.166 + mouse_y = y;
1.167 + }
1.168 + mouse_buttons &= ~(1<<button);
1.169 + input_event_keyup( &system_mouse_driver, button+1, 1 );
1.170 + input_event_run_mouse_hooks( mouse_buttons, x, y, absolute );
1.171 }
1.172
1.173 -gboolean input_is_key_registered( const gchar *keysym )
1.174 +void input_event_mousemove( int32_t x, int32_t y, gboolean absolute )
1.175 {
1.176 - keymap_entry_t *ptr = input_entry_from_keysym(keysym);
1.177 - return ptr != NULL && *ptr != NULL;
1.178 + if( absolute ) {
1.179 + mouse_x = x;
1.180 + mouse_y = y;
1.181 + }
1.182 + input_event_run_mouse_hooks( mouse_buttons, x, y, absolute );
1.183 }
1.184
1.185 -void input_event_keydown( input_driver_t driver, uint16_t keycode, uint32_t pressure )
1.186 -{
1.187 - if( display_focused ) {
1.188 - keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);
1.189 - if( entryp != NULL && *entryp != NULL ) {
1.190 - (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, TRUE );
1.191 - }
1.192 - keymap_entry_t key = keyhooks;
1.193 - while( key != NULL ) {
1.194 - key->callback( key->data, keycode, pressure, TRUE );
1.195 - key = key->next;
1.196 - }
1.197 - }
1.198 - if( display_keysym_hook != NULL ) {
1.199 - gchar *sym = input_keycode_to_keysym( driver, keycode );
1.200 - if( sym != NULL ) {
1.201 - display_keysym_hook(display_keysym_hook_data, sym);
1.202 - g_free(sym);
1.203 - }
1.204 - }
1.205 -}
1.206 -
1.207 -void input_event_keyup( input_driver_t driver, uint16_t keycode, uint32_t pressure )
1.208 -{
1.209 - if( display_focused ) {
1.210 - keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);
1.211 - if( entryp != NULL && *entryp != NULL ) {
1.212 - (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, FALSE );
1.213 - }
1.214 -
1.215 - keymap_entry_t key = keyhooks;
1.216 - while( key != NULL ) {
1.217 - key->callback( key->data, keycode, pressure, FALSE );
1.218 - key = key->next;
1.219 - }
1.220 - }
1.221 -}
1.222 -
1.223 -uint16_t input_keycode_to_dckeysym( uint16_t keycode )
1.224 -{
1.225 - return display_driver->convert_to_dckeysym(keycode);
1.226 -}
1.227 +/************************ Main display driver *************************/
1.228
1.229 void print_display_drivers( FILE *out )
1.230 {
1.231 @@ -450,7 +519,9 @@
1.232 display_driver = driver;
1.233 if( driver->init_driver != NULL )
1.234 rv = driver->init_driver();
1.235 - if( !rv ) {
1.236 + if( rv ) {
1.237 + input_register_device(&system_mouse_driver, MAX_MOUSE_BUTTONS);
1.238 + } else {
1.239 display_driver = NULL;
1.240 }
1.241 return rv;
1.242 @@ -460,9 +531,3 @@
1.243 {
1.244 display_focused = has_focus;
1.245 }
1.246 -
1.247 -void input_set_keysym_hook( display_keysym_callback_t hook, void *data )
1.248 -{
1.249 - display_keysym_hook = hook;
1.250 - display_keysym_hook_data = data;
1.251 -}
.