Mouse capture/release improvements

This commit is contained in:
Dimitris Panokostas 2020-07-01 00:44:08 +02:00
parent c8c10a713a
commit d42608b546
3 changed files with 114 additions and 61 deletions

View file

@ -4054,9 +4054,9 @@ static bool inputdevice_handle_inputcode2(int code, int state, const TCHAR *s)
case AKS_WARP: case AKS_WARP:
warpmode(newstate); warpmode(newstate);
break; break;
//case AKS_INHIBITSCREEN: case AKS_INHIBITSCREEN:
// toggle_inhibit_frame(monid, IHF_SCROLLLOCK); toggle_inhibit_frame(IHF_SCROLLLOCK);
// break; break;
//case AKS_STATEREWIND: //case AKS_STATEREWIND:
// savestate_dorewind(-2); // savestate_dorewind(-2);
// break; // break;

View file

@ -189,6 +189,7 @@ bool resumepaused(int priority)
if (pausemouseactive) if (pausemouseactive)
{ {
pausemouseactive = 0; pausemouseactive = 0;
setmouseactive(isfullscreen() > 0 ? 1 : -1);
} }
pause_emulation = 0; pause_emulation = 0;
setsystime(); setsystime();
@ -204,6 +205,10 @@ bool setpaused(int priority)
devices_pause(); devices_pause();
setsoundpaused(); setsoundpaused();
pausemouseactive = 1; pausemouseactive = 1;
if (isfullscreen() <= 0) {
pausemouseactive = mouseactive;
setmouseactive(0);
}
return true; return true;
} }
@ -1476,19 +1481,16 @@ static void amiberry_inactive(int minimized)
if (minimized) { if (minimized) {
inputdevice_unacquire(); inputdevice_unacquire();
setpaused(1); setpaused(1);
setsoundpaused();
sound_closed = -1; sound_closed = -1;
} }
else if (mouseactive) { else if (mouseactive) {
inputdevice_unacquire(); inputdevice_unacquire();
setpaused(2); setpaused(2);
setsoundpaused();
sound_closed = -1; sound_closed = -1;
} }
else { else {
inputdevice_unacquire(); inputdevice_unacquire();
setpaused(2); setpaused(2);
setsoundpaused();
sound_closed = -1; sound_closed = -1;
} }
} else { } else {
@ -1512,6 +1514,67 @@ static void amiberry_active(int minimized)
//clipboard_active(1); //clipboard_active(1);
} }
static void setmouseactive2(int active, bool allowpause)
{
if (active == 0)
set_mouse_grab(false);
if (mouseactive == active && active >= 0)
return;
if (active == 1 && !(currprefs.input_mouse_untrap & MOUSEUNTRAP_MAGIC)) {
set_mouse_grab(true);
}
if (active < 0)
active = 1;
mouseactive = active ? 1 : 0;
recapture = 0;
if (isfullscreen() <= 0 && (currprefs.input_mouse_untrap & MOUSEUNTRAP_MAGIC) && currprefs.input_tablet > 0) {
if (mousehack_alive())
return;
}
if (active) {
inputdevice_acquire(TRUE);
resumepaused(2);
if (sound_closed < 0)
resumesoundpaused();
}
else {
inputdevice_acquire(FALSE);
inputdevice_releasebuttons();
setpaused(2);
sound_closed = -1;
}
}
void setmouseactive(int active)
{
if (active > 1)
SDL_RaiseWindow(sdl_window);
setmouseactive2(active, true);
}
void enablecapture()
{
if (pause_emulation > 2)
return;
setmouseactive(1);
if (sound_closed < 0) {
resumesoundpaused();
sound_closed = 0;
}
}
void disablecapture()
{
setmouseactive(0);
focus = 0;
}
int handle_msgpump() int handle_msgpump()
{ {
auto gotEvent = 0; auto gotEvent = 0;
@ -1531,6 +1594,9 @@ int handle_msgpump()
setminimized(); setminimized();
amiberry_inactive(minimized); amiberry_inactive(minimized);
break; break;
case SDL_WINDOWEVENT_LEAVE:
set_mouse_grab(false);
break;
case SDL_WINDOWEVENT_CLOSE: case SDL_WINDOWEVENT_CLOSE:
uae_quit(); uae_quit();
break; break;
@ -1708,34 +1774,36 @@ int handle_msgpump()
case SDL_FINGERMOTION: case SDL_FINGERMOTION:
//TODO this doesn't work yet //TODO this doesn't work yet
mouseScale = currprefs.input_joymouse_multiplier / 2; setmousestate(0, 0, event.motion.xrel, 0);
x = event.motion.xrel; setmousestate(0, 1, event.motion.yrel, 0);
y = event.motion.yrel;
setmousestate(0, 0, x* mouseScale, 0);
setmousestate(0, 1, y* mouseScale, 0);
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
if (currprefs.input_tablet == TABLET_OFF) if (recapture && isfullscreen() <= 0) {
enablecapture();
}
if (currprefs.input_tablet >= TABLET_MOUSEHACK)
{ {
if (currprefs.jports[0].id == JSEM_MICE || currprefs.jports[1].id == JSEM_MICE) /* absolute */
{ setmousestate(0, 0, event.motion.x, 1);
mouseScale = currprefs.input_joymouse_multiplier / 2; setmousestate(0, 1, event.motion.y, 1);
x = event.motion.xrel; }
y = event.motion.yrel; else if (currprefs.jports[0].id == JSEM_MICE || currprefs.jports[1].id == JSEM_MICE)
{
/* relative */
#if defined (ANDROID) #if defined (ANDROID)
if (event.motion.x == 0 && x > -4) if (event.motion.x == 0 && x > -4)
x = -4; x = -4;
if (event.motion.y == 0 && y > -4) if (event.motion.y == 0 && y > -4)
y = -4; y = -4;
if (event.motion.x == currprefs.gfx_monitor.gfx_size.width - 1 && x < 4) if (event.motion.x == currprefs.gfx_monitor.gfx_size.width - 1 && x < 4)
x = 4; x = 4;
if (event.motion.y == currprefs.gfx_monitor.gfx_size.height - 1 && y < 4) if (event.motion.y == currprefs.gfx_monitor.gfx_size.height - 1 && y < 4)
y = 4; y = 4;
#endif //ANDROID #endif //ANDROID
setmousestate(0, 0, x * mouseScale, 0); setmousestate(0, 0, event.motion.xrel, 0);
setmousestate(0, 1, y * mouseScale, 0); setmousestate(0, 1, event.motion.yrel, 0);
}
} }
break; break;
@ -1791,6 +1859,9 @@ bool handle_events()
amiberry_active(minimized); amiberry_active(minimized);
unsetminimized(); unsetminimized();
break; break;
case SDL_WINDOWEVENT_LEAVE:
set_mouse_grab(false);
break;
case SDL_WINDOWEVENT_CLOSE: case SDL_WINDOWEVENT_CLOSE:
uae_quit(); uae_quit();
break; break;

View file

@ -1,9 +1,8 @@
#include <stdio.h> #include <cstdio>
#include <strings.h> #include <strings.h>
#include <string.h> #include <cstring>
#include <stdlib.h> #include <cstdlib>
#include <stdarg.h> #include <cstdarg>
#include <stdbool.h>
#include <guisan.hpp> #include <guisan.hpp>
#include <guisan/sdl.hpp> #include <guisan/sdl.hpp>
@ -139,7 +138,7 @@ void ClearAvailableROMList()
{ {
while (!lstAvailableROMs.empty()) while (!lstAvailableROMs.empty())
{ {
const auto tmp = lstAvailableROMs[0]; auto* const tmp = lstAvailableROMs[0];
lstAvailableROMs.erase(lstAvailableROMs.begin()); lstAvailableROMs.erase(lstAvailableROMs.begin());
delete tmp; delete tmp;
} }
@ -148,7 +147,7 @@ void ClearAvailableROMList()
static void addrom(struct romdata* rd, const char* path) static void addrom(struct romdata* rd, const char* path)
{ {
char tmpName[MAX_DPATH]; char tmpName[MAX_DPATH];
const auto tmp = new AvailableROM(); auto* const tmp = new AvailableROM();
getromname(rd, tmpName); getromname(rd, tmpName);
strncpy(tmp->Name, tmpName, MAX_DPATH - 1); strncpy(tmp->Name, tmpName, MAX_DPATH - 1);
if (path != nullptr) if (path != nullptr)
@ -191,7 +190,7 @@ static struct romdata* scan_single_rom_2(struct zfile* f)
{ {
zfile_fseek(f, 0, SEEK_SET); zfile_fseek(f, 0, SEEK_SET);
} }
uae_u8* rombuf = xcalloc(uae_u8, size); auto* rombuf = xcalloc(uae_u8, size);
if (!rombuf) if (!rombuf)
return nullptr; return nullptr;
zfile_fread(rombuf, 1, size, f); zfile_fread(rombuf, 1, size, f);
@ -222,7 +221,7 @@ static int isromext(char* path)
{ {
if (!path) if (!path)
return 0; return 0;
auto ext = strrchr(path, '.'); auto* ext = strrchr(path, '.');
if (!ext) if (!ext)
return 0; return 0;
ext++; ext++;
@ -240,11 +239,11 @@ static int isromext(char* path)
static int scan_rom_2(struct zfile* f, void* dummy) static int scan_rom_2(struct zfile* f, void* dummy)
{ {
const auto path = zfile_getname(f); auto* const path = zfile_getname(f);
if (!isromext(path)) if (!isromext(path))
return 0; return 0;
const auto rd = scan_single_rom_2(f); auto* const rd = scan_single_rom_2(f);
if (rd) if (rd)
addrom(rd, path); addrom(rd, path);
return 0; return 0;
@ -286,7 +285,7 @@ void RescanROMs()
auto id = 1; auto id = 1;
for (;;) { for (;;) {
auto rd = getromdatabyid(id); auto* rd = getromdatabyid(id);
if (!rd) if (!rd)
break; break;
if (rd->crc32 == 0xffffffff && strncmp(rd->model, "AROS", 4) == 0) if (rd->crc32 == 0xffffffff && strncmp(rd->model, "AROS", 4) == 0)
@ -302,13 +301,12 @@ static void ClearConfigFileList()
{ {
while (!ConfigFilesList.empty()) while (!ConfigFilesList.empty())
{ {
const auto tmp = ConfigFilesList[0]; auto* const tmp = ConfigFilesList[0];
ConfigFilesList.erase(ConfigFilesList.begin()); ConfigFilesList.erase(ConfigFilesList.begin());
delete tmp; delete tmp;
} }
} }
void ReadConfigFileList(void) void ReadConfigFileList(void)
{ {
char path[MAX_DPATH]; char path[MAX_DPATH];
@ -372,16 +370,6 @@ static void clearallkeys (void)
inputdevice_updateconfig (NULL, &changed_prefs); inputdevice_updateconfig (NULL, &changed_prefs);
} }
void setmouseactive(int active)
{
if (active) {
inputdevice_acquire(TRUE);
} else {
inputdevice_acquire (FALSE);
inputdevice_releasebuttons();
}
}
static void prefs_to_gui() static void prefs_to_gui()
{ {
/* filesys hack */ /* filesys hack */
@ -389,7 +377,6 @@ static void prefs_to_gui()
memcpy(&changed_prefs.mountconfig, &currprefs.mountconfig, MOUNT_CONFIG_SIZE * sizeof(struct uaedev_config_info)); memcpy(&changed_prefs.mountconfig, &currprefs.mountconfig, MOUNT_CONFIG_SIZE * sizeof(struct uaedev_config_info));
} }
static void gui_to_prefs(void) static void gui_to_prefs(void)
{ {
/* filesys hack */ /* filesys hack */
@ -398,7 +385,6 @@ static void gui_to_prefs(void)
fixup_prefs(&changed_prefs, true); fixup_prefs(&changed_prefs, true);
} }
static void after_leave_gui() static void after_leave_gui()
{ {
// Check if we have to set or clear autofire // Check if we have to set or clear autofire
@ -420,7 +406,6 @@ static void after_leave_gui()
inputdevice_config_change_test(); inputdevice_config_change_test();
} }
int gui_init() int gui_init()
{ {
emulating = 0; emulating = 0;
@ -454,13 +439,11 @@ void gui_exit()
ClearAvailableROMList(); ClearAvailableROMList();
} }
void gui_purge_events() void gui_purge_events()
{ {
keybuf_init(); keybuf_init();
} }
int gui_update() int gui_update()
{ {
char tmp[MAX_DPATH]; char tmp[MAX_DPATH];
@ -499,7 +482,6 @@ int gui_update()
return 0; return 0;
} }
void gui_display(int shortcut) void gui_display(int shortcut)
{ {
if (quit_program != 0) if (quit_program != 0)
@ -769,8 +751,8 @@ bool DevicenameExists(const char* name)
{ {
for (auto i = 0; i < MAX_HD_DEVICES; ++i) for (auto i = 0; i < MAX_HD_DEVICES; ++i)
{ {
auto uci = &changed_prefs.mountconfig[i]; auto* uci = &changed_prefs.mountconfig[i];
const auto ci = &uci->ci; auto* const ci = &uci->ci;
if (ci->devname[0]) if (ci->devname[0])
{ {
@ -813,7 +795,7 @@ int tweakbootpri(int bp, int ab, int dnm)
bool hardfile_testrdb(const TCHAR* filename) bool hardfile_testrdb(const TCHAR* filename)
{ {
auto isrdb = false; auto isrdb = false;
auto f = zfile_fopen(filename, _T("rb"), ZFD_NORMAL); auto* f = zfile_fopen(filename, _T("rb"), ZFD_NORMAL);
uae_u8 tmp[8]; uae_u8 tmp[8];
if (!f) if (!f)