Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dosbox-staging/dosbox-staging.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeralChild64 <unknown>2022-11-05 22:40:35 +0300
committerkcgen <1557255+kcgen@users.noreply.github.com>2022-11-07 08:43:55 +0300
commitc9351ab7768b5230440404fdeb4faf16f6f6985b (patch)
treeab0d5e6a23941c62e8730f648c6b5576328a3ed6
parent4d02ad620b15737253f844b88f303b47c05320b0 (diff)
Allow to cancel interactive mouse mapping with a keyboard
-rw-r--r--src/hardware/mouse/mouse_manymouse.cpp24
-rw-r--r--src/hardware/mouse/mouse_manymouse.h1
2 files changed, 24 insertions, 1 deletions
diff --git a/src/hardware/mouse/mouse_manymouse.cpp b/src/hardware/mouse/mouse_manymouse.cpp
index 34b9aa472..46f9c03a2 100644
--- a/src/hardware/mouse/mouse_manymouse.cpp
+++ b/src/hardware/mouse/mouse_manymouse.cpp
@@ -22,6 +22,7 @@
#include "callback.h"
#include "checks.h"
+#include "dos_inc.h"
#include "math_utils.h"
#include "pic.h"
#include "string_utils.h"
@@ -254,6 +255,9 @@ bool ManyMouseGlue::ProbeForMapping(uint8_t &physical_device_idx)
bool success = false;
while (!shutdown_requested) {
+ if (IsCancelRequested())
+ break; // user cancelled using a keyboard
+
// Poll mouse events, handle critical ones
if (!ManyMouse_PollEvent(&event)) {
CALLBACK_Idle();
@@ -272,7 +276,7 @@ bool ManyMouseGlue::ProbeForMapping(uint8_t &physical_device_idx)
physical_device_idx = static_cast<uint8_t>(event.device);
if (event.item >= 1)
- break; // user cancelled the interactive mouse mapping
+ break; // user cancelled using a mouse button
// Do not accept already mapped devices
bool already_mapped = false;
@@ -293,6 +297,24 @@ bool ManyMouseGlue::ProbeForMapping(uint8_t &physical_device_idx)
return success;
}
+bool ManyMouseGlue::IsCancelRequested()
+{
+ constexpr uint8_t code_ctrl_c = 0x03;
+ constexpr uint8_t code_esc = 0x1b;
+
+ while (!(Files[STDIN]->GetInformation() & (1 << 6))) {
+ // A key is waiting, read it
+ uint16_t count = 1;
+ uint8_t code = 0;
+ DOS_ReadFile(STDIN, &code, &count);
+ // Check if requested to cancel
+ if (code == code_ctrl_c || code == code_esc || code == 'q' || code == 'Q')
+ return true;
+ }
+
+ return false;
+}
+
uint8_t ManyMouseGlue::GetIdx(const std::regex &regex)
{
assert(max_mice < UINT8_MAX);
diff --git a/src/hardware/mouse/mouse_manymouse.h b/src/hardware/mouse/mouse_manymouse.h
index 69753e145..f9b0a0fc1 100644
--- a/src/hardware/mouse/mouse_manymouse.h
+++ b/src/hardware/mouse/mouse_manymouse.h
@@ -73,6 +73,7 @@ private:
ManyMouseGlue(const ManyMouseGlue &) = delete;
ManyMouseGlue &operator=(const ManyMouseGlue &) = delete;
+ bool IsCancelRequested();
void Tick();
friend void manymouse_tick(uint32_t);