From 8ad669b3fbe371d2e9d4970638a349cb4620a3c7 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sun, 19 Feb 2023 18:00:18 +0200 Subject: [PATCH] Disable keyboard/game controllers option when not captured. --- include/options.h | 1 + od-win32/dinput.cpp | 13 +++++++++++++ od-win32/resources/resource.h | 2 ++ od-win32/resources/winuae.rc | 16 +++++++++------- od-win32/win32.cpp | 11 +++++++---- od-win32/win32gfx.cpp | 4 +++- od-win32/win32gui.cpp | 23 +++++++++++++++++++++-- 7 files changed, 56 insertions(+), 14 deletions(-) diff --git a/include/options.h b/include/options.h index 69b1521b..c00a70b0 100644 --- a/include/options.h +++ b/include/options.h @@ -866,6 +866,7 @@ struct uae_prefs { int win32_active_capture_priority; bool win32_active_nocapture_pause; bool win32_active_nocapture_nosound; + int win32_active_input; int win32_inactive_priority; bool win32_inactive_pause; bool win32_inactive_nosound; diff --git a/od-win32/dinput.cpp b/od-win32/dinput.cpp index 5a9e3d08..e7ccd1d7 100644 --- a/od-win32/dinput.cpp +++ b/od-win32/dinput.cpp @@ -2291,6 +2291,10 @@ static void handle_rawinput_2 (RAWINPUT *raw, LPARAM lParam) if (rp_isactive ()) return; #endif + if (!istest && !mouseactive && !(currprefs.win32_active_input & 4)) { + return; + } + if (num < num_joystick) { rawdata = (PCHAR)hid->bRawData; @@ -2598,6 +2602,12 @@ static void handle_rawinput_2 (RAWINPUT *raw, LPARAM lParam) return; if (isfocus () < 2 && currprefs.input_tablet >= TABLET_MOUSEHACK && (currprefs.input_mouse_untrap & MOUSEUNTRAP_MAGIC)) return; + if (!mouseactive && !(currprefs.win32_active_input & 1)) { + if ((currprefs.win32_guikey <= 0 && scancode == DIK_F12) || (scancode == currprefs.win32_guikey)) { + inputdevice_add_inputcode(AKS_ENTERGUI, 1, NULL); + } + return; + } if (pressed) { di_keycodes[num][scancode] = 1; } else { @@ -4092,6 +4102,9 @@ static void read_joystick (void) if (rp_isactive ()) return; #endif + if (!istest && !mouseactive && !(currprefs.win32_active_input & 4)) { + return; + } for (i = 0; i < MAX_INPUT_DEVICES; i++) { struct didata *did = &di_joystick[i]; diff --git a/od-win32/resources/resource.h b/od-win32/resources/resource.h index dd191529..73b8f2bb 100644 --- a/od-win32/resources/resource.h +++ b/od-win32/resources/resource.h @@ -801,6 +801,8 @@ #define IDC_ACTIVE_NOSOUND 1535 #define IDC_STATECLEAR 1536 #define IDC_MINIMIZED_NOJOY 1537 +#define IDC_ACTIVE_NOJOY 1538 +#define IDC_ACTIVE_NOKEYBOARD 1539 #define IDC_SER_SHARED 1553 #define IDC_GUI_RESIZE 1553 #define IDC_SER_CTSRTS 1554 diff --git a/od-win32/resources/winuae.rc b/od-win32/resources/winuae.rc index f4fd8ce3..573f1328 100644 --- a/od-win32/resources/winuae.rc +++ b/od-win32/resources/winuae.rc @@ -1013,28 +1013,30 @@ IDD_MISC2 DIALOGEX 0, 0, 396, 316 STYLE DS_LOCALEDIT | DS_SETFONT | DS_3DLOOK | DS_CONTROL | WS_CHILD FONT 8, "MS Sans Serif", 0, 0, 0x1 BEGIN - GROUPBOX "When Active",IDC_STATIC,1,24,125,105 + GROUPBOX "When Active",IDC_STATIC,1,24,125,119 CTEXT "Run at priority:",IDC_ACTIVE_PRI,10,35,108,10,SS_CENTERIMAGE | WS_TABSTOP COMBOBOX IDC_ACTIVE_PRIORITY,10,50,108,65,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP CTEXT "Mouse uncaptured:",IDC_STATIC,10,67,101,15,SS_CENTERIMAGE CONTROL "Pause emulation",IDC_ACTIVE_PAUSE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,84,109,10 CONTROL "Disable sound",IDC_ACTIVE_NOSOUND,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,98,109,10 - GROUPBOX "When Inactive",IDC_STATIC,133,24,126,105 + GROUPBOX "When Inactive",IDC_STATIC,133,24,126,119 CTEXT "Run at priority:",IDC_INACTIVE_PRI,144,35,107,10,SS_CENTERIMAGE | WS_TABSTOP COMBOBOX IDC_INACTIVE_PRIORITY,144,50,108,65,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP CONTROL "Pause emulation",IDC_INACTIVE_PAUSE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,143,84,109,10 CONTROL "Disable sound",IDC_INACTIVE_NOSOUND,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,143,98,109,10 CONTROL "Disable game controllers",IDC_INACTIVE_NOJOY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,143,112,109,10 - GROUPBOX "When Minimized",IDC_STATIC,269,24,125,105 + GROUPBOX "When Minimized",IDC_STATIC,269,24,125,119 CTEXT "Run at priority:",IDC_MINIMIZED_PRI,278,36,109,10,SS_CENTERIMAGE | WS_TABSTOP COMBOBOX IDC_MINIMIZED_PRIORITY,278,50,108,65,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP CONTROL "Pause emulation",IDC_MINIMIZED_PAUSE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,280,84,108,10 CONTROL "Disable sound",IDC_MINIMIZED_NOSOUND,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,280,98,108,10 CONTROL "Disable game controllers",IDC_MINIMIZED_NOJOY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,280,112,107,10 - GROUPBOX "File Extension Associations",IDC_STATIC,0,137,260,155 - CONTROL "",IDC_ASSOCIATELIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,9,154,238,108 - PUSHBUTTON "Associate all",IDC_ASSOCIATE_ON,36,270,85,14 - PUSHBUTTON "Deassociate all",IDC_ASSOCIATE_OFF,125,270,85,14 + GROUPBOX "File Extension Associations",IDC_STATIC,0,148,260,155 + CONTROL "",IDC_ASSOCIATELIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,9,165,238,108 + PUSHBUTTON "Associate all",IDC_ASSOCIATE_ON,36,281,85,14 + PUSHBUTTON "Deassociate all",IDC_ASSOCIATE_OFF,125,281,85,14 + CONTROL "Disable keyboard",IDC_ACTIVE_NOKEYBOARD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,126,109,10 + CONTROL "Disable game controllers",IDC_ACTIVE_NOJOY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,112,109,10 END IDD_DISK DIALOGEX 0, 0, 396, 316 diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index 3f1b304b..e7aba9be 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -1249,11 +1249,11 @@ static void winuae_inactive(struct AmigaMonitor *mon, HWND hWnd, int minimized) setpaused(1); sound_closed = 1; } else if (currprefs.win32_iconified_nosound) { - inputdevice_unacquire(true, currprefs.win32_iconified_input); + inputdevice_unacquire(currprefs.win32_iconified_input); setsoundpaused(); sound_closed = -1; } else { - inputdevice_unacquire(true, currprefs.win32_iconified_input); + inputdevice_unacquire(currprefs.win32_iconified_input); } } else if (mouseactive) { inputdevice_unacquire(); @@ -1270,11 +1270,11 @@ static void winuae_inactive(struct AmigaMonitor *mon, HWND hWnd, int minimized) setpaused(2); sound_closed = 1; } else if (currprefs.win32_inactive_nosound) { - inputdevice_unacquire(true, currprefs.win32_inactive_input); + inputdevice_unacquire(currprefs.win32_inactive_input); setsoundpaused(); sound_closed = -1; } else { - inputdevice_unacquire(true, currprefs.win32_inactive_input); + inputdevice_unacquire(currprefs.win32_inactive_input); } } } else { @@ -4229,6 +4229,7 @@ void target_default_options (struct uae_prefs *p, int type) p->win32_logfile = 0; p->win32_active_nocapture_pause = 0; p->win32_active_nocapture_nosound = 0; + p->win32_active_input = 1 | 2 | 4; p->win32_iconified_nosound = 1; p->win32_iconified_pause = 1; p->win32_iconified_input = 0; @@ -4340,6 +4341,7 @@ void target_save_options (struct zfile *f, struct uae_prefs *p) #endif cfgfile_target_dwrite_bool(f, _T("active_not_captured_nosound"), p->win32_active_nocapture_nosound); cfgfile_target_dwrite_bool(f, _T("active_not_captured_pause"), p->win32_active_nocapture_pause); + cfgfile_target_dwrite(f, _T("active_input"), _T("%d"), p->win32_active_input); cfgfile_target_dwrite(f, _T("inactive_priority"), _T("%d"), priorities[p->win32_inactive_priority].value); cfgfile_target_dwrite_bool(f, _T("inactive_nosound"), p->win32_inactive_nosound); cfgfile_target_dwrite_bool(f, _T("inactive_pause"), p->win32_inactive_pause); @@ -4536,6 +4538,7 @@ static int target_parse_option_host(struct uae_prefs *p, const TCHAR *option, co || cfgfile_yesno(option, value, _T("active_not_captured_nosound"), &p->win32_active_nocapture_nosound) || cfgfile_yesno(option, value, _T("inactive_pause"), &p->win32_inactive_pause) || cfgfile_yesno(option, value, _T("inactive_nosound"), &p->win32_inactive_nosound) + || cfgfile_intval(option, value, _T("active_input"), &p->win32_active_input, 1) || cfgfile_intval(option, value, _T("inactive_input"), &p->win32_inactive_input, 1) || cfgfile_yesno(option, value, _T("iconified_pause"), &p->win32_iconified_pause) || cfgfile_yesno(option, value, _T("iconified_nosound"), &p->win32_iconified_nosound) diff --git a/od-win32/win32gfx.cpp b/od-win32/win32gfx.cpp index 2a6da468..1f816df3 100644 --- a/od-win32/win32gfx.cpp +++ b/od-win32/win32gfx.cpp @@ -2056,7 +2056,7 @@ static int open_windows(struct AmigaMonitor *mon, bool mousecapture, bool starte if (upd > 0) { inputdevice_acquire(TRUE); if (!isfocus()) - inputdevice_unacquire(true, input); + inputdevice_unacquire(input); } if (startpaused) @@ -2514,6 +2514,7 @@ int check_prefs_changed_gfx(void) currprefs.win32_iconified_priority != changed_prefs.win32_iconified_priority || currprefs.win32_active_nocapture_nosound != changed_prefs.win32_active_nocapture_nosound || currprefs.win32_active_nocapture_pause != changed_prefs.win32_active_nocapture_pause || + currprefs.win32_active_input != changed_prefs.win32_active_input || currprefs.win32_inactive_nosound != changed_prefs.win32_inactive_nosound || currprefs.win32_inactive_pause != changed_prefs.win32_inactive_pause || currprefs.win32_inactive_input != changed_prefs.win32_inactive_input || @@ -2535,6 +2536,7 @@ int check_prefs_changed_gfx(void) currprefs.win32_inactive_priority = changed_prefs.win32_inactive_priority; currprefs.win32_iconified_priority = changed_prefs.win32_iconified_priority; currprefs.win32_active_nocapture_nosound = changed_prefs.win32_active_nocapture_nosound; + currprefs.win32_active_input = changed_prefs.win32_active_input; currprefs.win32_active_nocapture_pause = changed_prefs.win32_active_nocapture_pause; currprefs.win32_inactive_nosound = changed_prefs.win32_inactive_nosound; currprefs.win32_inactive_pause = changed_prefs.win32_inactive_pause; diff --git a/od-win32/win32gui.cpp b/od-win32/win32gui.cpp index 4d262be5..e1e1031e 100644 --- a/od-win32/win32gui.cpp +++ b/od-win32/win32gui.cpp @@ -12433,9 +12433,11 @@ static void enable_for_miscdlg (HWND hDlg) bool paused = false; bool nosound = false; + bool activenojoy = (workprefs.win32_active_input & 4) == 0; + bool activenokeyboard = (workprefs.win32_active_input & 1) == 0; bool nojoy = (workprefs.win32_inactive_input & 4) == 0; - ew (hDlg, IDC_ACTIVE_PAUSE, paused == false); - ew (hDlg, IDC_ACTIVE_NOSOUND, nosound == false && paused == false); + ew(hDlg, IDC_ACTIVE_PAUSE, paused == false); + ew(hDlg, IDC_ACTIVE_NOSOUND, nosound == false && paused == false); if (!paused) { paused = workprefs.win32_active_nocapture_pause; if (!nosound) @@ -12446,13 +12448,20 @@ static void enable_for_miscdlg (HWND hDlg) workprefs.win32_active_nocapture_pause = workprefs.win32_active_nocapture_nosound = true; nosound = true; nojoy = true; + workprefs.win32_active_input = 0; } + ew(hDlg, IDC_ACTIVE_NOJOY, paused == false); + ew(hDlg, IDC_ACTIVE_NOKEYBOARD, paused == false); if (paused) CheckDlgButton (hDlg, IDC_INACTIVE_PAUSE, TRUE); if (nosound || paused) CheckDlgButton(hDlg, IDC_INACTIVE_NOSOUND, TRUE); if (paused || nojoy) CheckDlgButton(hDlg, IDC_INACTIVE_NOJOY, TRUE); + if (paused || activenojoy) + CheckDlgButton(hDlg, IDC_ACTIVE_NOJOY, TRUE); + if (paused || activenokeyboard) + CheckDlgButton(hDlg, IDC_ACTIVE_NOKEYBOARD, TRUE); ew(hDlg, IDC_INACTIVE_PAUSE, paused == false); ew(hDlg, IDC_INACTIVE_NOSOUND, nosound == false && paused == false); ew(hDlg, IDC_INACTIVE_NOJOY, paused == false); @@ -12691,6 +12700,8 @@ static void values_to_miscdlg (HWND hDlg) CheckDlgButton(hDlg, IDC_ACTIVE_PAUSE, workprefs.win32_active_nocapture_pause); CheckDlgButton(hDlg, IDC_ACTIVE_NOSOUND, workprefs.win32_active_nocapture_nosound || workprefs.win32_active_nocapture_pause); + CheckDlgButton(hDlg, IDC_ACTIVE_NOJOY, (workprefs.win32_active_input & 4) == 0 || workprefs.win32_active_nocapture_pause); + CheckDlgButton(hDlg, IDC_ACTIVE_NOKEYBOARD, (workprefs.win32_active_input & 1) == 0 || workprefs.win32_active_nocapture_pause); CheckDlgButton(hDlg, IDC_INACTIVE_PAUSE, workprefs.win32_inactive_pause); CheckDlgButton(hDlg, IDC_INACTIVE_NOSOUND, workprefs.win32_inactive_nosound || workprefs.win32_inactive_pause); CheckDlgButton(hDlg, IDC_INACTIVE_NOJOY, (workprefs.win32_inactive_input & 4) == 0 || workprefs.win32_inactive_pause); @@ -13055,6 +13066,12 @@ static INT_PTR MiscDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) workprefs.win32_inactive_input = ischecked(hDlg, IDC_INACTIVE_NOJOY) ? 0 : 4; enable_for_miscdlg(hDlg); break; + case IDC_ACTIVE_NOJOY: + if (!ischecked(hDlg, IDC_ACTIVE_NOJOY)) + CheckDlgButton(hDlg, IDC_ACTIVE_NOJOY, BST_UNCHECKED); + case IDC_ACTIVE_NOKEYBOARD: + if (!ischecked(hDlg, IDC_ACTIVE_NOKEYBOARD)) + CheckDlgButton(hDlg, IDC_ACTIVE_NOKEYBOARD, BST_UNCHECKED); case IDC_ACTIVE_NOSOUND: if (!ischecked (hDlg, IDC_ACTIVE_NOSOUND)) CheckDlgButton (hDlg, IDC_ACTIVE_PAUSE, BST_UNCHECKED); @@ -13063,6 +13080,8 @@ static INT_PTR MiscDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) if (workprefs.win32_active_nocapture_pause) CheckDlgButton (hDlg, IDC_ACTIVE_NOSOUND, BST_CHECKED); workprefs.win32_active_nocapture_nosound = ischecked (hDlg, IDC_ACTIVE_NOSOUND); + workprefs.win32_active_input = ischecked(hDlg, IDC_ACTIVE_NOJOY) ? 0 : 4; + workprefs.win32_active_input |= ischecked(hDlg, IDC_ACTIVE_NOKEYBOARD) ? 0 : 1; enable_for_miscdlg (hDlg); break; case IDC_MINIMIZED_NOJOY: -- 2.47.3