Search
lxdream.org :: lxdream/src/display.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/display.c
changeset 736:a02d1475ccfd
prev700:4650d0c7f6f9
next770:429ff505c450
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
1.1 --- a/src/display.c Sun Jun 22 06:49:00 2008 +0000
1.2 +++ b/src/display.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -26,14 +26,14 @@
1.4
1.5 display_driver_t display_driver_list[] = {
1.6 #ifdef HAVE_GTK
1.7 - &display_gtk_driver,
1.8 + &display_gtk_driver,
1.9 #else
1.10 #ifdef HAVE_COCOA
1.11 - &display_osx_driver,
1.12 + &display_osx_driver,
1.13 #endif
1.14 #endif
1.15 - &display_null_driver,
1.16 - NULL };
1.17 + &display_null_driver,
1.18 + NULL };
1.19
1.20 /* Some explanation:
1.21 * The system has at least one "root" device representing the main display
1.22 @@ -76,17 +76,17 @@
1.23 * Colour format information
1.24 */
1.25 struct colour_format colour_formats[] = {
1.26 - { GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_BGRA, GL_RGB5_A1, 2 },
1.27 - { GL_UNSIGNED_SHORT_5_6_5, GL_RGB, GL_RGB5, 2 },
1.28 - { GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_BGRA, GL_RGBA4, 2 },
1.29 - { GL_UNSIGNED_BYTE, GL_BGRA, GL_RGBA8, 4 }, /* YUV decoded to ARGB8888 */
1.30 - { GL_UNSIGNED_BYTE, GL_BGR, GL_RGB, 3 },
1.31 - { GL_UNSIGNED_BYTE, GL_BGRA, GL_RGBA8, 4 },
1.32 - { GL_UNSIGNED_BYTE, GL_BGRA, GL_RGBA8, 4 }, /* Index4 decoded */
1.33 - { GL_UNSIGNED_BYTE, GL_BGRA, GL_RGBA8, 4 }, /* Index8 decoded */
1.34 - { GL_UNSIGNED_BYTE, GL_BGRA, GL_RGBA8, 4 },
1.35 - { GL_UNSIGNED_BYTE, GL_RGB, GL_RGB, 3 },
1.36 -
1.37 + { GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_BGRA, GL_RGB5_A1, 2 },
1.38 + { GL_UNSIGNED_SHORT_5_6_5, GL_RGB, GL_RGB5, 2 },
1.39 + { GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_BGRA, GL_RGBA4, 2 },
1.40 + { GL_UNSIGNED_BYTE, GL_BGRA, GL_RGBA8, 4 }, /* YUV decoded to ARGB8888 */
1.41 + { GL_UNSIGNED_BYTE, GL_BGR, GL_RGB, 3 },
1.42 + { GL_UNSIGNED_BYTE, GL_BGRA, GL_RGBA8, 4 },
1.43 + { GL_UNSIGNED_BYTE, GL_BGRA, GL_RGBA8, 4 }, /* Index4 decoded */
1.44 + { GL_UNSIGNED_BYTE, GL_BGRA, GL_RGBA8, 4 }, /* Index8 decoded */
1.45 + { GL_UNSIGNED_BYTE, GL_BGRA, GL_RGBA8, 4 },
1.46 + { GL_UNSIGNED_BYTE, GL_RGB, GL_RGB, 3 },
1.47 +
1.48 };
1.49
1.50 /**
1.51 @@ -104,10 +104,10 @@
1.52 {
1.53 GList *ptr;
1.54 for( ptr = input_drivers; ptr != NULL; ptr = g_list_next(ptr) ) {
1.55 - input_driver_entry_t entry = (input_driver_entry_t)ptr->data;
1.56 - if( strcasecmp( entry->driver->id, driver->id ) == 0 ) {
1.57 - return FALSE;
1.58 - }
1.59 + input_driver_entry_t entry = (input_driver_entry_t)ptr->data;
1.60 + if( strcasecmp( entry->driver->id, driver->id ) == 0 ) {
1.61 + return FALSE;
1.62 + }
1.63 }
1.64
1.65 input_driver_entry_t entry = g_malloc0( sizeof(struct input_driver_entry) + (sizeof(keymap_entry_t) * max_keycode) );
1.66 @@ -121,10 +121,10 @@
1.67 {
1.68 GList *ptr;
1.69 for( ptr = input_drivers; ptr != NULL; ptr = g_list_next(ptr) ) {
1.70 - input_driver_entry_t entry = (input_driver_entry_t)ptr->data;
1.71 - if( strcasecmp(entry->driver->id, id) == 0 ) {
1.72 - return TRUE;
1.73 - }
1.74 + input_driver_entry_t entry = (input_driver_entry_t)ptr->data;
1.75 + if( strcasecmp(entry->driver->id, id) == 0 ) {
1.76 + return TRUE;
1.77 + }
1.78 }
1.79 return FALSE;
1.80 }
1.81 @@ -134,15 +134,15 @@
1.82 {
1.83 GList *ptr;
1.84 for( ptr = input_drivers; ptr != NULL; ptr = g_list_next(ptr) ) {
1.85 - input_driver_entry_t entry = (input_driver_entry_t)ptr->data;
1.86 - if( entry->driver == driver ) {
1.87 - if( driver->destroy != NULL ) {
1.88 - driver->destroy(driver);
1.89 - }
1.90 - input_drivers = g_list_remove(input_drivers, (gpointer)entry);
1.91 - g_free( entry );
1.92 - return;
1.93 - }
1.94 + input_driver_entry_t entry = (input_driver_entry_t)ptr->data;
1.95 + if( entry->driver == driver ) {
1.96 + if( driver->destroy != NULL ) {
1.97 + driver->destroy(driver);
1.98 + }
1.99 + input_drivers = g_list_remove(input_drivers, (gpointer)entry);
1.100 + g_free( entry );
1.101 + return;
1.102 + }
1.103 }
1.104 }
1.105
1.106 @@ -153,43 +153,43 @@
1.107 static struct keymap_entry **input_entry_from_keysym( const gchar *keysym )
1.108 {
1.109 if( keysym == NULL || keysym[0] == 0 ) {
1.110 - return NULL;
1.111 + return NULL;
1.112 }
1.113 char **strv = g_strsplit(keysym,":",2);
1.114 if( strv[1] == NULL ) {
1.115 - /* root device */
1.116 - if( display_driver == NULL || display_driver->resolve_keysym == NULL) {
1.117 - // Root device has no input handling
1.118 - g_strfreev(strv);
1.119 - return NULL;
1.120 - }
1.121 - uint16_t keycode = display_driver->resolve_keysym(g_strstrip(strv[0]));
1.122 - g_strfreev(strv);
1.123 - if( keycode == 0 ) {
1.124 - return NULL;
1.125 - }
1.126 - return &root_keymap[keycode-1];
1.127 + /* root device */
1.128 + if( display_driver == NULL || display_driver->resolve_keysym == NULL) {
1.129 + // Root device has no input handling
1.130 + g_strfreev(strv);
1.131 + return NULL;
1.132 + }
1.133 + uint16_t keycode = display_driver->resolve_keysym(g_strstrip(strv[0]));
1.134 + g_strfreev(strv);
1.135 + if( keycode == 0 ) {
1.136 + return NULL;
1.137 + }
1.138 + return &root_keymap[keycode-1];
1.139 } else {
1.140 - char *id = g_strstrip(strv[0]);
1.141 - GList *ptr;
1.142 - for( ptr = input_drivers; ptr != NULL; ptr = g_list_next(ptr) ) {
1.143 - input_driver_entry_t entry = (input_driver_entry_t)ptr->data;
1.144 - if( strcasecmp( entry->driver->id, id ) == 0 ) {
1.145 - /* we have ze device */
1.146 - if( entry->driver->resolve_keysym == NULL ) {
1.147 - g_strfreev(strv);
1.148 - return NULL;
1.149 - }
1.150 - uint16_t keycode = entry->driver->resolve_keysym(entry->driver, g_strstrip(strv[1]));
1.151 - g_strfreev(strv);
1.152 - if( keycode == 0 || keycode > entry->entry_count ) {
1.153 - return NULL;
1.154 - }
1.155 - return &entry->keymap[keycode-1];
1.156 - }
1.157 - }
1.158 - g_strfreev(strv);
1.159 - return NULL; // device not found
1.160 + char *id = g_strstrip(strv[0]);
1.161 + GList *ptr;
1.162 + for( ptr = input_drivers; ptr != NULL; ptr = g_list_next(ptr) ) {
1.163 + input_driver_entry_t entry = (input_driver_entry_t)ptr->data;
1.164 + if( strcasecmp( entry->driver->id, id ) == 0 ) {
1.165 + /* we have ze device */
1.166 + if( entry->driver->resolve_keysym == NULL ) {
1.167 + g_strfreev(strv);
1.168 + return NULL;
1.169 + }
1.170 + uint16_t keycode = entry->driver->resolve_keysym(entry->driver, g_strstrip(strv[1]));
1.171 + g_strfreev(strv);
1.172 + if( keycode == 0 || keycode > entry->entry_count ) {
1.173 + return NULL;
1.174 + }
1.175 + return &entry->keymap[keycode-1];
1.176 + }
1.177 + }
1.178 + g_strfreev(strv);
1.179 + return NULL; // device not found
1.180 }
1.181 }
1.182
1.183 @@ -198,22 +198,22 @@
1.184 GList *ptr;
1.185
1.186 if( keycode == 0 ) {
1.187 - return NULL;
1.188 + return NULL;
1.189 }
1.190
1.191 if( driver == NULL ) {
1.192 - return &root_keymap[keycode-1];
1.193 + return &root_keymap[keycode-1];
1.194 }
1.195
1.196 for( ptr = input_drivers; ptr != NULL; ptr = g_list_next(ptr) ) {
1.197 - input_driver_entry_t entry = (input_driver_entry_t)ptr->data;
1.198 - if( entry->driver == driver ) {
1.199 - if( keycode > entry->entry_count ) {
1.200 - return NULL;
1.201 - } else {
1.202 - return &entry->keymap[keycode-1];
1.203 - }
1.204 - }
1.205 + input_driver_entry_t entry = (input_driver_entry_t)ptr->data;
1.206 + if( entry->driver == driver ) {
1.207 + if( keycode > entry->entry_count ) {
1.208 + return NULL;
1.209 + } else {
1.210 + return &entry->keymap[keycode-1];
1.211 + }
1.212 + }
1.213 }
1.214 return NULL;
1.215 }
1.216 @@ -221,71 +221,71 @@
1.217 static gchar *input_keysym_for_keycode( input_driver_t driver, uint16_t keycode )
1.218 {
1.219 if( keycode == 0 ) {
1.220 - return NULL;
1.221 + return NULL;
1.222 }
1.223 if( driver == NULL ) {
1.224 - if( display_driver != NULL && display_driver->get_keysym_for_keycode != NULL ) {
1.225 - return display_driver->get_keysym_for_keycode(keycode);
1.226 - }
1.227 + if( display_driver != NULL && display_driver->get_keysym_for_keycode != NULL ) {
1.228 + return display_driver->get_keysym_for_keycode(keycode);
1.229 + }
1.230 } else if( driver->get_keysym_for_keycode ) {
1.231 - gchar *sym = driver->get_keysym_for_keycode(driver,keycode);
1.232 - if( sym != NULL ) {
1.233 - gchar *result = g_strdup_printf( "%s: %s", driver->id, sym );
1.234 - g_free(sym);
1.235 - return result;
1.236 - }
1.237 + gchar *sym = driver->get_keysym_for_keycode(driver,keycode);
1.238 + if( sym != NULL ) {
1.239 + gchar *result = g_strdup_printf( "%s: %s", driver->id, sym );
1.240 + g_free(sym);
1.241 + return result;
1.242 + }
1.243 }
1.244 return NULL;
1.245 }
1.246
1.247
1.248 gboolean input_register_key( const gchar *keysym, input_key_callback_t callback,
1.249 - void *data, uint32_t value )
1.250 + void *data, uint32_t value )
1.251 {
1.252 if( keysym == NULL ) {
1.253 - return FALSE;
1.254 + return FALSE;
1.255 }
1.256 int keys = 0;
1.257 gchar **strv = g_strsplit(keysym, ",", 16);
1.258 gchar **s = strv;
1.259 while( *s != NULL ) {
1.260 - keymap_entry_t *entryp = input_entry_from_keysym(*s);
1.261 - if( entryp != NULL ) {
1.262 - *entryp = g_malloc0(sizeof(struct keymap_entry));
1.263 - (*entryp)->callback = callback;
1.264 - (*entryp)->data = data;
1.265 - (*entryp)->value = value;
1.266 - keys++;
1.267 - }
1.268 - s++;
1.269 + keymap_entry_t *entryp = input_entry_from_keysym(*s);
1.270 + if( entryp != NULL ) {
1.271 + *entryp = g_malloc0(sizeof(struct keymap_entry));
1.272 + (*entryp)->callback = callback;
1.273 + (*entryp)->data = data;
1.274 + (*entryp)->value = value;
1.275 + keys++;
1.276 + }
1.277 + s++;
1.278 }
1.279 g_strfreev(strv);
1.280 return keys != 0;
1.281 }
1.282
1.283 void input_unregister_key( const gchar *keysym, input_key_callback_t callback,
1.284 - void *data, uint32_t value )
1.285 + void *data, uint32_t value )
1.286 {
1.287 if( keysym == NULL ) {
1.288 - return;
1.289 + return;
1.290 }
1.291
1.292 gchar **strv = g_strsplit(keysym, ",", 16);
1.293 gchar **s = strv;
1.294 while( *s != NULL ) {
1.295 - keymap_entry_t *entryp = input_entry_from_keysym(*s);
1.296 - if( entryp != NULL && *entryp != NULL && (*entryp)->callback == callback &&
1.297 - (*entryp)->data == data && (*entryp)->value == value ) {
1.298 - g_free( *entryp );
1.299 - *entryp = NULL;
1.300 - }
1.301 - s++;
1.302 + keymap_entry_t *entryp = input_entry_from_keysym(*s);
1.303 + if( entryp != NULL && *entryp != NULL && (*entryp)->callback == callback &&
1.304 + (*entryp)->data == data && (*entryp)->value == value ) {
1.305 + g_free( *entryp );
1.306 + *entryp = NULL;
1.307 + }
1.308 + s++;
1.309 }
1.310 g_strfreev(strv);
1.311 }
1.312
1.313 gboolean input_register_hook( input_key_callback_t callback,
1.314 - void *data )
1.315 + void *data )
1.316 {
1.317 keymap_entry_t key = malloc( sizeof( struct keymap_entry ) );
1.318 assert( key != NULL );
1.319 @@ -297,29 +297,29 @@
1.320 }
1.321
1.322 void input_unregister_hook( input_key_callback_t callback,
1.323 - void *data )
1.324 + void *data )
1.325 {
1.326 keymap_entry_t key = keyhooks;
1.327 if( key != NULL ) {
1.328 - if( key->callback == callback && key->data == data ) {
1.329 - keyhooks = keyhooks->next;
1.330 - free(key);
1.331 - return;
1.332 - }
1.333 - while( key->next != NULL ) {
1.334 - if( key->next->callback == callback && key->next->data == data ) {
1.335 + if( key->callback == callback && key->data == data ) {
1.336 + keyhooks = keyhooks->next;
1.337 + free(key);
1.338 + return;
1.339 + }
1.340 + while( key->next != NULL ) {
1.341 + if( key->next->callback == callback && key->next->data == data ) {
1.342 keymap_entry_t next = key->next;
1.343 - key->next = next->next;
1.344 - free(next);
1.345 - return;
1.346 - }
1.347 - key = key->next;
1.348 - }
1.349 + key->next = next->next;
1.350 + free(next);
1.351 + return;
1.352 + }
1.353 + key = key->next;
1.354 + }
1.355 }
1.356 }
1.357
1.358 gboolean input_register_mouse_hook( gboolean relative, input_mouse_callback_t callback,
1.359 - void *data )
1.360 + void *data )
1.361 {
1.362 mouse_entry_t ent = malloc( sizeof( struct mouse_entry ) );
1.363 assert( ent != NULL );
1.364 @@ -334,20 +334,20 @@
1.365 {
1.366 mouse_entry_t ent = mousehooks;
1.367 if( ent != NULL ) {
1.368 - if( ent->callback == callback && ent->data == data ) {
1.369 - mousehooks = mousehooks->next;
1.370 - free(ent);
1.371 - return;
1.372 - }
1.373 - while( ent->next != NULL ) {
1.374 - if( ent->next->callback == callback && ent->next->data == data ) {
1.375 + if( ent->callback == callback && ent->data == data ) {
1.376 + mousehooks = mousehooks->next;
1.377 + free(ent);
1.378 + return;
1.379 + }
1.380 + while( ent->next != NULL ) {
1.381 + if( ent->next->callback == callback && ent->next->data == data ) {
1.382 mouse_entry_t next = ent->next;
1.383 - ent->next = next->next;
1.384 - free(next);
1.385 - return;
1.386 - }
1.387 - ent = ent->next;
1.388 - }
1.389 + ent->next = next->next;
1.390 + free(next);
1.391 + return;
1.392 + }
1.393 + ent = ent->next;
1.394 + }
1.395 }
1.396 }
1.397
1.398 @@ -355,8 +355,8 @@
1.399 {
1.400 mouse_entry_t ent = mousehooks;
1.401 while( ent != NULL ) {
1.402 - ent->callback(ent->data, buttons, x, y);
1.403 - ent = ent->next;
1.404 + ent->callback(ent->data, buttons, x, y);
1.405 + ent = ent->next;
1.406 }
1.407 }
1.408
1.409 @@ -375,38 +375,38 @@
1.410 void input_event_keydown( input_driver_t driver, uint16_t keycode, uint32_t pressure )
1.411 {
1.412 if( display_focused ) {
1.413 - keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);
1.414 - if( entryp != NULL && *entryp != NULL ) {
1.415 - (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, TRUE );
1.416 - }
1.417 - keymap_entry_t key = keyhooks;
1.418 - while( key != NULL ) {
1.419 - key->callback( key->data, keycode, pressure, TRUE );
1.420 - key = key->next;
1.421 - }
1.422 + keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);
1.423 + if( entryp != NULL && *entryp != NULL ) {
1.424 + (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, TRUE );
1.425 + }
1.426 + keymap_entry_t key = keyhooks;
1.427 + while( key != NULL ) {
1.428 + key->callback( key->data, keycode, pressure, TRUE );
1.429 + key = key->next;
1.430 + }
1.431 }
1.432 if( display_keysym_hook != NULL ) {
1.433 - gchar *sym = input_keysym_for_keycode( driver, keycode );
1.434 - if( sym != NULL ) {
1.435 - display_keysym_hook(display_keysym_hook_data, sym);
1.436 - g_free(sym);
1.437 - }
1.438 + gchar *sym = input_keysym_for_keycode( driver, keycode );
1.439 + if( sym != NULL ) {
1.440 + display_keysym_hook(display_keysym_hook_data, sym);
1.441 + g_free(sym);
1.442 + }
1.443 }
1.444 }
1.445
1.446 void input_event_keyup( input_driver_t driver, uint16_t keycode, uint32_t pressure )
1.447 {
1.448 if( display_focused ) {
1.449 - keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);
1.450 - if( entryp != NULL && *entryp != NULL ) {
1.451 - (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, FALSE );
1.452 - }
1.453 + keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);
1.454 + if( entryp != NULL && *entryp != NULL ) {
1.455 + (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, FALSE );
1.456 + }
1.457
1.458 - keymap_entry_t key = keyhooks;
1.459 - while( key != NULL ) {
1.460 - key->callback( key->data, keycode, pressure, FALSE );
1.461 - key = key->next;
1.462 - }
1.463 + keymap_entry_t key = keyhooks;
1.464 + while( key != NULL ) {
1.465 + key->callback( key->data, keycode, pressure, FALSE );
1.466 + key = key->next;
1.467 + }
1.468 }
1.469 }
1.470
1.471 @@ -421,7 +421,7 @@
1.472 fprintf( out, "Available video drivers:\n" );
1.473 for( i=0; display_driver_list[i] != NULL; i++ ) {
1.474 fprintf( out, " %-8s %s\n", display_driver_list[i]->name,
1.475 - gettext(display_driver_list[i]->description) );
1.476 + gettext(display_driver_list[i]->description) );
1.477 }
1.478 }
1.479
1.480 @@ -429,12 +429,12 @@
1.481 {
1.482 int i;
1.483 if( name == NULL ) {
1.484 - return display_driver_list[0];
1.485 + return display_driver_list[0];
1.486 }
1.487 for( i=0; display_driver_list[i] != NULL; i++ ) {
1.488 - if( strcasecmp( display_driver_list[i]->name, name ) == 0 ) {
1.489 - return display_driver_list[i];
1.490 - }
1.491 + if( strcasecmp( display_driver_list[i]->name, name ) == 0 ) {
1.492 + return display_driver_list[i];
1.493 + }
1.494 }
1.495
1.496 return NULL;
1.497 @@ -445,13 +445,13 @@
1.498 {
1.499 gboolean rv = TRUE;
1.500 if( display_driver != NULL && display_driver->shutdown_driver != NULL )
1.501 - display_driver->shutdown_driver();
1.502 + display_driver->shutdown_driver();
1.503
1.504 display_driver = driver;
1.505 if( driver->init_driver != NULL )
1.506 - rv = driver->init_driver();
1.507 + rv = driver->init_driver();
1.508 if( !rv ) {
1.509 - display_driver = NULL;
1.510 + display_driver = NULL;
1.511 }
1.512 return rv;
1.513 }
.