input: map OK/Back buttons for OSD, Back+OK in OSD -> unmount action.

This commit is contained in:
sorgelig
2019-12-27 08:34:54 +08:00
parent 8f9387b9f3
commit 81fac39308
3 changed files with 70 additions and 17 deletions

View File

@@ -1477,6 +1477,7 @@ static void mouse_cb(unsigned char b, int16_t x = 0, int16_t y = 0, int16_t w =
static void joy_digital(int jnum, uint32_t mask, uint32_t code, char press, int bnum, int dont_save = 0)
{
static uint32_t osdbtn = 0;
static char str[128];
static uint32_t lastcode[NUMPLAYERS], lastmask[NUMPLAYERS];
int num = jnum - 1;
@@ -1593,6 +1594,31 @@ static void joy_digital(int jnum, uint32_t mask, uint32_t code, char press, int
if (user_io_osd_is_visible() || (bnum == BTN_OSD))
{
if (press)
{
osdbtn |= mask;
if ((osdbtn & (JOY_BTN1 | JOY_BTN2)) == (JOY_BTN1 | JOY_BTN2))
{
osdbtn |= JOY_BTN3;
mask = JOY_BTN3;
}
}
else
{
int old_osdbtn = osdbtn;
osdbtn &= ~mask;
if ((old_osdbtn & (JOY_BTN1 | JOY_BTN2 | JOY_BTN3)) == (JOY_BTN1 | JOY_BTN2 | JOY_BTN3))
{
mask = JOY_BTN3;
}
else if (old_osdbtn & JOY_BTN3)
{
if (!(osdbtn & (JOY_BTN1 | JOY_BTN2))) osdbtn &= ~JOY_BTN3;
mask = 0;
}
}
memset(joy, 0, sizeof(joy));
struct input_event ev;
ev.type = EV_KEY;
@@ -1865,7 +1891,7 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
}
mapping_clear = 0;
if (mapping_dev >= 0 && (mapping_dev == dev || clear) && mapping_button < (is_menu_core() ? (SYS_BTN_OSD_KTGL+1) : mapping_count))
if (mapping_dev >= 0 && (mapping_dev == dev || clear) && mapping_button < (is_menu_core() ? (mapping_type ? SYS_BTN_CNT_ESC + 1 : SYS_BTN_OSD_KTGL + 1) : mapping_count))
{
if (ev->value == 1 && !key_mapped)
{
@@ -1881,8 +1907,14 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
if (!found || (mapping_button == SYS_BTN_OSD_KTGL && mapping_type))
{
input[dev].map[(mapping_button == SYS_BTN_OSD_KTGL) ? SYS_BTN_OSD_KTGL + mapping_type : mapping_button] = ev->code;
input[dev].map[SYS_BTN_OSD_KTGL + 2] = input[dev].map[SYS_BTN_OSD_KTGL + 1];
if (mapping_button == SYS_BTN_CNT_OK) input[dev].map[SYS_BTN_MENU_FUNC] = ev->code & 0xFFFF;
else if (mapping_button == SYS_BTN_CNT_ESC) input[dev].map[SYS_BTN_MENU_FUNC] = (ev->code << 16) | input[dev].map[SYS_BTN_MENU_FUNC];
else if (mapping_button == SYS_BTN_OSD_KTGL)
{
input[dev].map[SYS_BTN_OSD_KTGL + mapping_type] = ev->code;
input[dev].map[SYS_BTN_OSD_KTGL + 2] = input[dev].map[SYS_BTN_OSD_KTGL + 1];
}
else input[dev].map[mapping_button] = ev->code;
key_mapped = ev->code;
@@ -1961,10 +1993,8 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
{
switch (mapping_button)
{
case 21: idx = SYS_AXIS_X; break;
case 22: idx = SYS_AXIS_Y; break;
case 23: idx = SYS_AXIS_MX; break;
case 24: idx = SYS_AXIS_MY; break;
case 23: idx = SYS_AXIS_X; break;
case 24: idx = SYS_AXIS_Y; break;
case -4: idx = SYS_AXIS1_X; break;
case -3: idx = SYS_AXIS1_Y; break;
case -2: idx = SYS_AXIS2_X; break;
@@ -2073,8 +2103,7 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
if (idx) input[mapping_dev].map[idx] = 0;
else if (mapping_button > 0)
{
if (is_menu_core()) input[mapping_dev].map[mapping_button] = 0;
else input[mapping_dev].map[mapping_button] &= mapping_set ? 0x0000FFFF : 0xFFFF0000;
if (!is_menu_core()) input[mapping_dev].map[mapping_button] &= mapping_set ? 0x0000FFFF : 0xFFFF0000;
}
}
last_axis = 0;
@@ -2137,7 +2166,23 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
{
if (ev->value <= 1)
{
for (int i = 0; i <= SYS_BTN_Y; i++)
if ((input[dev].mmap[SYS_BTN_MENU_FUNC] & 0xFFFF) ?
(ev->code == (input[dev].mmap[SYS_BTN_MENU_FUNC] & 0xFFFF)) :
(ev->code == input[dev].mmap[SYS_BTN_A]))
{
joy_digital(0, JOY_BTN1, 0, ev->value, 0);
return;
}
if ((input[dev].mmap[SYS_BTN_MENU_FUNC] >> 16) ?
(ev->code == (input[dev].mmap[SYS_BTN_MENU_FUNC] >> 16)) :
(ev->code == input[dev].mmap[SYS_BTN_B]))
{
joy_digital(0, JOY_BTN2, 0, ev->value, 0);
return;
}
for (int i = 0; i < SYS_BTN_A; i++)
{
if (ev->code == input[dev].mmap[i])
{

View File

@@ -53,6 +53,7 @@
#define SYS_MS_BTN_M 18
#define SYS_MS_BTN_EMU 19
#define SYS_BTN_OSD_KTGL 20 // 20 for keyboard, 21+22 for gamepad
#define SYS_BTN_MENU_FUNC 23
#define SYS_AXIS1_X 24
#define SYS_AXIS1_Y 25
#define SYS_AXIS2_X 26
@@ -62,6 +63,9 @@
#define SYS_AXIS_MX 30
#define SYS_AXIS_MY 31
#define SYS_BTN_CNT_OK 21
#define SYS_BTN_CNT_ESC 22
#define KEY_EMU (KEY_MAX+1)
void set_kbdled(int mask, int state);

View File

@@ -2220,7 +2220,7 @@ void HandleUI(void)
p = joy_bnames[get_map_button() - DPAD_NAMES];
if (is_menu_core())
{
if (get_map_type()) joy_bcount = 19;
if (get_map_type()) joy_bcount = 21;
if (get_map_button() == SYS_BTN_OSD_KTGL)
{
p = joy_button_map[DPAD_BUTTON_NAMES + get_map_type()];
@@ -2239,9 +2239,9 @@ void HandleUI(void)
if (get_map_button() >= 0)
{
if (is_menu_core() && get_map_button() > SYS_BTN_OSD_KTGL)
if (is_menu_core() && get_map_button() > SYS_BTN_CNT_ESC)
{
strcpy(s, joy_button_map[(get_map_button() - SYS_BTN_OSD_KTGL - 1) + DPAD_BUTTON_NAMES + 2]);
strcpy(s, joy_button_map[(get_map_button() - SYS_BTN_CNT_ESC - 1) + DPAD_BUTTON_NAMES + 2]);
}
else
{
@@ -3237,7 +3237,8 @@ void HandleUI(void)
{
for (int i = 0; i < OsdGetSize(); i++) OsdWrite(i, "", 0, 0);
OsdWrite(OsdGetSize() / 2, " Unmounting the image", 0, 0);
usleep(1500000);
OsdUpdate();
sleep(1);
SelectedPath[0] = 0;
menustate = fs_MenuSelect;
}
@@ -4128,9 +4129,9 @@ void HandleUI(void)
menusub = 0;
break;
case 2:
strcpy(joy_bnames[SYS_BTN_A - DPAD_NAMES], "A (OK/Enter)");
strcpy(joy_bnames[SYS_BTN_B - DPAD_NAMES], "B (ESC/Back)");
strcpy(joy_bnames[SYS_BTN_X - DPAD_NAMES], "X (Backspace)");
strcpy(joy_bnames[SYS_BTN_A - DPAD_NAMES], "A");
strcpy(joy_bnames[SYS_BTN_B - DPAD_NAMES], "B");
strcpy(joy_bnames[SYS_BTN_X - DPAD_NAMES], "X");
strcpy(joy_bnames[SYS_BTN_Y - DPAD_NAMES], "Y");
strcpy(joy_bnames[SYS_BTN_L - DPAD_NAMES], "L");
strcpy(joy_bnames[SYS_BTN_R - DPAD_NAMES], "R");
@@ -4144,6 +4145,9 @@ void HandleUI(void)
strcpy(joy_bnames[SYS_MS_BTN_R - DPAD_NAMES], "Mouse Btn Right");
strcpy(joy_bnames[SYS_MS_BTN_M - DPAD_NAMES], "Mouse Btn Middle");
strcpy(joy_bnames[SYS_MS_BTN_EMU - DPAD_NAMES], "Mouse Emu / Sniper");
strcpy(joy_bnames[SYS_BTN_OSD_KTGL - DPAD_NAMES], "Menu");
strcpy(joy_bnames[SYS_BTN_CNT_OK - DPAD_NAMES], "Menu: OK");
strcpy(joy_bnames[SYS_BTN_CNT_ESC - DPAD_NAMES], "Menu: Back");
joy_bcount = 16+1; //buttons + OSD/KTGL button
start_map_setting(joy_bcount + 6); // + dpad + Analog X/Y
menustate = MENU_JOYDIGMAP;