diff --git a/blackberry-qnx/qnx_input.c b/blackberry-qnx/qnx_input.c index 37cd523125..b386a088ef 100644 --- a/blackberry-qnx/qnx_input.c +++ b/blackberry-qnx/qnx_input.c @@ -49,11 +49,16 @@ struct touches int map; }; -static struct touches touch[MAX_TOUCH]; -static unsigned touch_count; -//The first touch_count indices of touch_map will be a valid, active index in touch array. -//Saves us from searching through touch array when polling state. -static int touch_map[MAX_TOUCH]; +typedef struct qnx_input +{ + struct touches touch[MAX_TOUCH]; + unsigned touch_count; + + int touch_map[MAX_TOUCH]; + /*The first touch_count indices of touch_map will be a valid, active index in touch array. + * Saves us from searching through touch array when polling state. + */ +} qnx_input_t; input_device_t devices[MAX_PADS]; input_device_t *port_device[MAX_PADS]; @@ -66,13 +71,14 @@ static void qnx_input_autodetect_gamepad(input_device_t* controller); static void initController(input_device_t* controller); #ifdef HAVE_BB10 -static void process_gamepad_event(screen_event_t screen_event, int type) +static void process_gamepad_event(void *data, screen_event_t screen_event, int type) { + int i; screen_device_t device; + input_device_t* controller = NULL; + screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DEVICE, (void**)&device); - input_device_t* controller = NULL; - int i; for (i = 0; i < MAX_PADS; ++i) { if (device == devices[i].handle) @@ -140,10 +146,10 @@ static void loadController(input_device_t* controller) } extern screen_context_t screen_ctx; -void discoverControllers() +void discoverControllers(void) { // Get an array of all available devices. - int deviceCount; + int deviceCount, i; screen_event_t *event; screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DEVICE_COUNT, &deviceCount); @@ -151,9 +157,7 @@ void discoverControllers() screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DEVICES, (void**)devices_found); // Scan the list for gamepad and joystick devices. - int i; - - for(i=0;iport == -1) return; - int b; for (b = 0; b < RARCH_FIRST_CUSTOM_BIND; ++b) { if ((unsigned int)g_settings.input.binds[controller->port][b].joykey == (unsigned int)(sym&0xFF)) @@ -308,11 +314,10 @@ static void process_keyboard_event(screen_event_t event, int type) g_extern.lifecycle_state ^= (1ULL << RARCH_MENU_TOGGLE); } -static void process_touch_event(screen_event_t event, int type) +static void process_touch_event(void *data, screen_event_t event, int type) { - int contact_id; - int pos[2]; - int i; + int contact_id, i, j, pos[2]; + qnx_input_t *qnx = (qnx_input_t*)data; screen_get_event_property_iv(event, SCREEN_PROPERTY_TOUCH_ID, (int*)&contact_id); screen_get_event_property_iv(event, SCREEN_PROPERTY_SOURCE_POSITION, pos); @@ -321,53 +326,52 @@ static void process_touch_event(screen_event_t event, int type) { case SCREEN_EVENT_MTOUCH_TOUCH: //Find a free touch struct - for(i=0;itouch[i].contact_id == -1) { - touch[i].contact_id = contact_id; + qnx->touch[i].contact_id = contact_id; input_translate_coord_viewport(pos[0], pos[1], - &touch[i].x, &touch[i].y, - &touch[i].full_x, &touch[i].full_y); + &qnx->touch[i].x, &qnx->touch[i].y, + &qnx->touch[i].full_x, &qnx->touch[i].full_y); //Add this touch to the map to signal it's valid - touch[i].map = touch_count; - touch_map[touch_count] = i; - touch_count++; + qnx->touch[i].map = qnx->touch_count; + qnx->touch_map[qnx->touch_count] = i; + qnx->touch_count++; break; } } //printf("New Touch: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id);fflush(stdout); - //printf("Map: %d %d %d %d %d %d\n", touch_map[0], touch_map[1], touch_map[2], touch_map[3], touch_map[4], touch_map[5]);fflush(stdout); + //printf("Map: %d %d %d %d %d %d\n", qnx->touch_map[0], qnx->touch_map[1], qnx->touch_map[2], qnx->touch_map[3], qnx->touch_map[4], qnx->touch_map[5]);fflush(stdout); break; case SCREEN_EVENT_MTOUCH_RELEASE: - for(i=0; itouch[i].contact_id == contact_id) { //Invalidate the finger - touch[i].contact_id = -1; + qnx->touch[i].contact_id = -1; //Remove touch from map and shift remaining valid ones to the front - touch_map[touch[i].map] = -1; - int j; - for(j=touch[i].map;jtouch_map[qnx->touch[i].map] = -1; + for(j = qnx->touch[i].map; j < qnx->touch_count; ++j) { - touch_map[j] = touch_map[j+1]; - touch[touch_map[j+1]].map = j; - touch_map[j+1] = -1; + qnx->touch_map[j] = qnx->touch_map[j+1]; + qnx->touch[qnx->touch_map[j+1]].map = j; + qnx->touch_map[j+1] = -1; } - touch_count--; + qnx->touch_count--; break; } } //printf("Release: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id);fflush(stdout); - //printf("Map: %d %d %d %d %d %d\n", touch_map[0], touch_map[1], touch_map[2], touch_map[3], touch_map[4], touch_map[5]);fflush(stdout); + //printf("Map: %d %d %d %d %d %d\n", qnx->touch_map[0], qnx->touch_map[1], qnx->touch_map[2], qnx->touch_map[3], qnx->touch_map[4], qnx->touch_map[5]);fflush(stdout); break; case SCREEN_EVENT_MTOUCH_MOVE: //Find the finger we're tracking and update - for(i=0; itouch_count; ++i) { - if(touch[i].contact_id == contact_id) + if(qnx->touch[i].contact_id == contact_id) { //During a move, we can go ~30 pixel into the bezel which gives negative //numbers or numbers larger than the screen res. Normalize. @@ -382,8 +386,8 @@ static void process_touch_event(screen_event_t event, int type) pos[1] = screen_height; input_translate_coord_viewport(pos[0], pos[1], - &touch[i].x, &touch[i].y, - &touch[i].full_x, &touch[i].full_y); + &qnx->touch[i].x, &qnx->touch[i].y, + &qnx->touch[i].full_x, &qnx->touch[i].full_y); //printf("Move: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id);fflush(stdout); break; } @@ -392,7 +396,7 @@ static void process_touch_event(screen_event_t event, int type) } } -static void handle_screen_event(bps_event_t *event) +static void handle_screen_event(void *data, bps_event_t *event) { int type; @@ -404,22 +408,21 @@ static void handle_screen_event(bps_event_t *event) case SCREEN_EVENT_MTOUCH_TOUCH: case SCREEN_EVENT_MTOUCH_RELEASE: case SCREEN_EVENT_MTOUCH_MOVE: - process_touch_event(screen_event, type); + process_touch_event(data, screen_event, type); break; case SCREEN_EVENT_KEYBOARD: - process_keyboard_event(screen_event, type); + process_keyboard_event(data, screen_event, type); break; #ifdef HAVE_BB10 case SCREEN_EVENT_GAMEPAD: case SCREEN_EVENT_JOYSTICK: - process_gamepad_event(screen_event, type); + process_gamepad_event(data, screen_event, type); break; case SCREEN_EVENT_DEVICE: { // A device was attached or removed. screen_device_t device; - int attached; - int type; + int attached, type, i; screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DEVICE, (void**)&device); @@ -430,8 +433,6 @@ static void handle_screen_event(bps_event_t *event) screen_get_device_property_iv(device, SCREEN_PROPERTY_TYPE, &type); - int i; - if (attached && (type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK || type == SCREEN_EVENT_KEYBOARD)) { for (i = 0; i < MAX_PADS; ++i) @@ -464,7 +465,7 @@ static void handle_screen_event(bps_event_t *event) } } -static void handle_navigator_event(bps_event_t *event) +static void handle_navigator_event(void *data, bps_event_t *event) { navigator_window_state_t state; bps_event_t *event_pause = NULL; @@ -517,19 +518,18 @@ static void handle_navigator_event(bps_event_t *event) static void *qnx_input_init(void) { int i; - static int initialized = 0; + qnx_input_t *qnx = (qnx_input_t*)calloc(1, sizeof(*qnx)); + if (!qnx) + return NULL; //Get screen dimensions if(gfx_ctx_bbqnx.get_video_size) gfx_ctx_bbqnx.get_video_size(driver.video_data, &screen_width, &screen_height); - if(initialized) - return (void*)-1; - for (i = 0; i < MAX_TOUCH; ++i) { - touch[i].contact_id = -1; - touch_map[i] = -1; + qnx->touch[i].contact_id = -1; + qnx->touch_map[i] = -1; } for (i = 0; i < MAX_PADS; ++i) @@ -544,9 +544,7 @@ static void *qnx_input_init(void) init_playbook_keyboard(); #endif - initialized = 1; - - return (void*)-1; + return qnx; } static void qnx_input_poll(void *data) @@ -568,9 +566,9 @@ static void qnx_input_poll(void *data) { domain = bps_event_get_domain(event); if (domain == navigator_get_domain()) - handle_navigator_event(event); + handle_navigator_event(data, event); else if (domain == screen_get_domain()) - handle_screen_event(event); + handle_screen_event(data, event); } else break; @@ -580,7 +578,7 @@ static void qnx_input_poll(void *data) static int16_t qnx_input_state(void *data, const struct retro_keybind **retro_keybinds, unsigned port, unsigned device, unsigned index, unsigned id) { - (void)data; + qnx_input_t *qnx = (qnx_input_t*)data; switch (device) { @@ -624,9 +622,12 @@ static int16_t qnx_input_state(void *data, const struct retro_keybind **retro_ke switch (id) { - case RETRO_DEVICE_ID_POINTER_X: return want_full ? touch[touch_map[index]].full_x : touch[touch_map[index]].x; - case RETRO_DEVICE_ID_POINTER_Y: return want_full ? touch[touch_map[index]].full_y : touch[touch_map[index]].y; - case RETRO_DEVICE_ID_POINTER_PRESSED: return (touch_map[index] != -1); + case RETRO_DEVICE_ID_POINTER_X: + return want_full ? qnx->touch[qnx->touch_map[index]].full_x : qnx->touch[qnx->touch_map[index]].x; + case RETRO_DEVICE_ID_POINTER_Y: + return want_full ? qnx->touch[qnx->touch_map[index]].full_y : qnx->touch[qnx->touch_map[index]].y; + case RETRO_DEVICE_ID_POINTER_PRESSED: + return (qnx->touch_map[index] != -1); } break; @@ -645,12 +646,17 @@ static bool qnx_input_key_pressed(void *data, int key) static void qnx_input_free_input(void *data) { - (void)data; + qnx_input_t *qnx = (qnx_input_t*)data; + + if (qnx) + free(qnx); + qnx = 0; } static void qnx_input_set_keybinds(void *data, unsigned device, unsigned port, unsigned id, unsigned keybind_action) { + int i; input_device_t *controller = (input_device_t*)data; #ifdef HAVE_BB10 uint64_t *key = &g_settings.input.binds[port][id].joykey; @@ -818,7 +824,7 @@ static void qnx_input_set_keybinds(void *data, unsigned device, unsigned port, #endif } - for (unsigned i = 0; i < RARCH_CUSTOM_BIND_LIST_END; i++) + for (i = 0; i < RARCH_CUSTOM_BIND_LIST_END; i++) { g_settings.input.binds[port][i].id = i; g_settings.input.binds[port][i].joykey = g_settings.input.binds[port][i].def_joykey;