diff --git a/src/keyboard.c b/src/keyboard.c
index 62eb8e8d5..7d68edb93 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -580,5 +580,11 @@ keyboard_isfsexit(void)
int
keyboard_ismsexit(void)
{
+#ifdef WIN32
+ /* Windows: F8+F12 */
return( recv_key[0x42] && recv_key[0x58] );
+#else
+ /* Linux: CTRL+END */
+ return( (recv_key[0x1D] || recv_key[0x9D]) && recv_key[0xCF] );
+#endif
}
diff --git a/src/keyboard.h b/src/keyboard.h
index 66a9a85bc..eb5c648d4 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -43,5 +43,9 @@ extern void keyboard_input(int down, uint16_t scan);
extern int keyboard_isfsexit(void);
extern int keyboard_ismsexit(void);
+#ifdef __cplusplus
+}
+#endif
+
#endif /*EMU_KEYBOARD_H*/
diff --git a/src/mouse.c b/src/mouse.c
index fb90ac715..109d35ee6 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -8,7 +8,7 @@
*
* Common driver module for MOUSE devices.
*
- * Version: @(#)mouse.c 1.0.11 2017/10/22
+ * Version: @(#)mouse.c 1.0.12 2017/10/24
*
* Authors: Sarah Walker,
* Miran Grca,
@@ -30,7 +30,6 @@
int mouse_type = 0;
-int mouse_capture;
int mouse_x,
mouse_y,
mouse_z,
@@ -71,7 +70,6 @@ mouse_emu_init(void)
/* Initialize local data. */
mouse_x = mouse_y = mouse_z = 0;
mouse_buttons = 0x00;
- mouse_capture = 0;
cur_mouse = mouse_list[mouse_type];
diff --git a/src/mouse.h b/src/mouse.h
index 7ed997e93..58d9e7bcc 100644
--- a/src/mouse.h
+++ b/src/mouse.h
@@ -8,14 +8,14 @@
*
* Definitions for the MOUSE driver.
*
- * Version: @(#)mouse.h 1.0.5 2017/10/22
+ * Version: @(#)mouse.h 1.0.6 2017/10/24
*
* Authors: Sarah Walker,
* Miran Grca,
* Fred N. van Kempen,
*
* Copyright 2008-2017 Sarah Walker.
- * Copyright 2016-2017 Miran Grca.
+ * Copyright 2016,2017 Miran Grca.
*/
#ifndef EMU_MOUSE_H
# define EMU_MOUSE_H
@@ -53,7 +53,6 @@ typedef struct {
extern int mouse_type;
-extern int mouse_capture;
extern int mouse_x, mouse_y, mouse_z;
extern int mouse_buttons;
diff --git a/src/pc.c b/src/pc.c
index ce0df4c3c..1fba2572d 100644
--- a/src/pc.c
+++ b/src/pc.c
@@ -666,7 +666,7 @@ pc_reset_hard_init(void)
/* Reset keyboard and/or mouse. */
keyboard_at_reset();
mouse_emu_init();
-
+
/* Reset the video card. */
video_reset();
if (voodoo_enabled)
@@ -774,13 +774,7 @@ pc_close(thread_t *ptr)
config_save();
-#if 0
- //FIXME: need to move this to Plat. */
- if (mouse_capture) {
- ClipCursor(&oldclip);
- ShowCursor(TRUE);
- }
-#endif
+ plat_mouse_capture(0);
for (i=0; iexit(i);
diff --git a/src/plat.h b/src/plat.h
index 06315a18f..c2a38291f 100644
--- a/src/plat.h
+++ b/src/plat.h
@@ -36,7 +36,8 @@ extern "C" {
GLOBAL int dopause, /* system is paused */
doresize, /* screen resize requested */
quited, /* system exit requested */
- leave_fullscreen_flag; /* windowed-mode requested */
+ leave_fullscreen_flag, /* windowed-mode requested */
+ mouse_capture; /* mouse is captured in app */
GLOBAL uint64_t timer_freq;
GLOBAL int infocus;
@@ -57,6 +58,7 @@ extern uint64_t plat_timer_read(void);
extern uint32_t plat_get_ticks(void);
extern void plat_delay_ms(uint32_t count);
extern void plat_pause(int p);
+extern void plat_mouse_capture(int on);
extern int plat_vidapi(char *name);
extern char *plat_vidapi_name(int api);
extern int plat_setvid(int api);
diff --git a/src/win/win.c b/src/win/win.c
index fb47eb3e1..19cf5a1ec 100644
--- a/src/win/win.c
+++ b/src/win/win.c
@@ -132,17 +132,6 @@ win_menu_update(void)
#endif
-static void
-releasemouse(void)
-{
- if (mouse_capture) {
- ClipCursor(&oldclip);
- ShowCursor(TRUE);
- mouse_capture = 0;
- }
-}
-
-
static void
video_toggle_option(HMENU h, int *val, int id)
{
@@ -606,7 +595,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_KILLFOCUS:
infocus = 0;
- releasemouse();
+ plat_mouse_capture(0);
if (video_fullscreen)
leave_fullscreen_flag = 1;
if (hook_enabled) {
@@ -616,22 +605,13 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_LBUTTONUP:
- if (!mouse_capture && !video_fullscreen) {
- GetClipCursor(&oldclip);
- GetWindowRect(hwndRender, &rect);
-
- ClipCursor(&rect);
- mouse_capture = 1;
- while (1) {
- if (ShowCursor(FALSE) < 0) break;
- }
- }
+ if (! video_fullscreen)
+ plat_mouse_capture(1);
break;
case WM_MBUTTONUP:
- if (!(mouse_get_type(mouse_type) & MOUSE_TYPE_3BUTTON)) {
- releasemouse();
- }
+ if (!(mouse_get_type(mouse_type) & MOUSE_TYPE_3BUTTON))
+ plat_mouse_capture(0);
break;
case WM_ENTERMENULOOP:
@@ -1085,9 +1065,8 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil)
}
if (mouse_capture && keyboard_ismsexit()) {
- ClipCursor(&oldclip);
- ShowCursor(TRUE);
- mouse_capture = 0;
+ /* Release the in-app mouse. */
+ plat_mouse_capture(0);
}
if (video_fullscreen && keyboard_isfsexit()) {
@@ -1098,11 +1077,9 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil)
timeEndPeriod(1);
- if (mouse_capture) {
- ClipCursor(&oldclip);
- ShowCursor(TRUE);
- }
-
+ if (mouse_capture)
+ plat_mouse_capture(0);
+
UnregisterClass(SUB_CLASS_NAME, hinstance);
UnregisterClass(CLASS_NAME, hinstance);
@@ -1174,7 +1151,10 @@ do_start(void)
timer_freq = qpc.QuadPart;
pclog("Main timer precision: %llu\n", timer_freq);
- atexit(releasemouse);
+#if 0
+ /* We should have an application-wide at_exit catcher. */
+ atexit(plat_mouse_capture);
+#endif
/* Start the emulator, really. */
thMain = thread_create(pc_thread, &quited);
@@ -1391,3 +1371,28 @@ plat_get_string_from_string(char *str)
{
return(plat_get_string(atoi(str)));
}
+
+
+void
+plat_mouse_capture(int on)
+{
+ RECT rect;
+
+ if (on && !mouse_capture) {
+ /* Enable the in-app mouse. */
+ GetClipCursor(&oldclip);
+ GetWindowRect(hwndRender, &rect);
+ ClipCursor(&rect);
+ while (1) {
+ if (ShowCursor(FALSE) < 0) break;
+ }
+
+ mouse_capture = 1;
+ } else if (!on && mouse_capture) {
+ /* Disable the in-app mouse. */
+ ClipCursor(&oldclip);
+ ShowCursor(TRUE);
+
+ mouse_capture = 0;
+ }
+}