Merge pull request #4169 from AdrianoML/kbmquake

Changes to make keyboard and mouse games more playable
This commit is contained in:
Twinaphex 2016-12-06 07:21:20 +01:00 committed by GitHub
commit 3a399340e3
13 changed files with 117 additions and 17 deletions

View File

@ -294,6 +294,7 @@ static const struct cmd_map map[] = {
{ "DISK_NEXT", RARCH_DISK_NEXT },
{ "DISK_PREV", RARCH_DISK_PREV },
{ "GRAB_MOUSE_TOGGLE", RARCH_GRAB_MOUSE_TOGGLE },
{ "GAME_FOCUS_TOGGLE", RARCH_GAME_FOCUS_TOGGLE },
{ "MENU_TOGGLE", RARCH_MENU_TOGGLE },
{ "MENU_UP", RETRO_DEVICE_ID_JOYPAD_UP },
{ "MENU_DOWN", RETRO_DEVICE_ID_JOYPAD_DOWN },
@ -1936,6 +1937,7 @@ bool command_event(enum event_command cmd, void *data)
video_driver_reinit();
/* Poll input to avoid possibly stale data to corrupt things. */
input_driver_poll();
command_event(CMD_EVENT_GAME_FOCUS_TOGGLE, (void *) -1);
#ifdef HAVE_MENU
menu_display_set_framebuffer_dirty_flag();
@ -2495,6 +2497,42 @@ bool command_event(enum event_command cmd, void *data)
video_driver_show_mouse();
}
break;
case CMD_EVENT_GAME_FOCUS_TOGGLE:
{
static bool game_focus_state = false;
long int mode = (long int)data;
/* mode = -1: restores current game focus state
* mode = 1: force set game focus, instead of toggling
* any other: toggle
*/
if (mode == 1)
game_focus_state = true;
else if (mode != -1)
game_focus_state = !game_focus_state;
RARCH_LOG("%s: %s.\n",
"Game focus is: ",
game_focus_state ? "on" : "off");
if (game_focus_state) {
input_driver_grab_mouse();
video_driver_hide_mouse();
input_driver_set_hotkey_block();
input_driver_keyboard_mapping_set_block(1);
runloop_msg_queue_push(msg_hash_to_str(MSG_GAME_FOCUS_ON),
1, 120, true);
} else {
input_driver_ungrab_mouse();
video_driver_show_mouse();
input_driver_unset_hotkey_block();
input_driver_keyboard_mapping_set_block(0);
runloop_msg_queue_push(msg_hash_to_str(MSG_GAME_FOCUS_OFF),
1, 120, true);
}
}
break;
case CMD_EVENT_PERFCNT_REPORT_FRONTEND_LOG:
rarch_perf_log();
break;

View File

@ -204,6 +204,8 @@ enum event_command
CMD_EVENT_RUMBLE_STOP,
/* Toggles mouse grab. */
CMD_EVENT_GRAB_MOUSE_TOGGLE,
/* Toggles game focus. */
CMD_EVENT_GAME_FOCUS_TOGGLE,
/* Toggles fullscreen mode. */
CMD_EVENT_FULLSCREEN_TOGGLE,
CMD_EVENT_PERFCNT_REPORT_FRONTEND_LOG,

View File

@ -993,6 +993,7 @@ static const struct retro_keybind retro_keybinds_1[] = {
{ true, RARCH_DISK_NEXT, MENU_ENUM_LABEL_VALUE_INPUT_META_DISK_NEXT, RETROK_UNKNOWN, NO_BTN, 0, AXIS_NONE },
{ true, RARCH_DISK_PREV, MENU_ENUM_LABEL_VALUE_INPUT_META_DISK_PREV, RETROK_UNKNOWN, NO_BTN, 0, AXIS_NONE },
{ true, RARCH_GRAB_MOUSE_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_GRAB_MOUSE_TOGGLE, RETROK_F11, NO_BTN, 0, AXIS_NONE },
{ true, RARCH_GAME_FOCUS_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_GAME_FOCUS_TOGGLE, RETROK_SCROLLOCK, NO_BTN, 0, AXIS_NONE },
{ true, RARCH_MENU_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_MENU_TOGGLE, RETROK_F1, NO_BTN, 0, AXIS_NONE },
};

View File

@ -316,6 +316,7 @@ static void x_input_poll_mouse(x11_input_t *x11)
XWarpPointer(x11->display, None,
x11->win, 0, 0, 0, 0,
mid_w, mid_h);
XSync(x11->display, False);
}
x11->mouse_last_x = mid_w;
x11->mouse_last_y = mid_h;

View File

@ -16,6 +16,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysymdef.h>
#include <X11/extensions/xf86vmode.h>
#include <boolean.h>
@ -37,7 +38,8 @@
void x11_handle_key_event(XEvent *event, XIC ic, bool filter)
{
int i;
unsigned state, key;
unsigned key;
unsigned state = event->xkey.state;
uint16_t mod = 0;
uint32_t chars[32];
@ -47,32 +49,41 @@ void x11_handle_key_event(XEvent *event, XIC ic, bool filter)
chars[0] = '\0';
if (down && !filter)
if (!filter)
{
char keybuf[32];
if (down)
{
char keybuf[32];
keybuf[0] = '\0';
keybuf[0] = '\0';
#ifdef X_HAVE_UTF8_STRING
Status status = 0;
Status status = 0;
/* XwcLookupString doesn't seem to work. */
num = Xutf8LookupString(ic, &event->xkey, keybuf, ARRAY_SIZE(keybuf), &keysym, &status);
/* XwcLookupString doesn't seem to work. */
num = Xutf8LookupString(ic, &event->xkey, keybuf, ARRAY_SIZE(keybuf), &keysym, &status);
/* libc functions need UTF-8 locale to work properly,
* which makes mbrtowc a bit impractical.
*
* Use custom UTF8 -> UTF-32 conversion. */
num = utf8_conv_utf32(chars, ARRAY_SIZE(chars), keybuf, num);
/* libc functions need UTF-8 locale to work properly,
* which makes mbrtowc a bit impractical.
*
* Use custom UTF8 -> UTF-32 conversion. */
num = utf8_conv_utf32(chars, ARRAY_SIZE(chars), keybuf, num);
#else
(void)ic;
num = XLookupString(&event->xkey, keybuf, sizeof(keybuf), &keysym, NULL); /* ASCII only. */
for (i = 0; i < num; i++)
chars[i] = keybuf[i] & 0x7f;
(void)ic;
num = XLookupString(&event->xkey, keybuf, sizeof(keybuf), &keysym, NULL); /* ASCII only. */
for (i = 0; i < num; i++)
chars[i] = keybuf[i] & 0x7f;
#endif
}
else
keysym = XLookupKeysym(&event->xkey, (state & ShiftMask) || (state & LockMask));
}
/* We can't feed uppercase letters to the keycode translator. Seems like a bad idea
* to feed it keysyms anyway, so here is a little hack... */
if (keysym >= XK_A && keysym <= XK_Z)
keysym += XK_z - XK_Z;
key = input_keymaps_translate_keysym_to_rk(keysym);
state = event->xkey.state;
if (state & ShiftMask)
mod |= RETROKMOD_SHIFT;

View File

@ -134,6 +134,7 @@ const struct input_bind_map input_config_bind_map[RARCH_BIND_LIST_END_NULL] = {
DECLARE_META_BIND(2, disk_next, RARCH_DISK_NEXT, MENU_ENUM_LABEL_VALUE_INPUT_META_DISK_NEXT),
DECLARE_META_BIND(2, disk_prev, RARCH_DISK_PREV, MENU_ENUM_LABEL_VALUE_INPUT_META_DISK_PREV),
DECLARE_META_BIND(2, grab_mouse_toggle, RARCH_GRAB_MOUSE_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_GRAB_MOUSE_TOGGLE),
DECLARE_META_BIND(2, game_focus_toggle, RARCH_GAME_FOCUS_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_GAME_FOCUS_TOGGLE),
#ifdef HAVE_MENU
DECLARE_META_BIND(1, menu_toggle, RARCH_MENU_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_MENU_TOGGLE),
#endif

View File

@ -81,6 +81,7 @@ enum
RARCH_DISK_NEXT,
RARCH_DISK_PREV,
RARCH_GRAB_MOUSE_TOGGLE,
RARCH_GAME_FOCUS_TOGGLE,
RARCH_MENU_TOGGLE,

View File

@ -672,6 +672,9 @@ uint64_t input_keys_pressed(void)
const struct retro_keybind *binds_auto = &settings->input.autoconf_binds[0][RARCH_ENABLE_HOTKEY];
const struct retro_keybind *normal = &binds[RARCH_ENABLE_HOTKEY];
const struct retro_keybind *focus_binds_auto = &settings->input.autoconf_binds[0][RARCH_GAME_FOCUS_TOGGLE];
const struct retro_keybind *focus_normal = &binds[RARCH_GAME_FOCUS_TOGGLE];
input_driver_block_libretro_input = false;
input_driver_block_hotkey = false;
@ -690,6 +693,14 @@ uint64_t input_keys_pressed(void)
input_driver_block_hotkey = true;
}
/* Allows rarch_focus_toggle hotkey to still work even tough every hotkey is blocked */
if (check_input_driver_block_hotkey(focus_normal, focus_binds_auto))
{
if (current_input->input_state(current_input_data, &binds, 0,
RETRO_DEVICE_JOYPAD, 0, RARCH_GAME_FOCUS_TOGGLE))
input_driver_block_hotkey = false;
}
for (i = 0; i < RARCH_BIND_LIST_END; i++)
{
if (input_keys_pressed_internal(i, binds))
@ -954,6 +965,11 @@ bool input_driver_is_flushing_input(void)
return input_driver_flushing_input;
}
void input_driver_unset_hotkey_block(void)
{
input_driver_block_hotkey = true;
}
void input_driver_set_hotkey_block(void)
{
input_driver_block_hotkey = true;

View File

@ -292,6 +292,8 @@ void input_driver_unset_flushing_input(void);
bool input_driver_is_flushing_input(void);
void input_driver_unset_hotkey_block(void);
void input_driver_set_hotkey_block(void);
bool input_driver_is_hotkey_blocked(void);

View File

@ -146,6 +146,13 @@ int menu_hash_get_help_us_enum(enum msg_hash_enums msg, char *s, size_t len)
"the window to allow relative mouse input to \n"
"work better.");
break;
case RARCH_GAME_FOCUS_TOGGLE:
snprintf(s, len,
"Toggles game focus.\n"
" \n"
"When a game has focus, RetroArch will both disable \n"
"hotkeys and keep/warp the mouse pointer inside the window.");
break;
case RARCH_MENU_TOGGLE:
snprintf(s, len, "Toggles menu.");
break;
@ -1070,6 +1077,13 @@ int menu_hash_get_help_us_enum(enum msg_hash_enums msg, char *s, size_t len)
"the window to allow relative mouse input to \n"
"work better.");
break;
case MENU_ENUM_LABEL_GAME_FOCUS_TOGGLE:
snprintf(s, len,
"Toggles game focus.\n"
" \n"
"When a game has focus, RetroArch will both disable \n"
"hotkeys and keep/warp the mouse pointer inside the window.");
break;
case MENU_ENUM_LABEL_DISK_NEXT:
snprintf(s, len,
"Cycles through disk images. Use after \n"

View File

@ -702,6 +702,8 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_META_FULLSCREEN_TOGGLE_KEY,
"Fullscreen toggle")
MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_META_GRAB_MOUSE_TOGGLE,
"Grab mouse toggle")
MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_META_GAME_FOCUS_TOGGLE,
"Game focus toggle")
MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_META_LOAD_STATE_KEY,
"Load state")
MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_META_MENU_TOGGLE,
@ -1922,6 +1924,10 @@ MSG_HASH(MSG_GOT_INVALID_DISK_INDEX,
"Got invalid disk index.")
MSG_HASH(MSG_GRAB_MOUSE_STATE,
"Grab mouse state")
MSG_HASH(MSG_GAME_FOCUS_ON,
"Game focus on")
MSG_HASH(MSG_GAME_FOCUS_OFF,
"Game focus off")
MSG_HASH(MSG_HW_RENDERED_MUST_USE_POSTSHADED_RECORDING,
"Libretro core is hardware rendered. Must use post-shaded recording as well.")
MSG_HASH(MSG_INFLATED_CHECKSUM_DID_NOT_MATCH_CRC32,

View File

@ -337,6 +337,8 @@ enum msg_hash_enums
MSG_UNPAUSED,
MSG_CORE_DOES_NOT_SUPPORT_DISK_OPTIONS,
MSG_GRAB_MOUSE_STATE,
MSG_GAME_FOCUS_ON,
MSG_GAME_FOCUS_OFF,
MSG_FAILED_TO_LOAD_MOVIE_FILE,
MSG_FAILED_TO,
MSG_SAVING_RAM_TYPE,
@ -534,6 +536,7 @@ enum msg_hash_enums
MENU_ENUM_LABEL_VALUE_INPUT_META_DISK_NEXT,
MENU_ENUM_LABEL_VALUE_INPUT_META_DISK_PREV,
MENU_ENUM_LABEL_VALUE_INPUT_META_GRAB_MOUSE_TOGGLE,
MENU_ENUM_LABEL_VALUE_INPUT_META_GAME_FOCUS_TOGGLE,
MENU_ENUM_LABEL_VALUE_INPUT_META_MENU_TOGGLE,
MENU_ENUM_LABEL_VALUE_INPUT_DEVICE_INDEX,
@ -1006,6 +1009,7 @@ enum msg_hash_enums
MENU_ENUM_LABEL_DISK_EJECT_TOGGLE,
MENU_ENUM_LABEL_DISK_NEXT,
MENU_ENUM_LABEL_GRAB_MOUSE_TOGGLE,
MENU_ENUM_LABEL_GAME_FOCUS_TOGGLE,
MENU_LABEL(STATE_SLOT_DECREASE),
MENU_LABEL(STATE_SLOT_INCREASE),

View File

@ -888,6 +888,9 @@ static enum runloop_state runloop_check_state(
if (runloop_idle)
return RUNLOOP_STATE_SLEEP;
if (runloop_cmd_triggered(trigger_input, RARCH_GAME_FOCUS_TOGGLE))
command_event(CMD_EVENT_GAME_FOCUS_TOGGLE, NULL);
#ifdef HAVE_MENU
if (menu_event_keyboard_is_set(RETROK_F1) == 1)
{