Fix emulator-handled UI keyboard combinations when keyboard requires capture and is not captured, also fix keyboard input in full screen in such situations, fixes #4697.

This commit is contained in:
OBattler
2024-08-07 06:11:50 +02:00
parent f537ae792e
commit 37ceea4ed0
4 changed files with 30 additions and 27 deletions

View File

@@ -25,6 +25,7 @@
#include <86box/86box.h> #include <86box/86box.h>
#include <86box/machine.h> #include <86box/machine.h>
#include <86box/keyboard.h> #include <86box/keyboard.h>
#include <86box/plat.h>
#include "cpu.h" #include "cpu.h"
@@ -50,7 +51,8 @@ uint16_t key_uncapture_2 = 0x14f; /* End */
void (*keyboard_send)(uint16_t val); void (*keyboard_send)(uint16_t val);
static int recv_key[512]; /* keyboard input buffer */ static int recv_key[512] = { 0 }; /* keyboard input buffer */
static int recv_key_ui[512] = { 0 }; /* keyboard input buffer */
static int oldkey[512]; static int oldkey[512];
#if 0 #if 0
static int keydelay[512]; static int keydelay[512];
@@ -238,16 +240,13 @@ keyboard_input(int down, uint16_t scan)
} }
} }
/* NOTE: Shouldn't this be some sort of bit shift? An array of 8 unsigned 64-bit integers
should be enough. */
#if 0
recv_key[scan >> 6] |= ((uint64_t) down << ((uint64_t) scan & 0x3fLL));
#endif
/* pclog("Received scan code: %03X (%s)\n", scan & 0x1ff, down ? "down" : "up"); */ /* pclog("Received scan code: %03X (%s)\n", scan & 0x1ff, down ? "down" : "up"); */
recv_key[scan & 0x1ff] = down; recv_key_ui[scan & 0x1ff] = down;
key_process(scan & 0x1ff, down); if (mouse_capture || !kbd_req_capture || video_fullscreen) {
recv_key[scan & 0x1ff] = down;
key_process(scan & 0x1ff, down);
}
} }
static uint8_t static uint8_t
@@ -343,30 +342,36 @@ keyboard_recv(uint16_t key)
return recv_key[key]; return recv_key[key];
} }
int
keyboard_recv_ui(uint16_t key)
{
return recv_key_ui[key];
}
/* Do we have Control-Alt-PgDn in the keyboard buffer? */ /* Do we have Control-Alt-PgDn in the keyboard buffer? */
int int
keyboard_isfsenter(void) keyboard_isfsenter(void)
{ {
return ((recv_key[0x01d] || recv_key[0x11d]) && (recv_key[0x038] || recv_key[0x138]) && (recv_key[0x049] || recv_key[0x149])); return ((recv_key_ui[0x01d] || recv_key_ui[0x11d]) && (recv_key_ui[0x038] || recv_key_ui[0x138]) && (recv_key_ui[0x049] || recv_key_ui[0x149]));
} }
int int
keyboard_isfsenter_up(void) keyboard_isfsenter_up(void)
{ {
return (!recv_key[0x01d] && !recv_key[0x11d] && !recv_key[0x038] && !recv_key[0x138] && !recv_key[0x049] && !recv_key[0x149]); return (!recv_key_ui[0x01d] && !recv_key_ui[0x11d] && !recv_key_ui[0x038] && !recv_key_ui[0x138] && !recv_key_ui[0x049] && !recv_key_ui[0x149]);
} }
/* Do we have Control-Alt-PgDn in the keyboard buffer? */ /* Do we have Control-Alt-PgDn in the keyboard buffer? */
int int
keyboard_isfsexit(void) keyboard_isfsexit(void)
{ {
return ((recv_key[0x01d] || recv_key[0x11d]) && (recv_key[0x038] || recv_key[0x138]) && (recv_key[0x051] || recv_key[0x151])); return ((recv_key_ui[0x01d] || recv_key_ui[0x11d]) && (recv_key_ui[0x038] || recv_key_ui[0x138]) && (recv_key_ui[0x051] || recv_key_ui[0x151]));
} }
int int
keyboard_isfsexit_up(void) keyboard_isfsexit_up(void)
{ {
return (!recv_key[0x01d] && !recv_key[0x11d] && !recv_key[0x038] && !recv_key[0x138] && !recv_key[0x051] && !recv_key[0x151]); return (!recv_key_ui[0x01d] && !recv_key_ui[0x11d] && !recv_key_ui[0x038] && !recv_key_ui[0x138] && !recv_key_ui[0x051] && !recv_key_ui[0x151]);
} }
/* Do we have the mouse uncapture combination in the keyboard buffer? */ /* Do we have the mouse uncapture combination in the keyboard buffer? */
@@ -374,10 +379,10 @@ int
keyboard_ismsexit(void) keyboard_ismsexit(void)
{ {
if ((key_prefix_2_1 != 0x000) || (key_prefix_2_2 != 0x000)) if ((key_prefix_2_1 != 0x000) || (key_prefix_2_2 != 0x000))
return ((recv_key[key_prefix_1_1] || recv_key[key_prefix_1_2]) && return ((recv_key_ui[key_prefix_1_1] || recv_key_ui[key_prefix_1_2]) &&
(recv_key[key_prefix_2_1] || recv_key[key_prefix_2_2]) && (recv_key_ui[key_prefix_2_1] || recv_key_ui[key_prefix_2_2]) &&
(recv_key[key_uncapture_1] || recv_key[key_uncapture_2])); (recv_key_ui[key_uncapture_1] || recv_key_ui[key_uncapture_2]));
else else
return ((recv_key[key_prefix_1_1] || recv_key[key_prefix_1_2]) && return ((recv_key_ui[key_prefix_1_1] || recv_key_ui[key_prefix_1_2]) &&
(recv_key[key_uncapture_1] || recv_key[key_uncapture_2])); (recv_key_ui[key_uncapture_1] || recv_key_ui[key_uncapture_2]));
} }

View File

@@ -272,6 +272,7 @@ extern uint8_t keyboard_get_shift(void);
extern void keyboard_get_states(uint8_t *cl, uint8_t *nl, uint8_t *sl); extern void keyboard_get_states(uint8_t *cl, uint8_t *nl, uint8_t *sl);
extern void keyboard_set_states(uint8_t cl, uint8_t nl, uint8_t sl); extern void keyboard_set_states(uint8_t cl, uint8_t nl, uint8_t sl);
extern int keyboard_recv(uint16_t key); extern int keyboard_recv(uint16_t key);
extern int keyboard_recv_ui(uint16_t key);
extern int keyboard_isfsenter(void); extern int keyboard_isfsenter(void);
extern int keyboard_isfsenter_up(void); extern int keyboard_isfsenter_up(void);
extern int keyboard_isfsexit(void); extern int keyboard_isfsexit(void);

View File

@@ -1218,7 +1218,7 @@ MainWindow::getTitle(wchar_t *title)
bool bool
MainWindow::eventFilter(QObject *receiver, QEvent *event) MainWindow::eventFilter(QObject *receiver, QEvent *event)
{ {
if (!dopause && (mouse_capture || !kbd_req_capture)) { if (!dopause) {
if (event->type() == QEvent::Shortcut) { if (event->type() == QEvent::Shortcut) {
auto shortcutEvent = (QShortcutEvent *) event; auto shortcutEvent = (QShortcutEvent *) event;
if (shortcutEvent->key() == ui->actionExit->shortcut()) { if (shortcutEvent->key() == ui->actionExit->shortcut()) {
@@ -1299,7 +1299,7 @@ MainWindow::showMessage_(int flags, const QString &header, const QString &messag
void void
MainWindow::keyPressEvent(QKeyEvent *event) MainWindow::keyPressEvent(QKeyEvent *event)
{ {
if (send_keyboard_input && !(kbd_req_capture && !mouse_capture)) { if (send_keyboard_input) {
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
processMacKeyboardInput(true, event); processMacKeyboardInput(true, event);
#else #else
@@ -1312,10 +1312,10 @@ MainWindow::keyPressEvent(QKeyEvent *event)
if (keyboard_ismsexit()) if (keyboard_ismsexit())
plat_mouse_capture(0); plat_mouse_capture(0);
if ((video_fullscreen > 0) && (keyboard_recv(0x1D) || keyboard_recv(0x11D))) { if ((video_fullscreen > 0) && (keyboard_recv_ui(0x1D) || keyboard_recv_ui(0x11D))) {
if (keyboard_recv(0x57)) if (keyboard_recv_ui(0x57))
ui->actionTake_screenshot->trigger(); ui->actionTake_screenshot->trigger();
else if (keyboard_recv(0x58)) else if (keyboard_recv_ui(0x58))
pc_send_cad(); pc_send_cad();
} }
@@ -1338,7 +1338,7 @@ void
MainWindow::keyReleaseEvent(QKeyEvent *event) MainWindow::keyReleaseEvent(QKeyEvent *event)
{ {
if (event->key() == Qt::Key_Pause) { if (event->key() == Qt::Key_Pause) {
if (keyboard_recv(0x38) && keyboard_recv(0x138)) { if (keyboard_recv_ui(0x38) && keyboard_recv_ui(0x138)) {
plat_pause(dopause ^ 1); plat_pause(dopause ^ 1);
} }
} }

View File

@@ -176,9 +176,6 @@ WindowsRawInputFilter::keyboard_handle(PRAWINPUT raw)
RAWKEYBOARD rawKB = raw->data.keyboard; RAWKEYBOARD rawKB = raw->data.keyboard;
scancode = rawKB.MakeCode; scancode = rawKB.MakeCode;
if (kbd_req_capture && !mouse_capture)
return;
/* If it's not a scan code that starts with 0xE1 */ /* If it's not a scan code that starts with 0xE1 */
if ((rawKB.Flags & RI_KEY_E1)) { if ((rawKB.Flags & RI_KEY_E1)) {
if (rawKB.MakeCode == 0x1D) { if (rawKB.MakeCode == 0x1D) {