From aad104be995fbfd517d70bc872ff9eec1fbc5f42 Mon Sep 17 00:00:00 2001 From: Omegadarling <112964595+Omegadarling@users.noreply.github.com> Date: Tue, 17 Nov 2026 16:02:00 -0500 Subject: [PATCH] Add option for Escape to close the viewer Pressing Escape now closes the viewer when Escape has nothing else to do. The existing Escape behaviour keeps priority, in this order: cancelling the current action, leaving fullscreen, then any command bound to Escape. Key repeats are ignored, so holding Escape to leave fullscreen does not also close the viewer. The option is on by default and can be turned off in Options > Controls > "Escape key closes the viewer" (ini: escape_closes). Notes for merging: - master does not build until one of the open build-fix pull requests (88 or 95) lands. The new control ID is 1067 so it does not collide with the IDs those add (1055-1066). The companion "zoom out past best fit" pull request uses 1068. - res/voidImageViewer.rc will conflict with 88/95 in IDD_CONTROLS, because they rename the IDs on the lines this change moves down. The right resolution keeps their IDs (IDC_COMMANDS_STATIC, the *_COMBOBOX names and so on) with this change's positions: the checkbox at 0,53, "&Commands:" at 0,70 and the command list at 0,81,193,61. Taking their side whole drops the checkbox, which silently turns the option off every time Options is closed with OK. I'm happy to rebase once a build fix is merged. - The Chinese label is a best-effort translation and may need a native speaker's review. Co-Authored-By: Claude Opus 5.5 --- res/resource.h | 3 ++- res/voidImageViewer.rc | 5 +++-- src/config.c | 3 +++ src/config.h | 1 + src/localization.h | 1 + src/localization_en_us.h | 1 + src/localization_zh_cn.h | 1 + src/viv.c | 14 ++++++++++++++ 8 files changed, 26 insertions(+), 3 deletions(-) diff --git a/res/resource.h b/res/resource.h index e3639f70..77d2b727 100644 --- a/res/resource.h +++ b/res/resource.h @@ -90,6 +90,7 @@ #define IDC_TITLE_BAR_FORMAT 1052 #define IDC_SHRINK_BLIT_MODE_STATIC 1053 #define IDC_MAGNIFY_BLIT_MODE_STATIC 1054 +#define IDC_ESCAPE_CLOSES_CHECKBOX 1067 // Next default values for new objects // @@ -98,7 +99,7 @@ #define _APS_NO_MFC 1 #define _APS_NEXT_RESOURCE_VALUE 130 #define _APS_NEXT_COMMAND_VALUE 40048 -#define _APS_NEXT_CONTROL_VALUE 1055 +#define _APS_NEXT_CONTROL_VALUE 1068 #define _APS_NEXT_SYMED_VALUE 109 #endif #endif diff --git a/res/voidImageViewer.rc b/res/voidImageViewer.rc index b138421b..90cebc36 100644 --- a/res/voidImageViewer.rc +++ b/res/voidImageViewer.rc @@ -99,8 +99,9 @@ BEGIN COMBOBOX IDC_RIGHTCLICKACTION,74,17,119,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP LTEXT "&Mouse wheel action:",IDC_STATIC,0,36,72,8 COMBOBOX IDC_MOUSEWHEELACTION,74,34,119,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "&Commands:",IDC_STATIC,0,53,57,8 - LISTBOX IDC_COMMANDS_LIST,0,64,193,78,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP + CONTROL "Escape &key closes the viewer",IDC_ESCAPE_CLOSES_CHECKBOX,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,0,53,193,10 + LTEXT "&Commands:",IDC_STATIC,0,70,57,8 + LISTBOX IDC_COMMANDS_LIST,0,81,193,61,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP GROUPBOX "Settings for selected command",IDC_STATIC,0,148,193,67 LISTBOX IDC_KEYS_LIST,7,158,125,50,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP PUSHBUTTON "&Add...",IDC_ADD_KEY,138,158,50,14 diff --git a/src/config.c b/src/config.c index 719eb0c1..7a0aa3d8 100644 --- a/src/config.c +++ b/src/config.c @@ -59,6 +59,7 @@ BYTE config_prevent_sleep = 1; BYTE config_loop_animations_once = 1; BYTE config_mouse_wheel_action = 0; // 0 = zoom, 1 = next/prev, 2=prev/next BYTE config_ctrl_mouse_wheel_action = 0; // 0 = zoom, 1 = next/prev, 2=prev/next +BYTE config_escape_closes = 1; // escape closes the viewer when there is nothing to cancel and we are not fullscreen. BYTE config_left_click_action = 0; // 0 = scroll, 1 = play/pause slideshow, 2 = play/pause animation, 3=zoom in, 4=next, 5=1:1 scroll, 6=move-window BYTE config_right_click_action = 0; // 0 = context menu, 1=zoom out, 2=prev, BYTE config_xbutton_action = 2; // 1=zoom, 2=next @@ -131,6 +132,7 @@ static void _config_load_settings_by_location(const wchar_t *path,int is_root) config_frame_minus = ini_get_int(ini,(const utf8_t *)"frame_minus",config_frame_minus); config_mouse_wheel_action = ini_get_int(ini,(const utf8_t *)"mouse_wheel_action",config_mouse_wheel_action); config_ctrl_mouse_wheel_action = ini_get_int(ini,(const utf8_t *)"ctrl_mouse_wheel_action",config_ctrl_mouse_wheel_action); + config_escape_closes = ini_get_int(ini,(const utf8_t *)"escape_closes",config_escape_closes); config_left_click_action = ini_get_int(ini,(const utf8_t *)"left_click_action",config_left_click_action); config_right_click_action = ini_get_int(ini,(const utf8_t *)"right_click_action",config_right_click_action); config_xbutton_action = ini_get_int(ini,(const utf8_t *)"xbutton_action",config_xbutton_action); @@ -315,6 +317,7 @@ static void _config_save_settings_by_location(const wchar_t *path,int is_root) _config_write_int(h,"frame_minus",config_frame_minus); _config_write_int(h,"mouse_wheel_action",config_mouse_wheel_action); _config_write_int(h,"ctrl_mouse_wheel_action",config_ctrl_mouse_wheel_action); + _config_write_int(h,"escape_closes",config_escape_closes); _config_write_int(h,"left_click_action",config_left_click_action); _config_write_int(h,"right_click_action",config_right_click_action); _config_write_int(h,"xbutton_action",config_xbutton_action); diff --git a/src/config.h b/src/config.h index 6a6afa13..f736832c 100644 --- a/src/config.h +++ b/src/config.h @@ -88,6 +88,7 @@ extern BYTE config_prevent_sleep; extern BYTE config_loop_animations_once; extern BYTE config_mouse_wheel_action; extern BYTE config_ctrl_mouse_wheel_action; +extern BYTE config_escape_closes; extern BYTE config_left_click_action; extern BYTE config_right_click_action; extern BYTE config_xbutton_action; diff --git a/src/localization.h b/src/localization.h index 99248c5d..425ae6e7 100644 --- a/src/localization.h +++ b/src/localization.h @@ -258,6 +258,7 @@ enum LOCALIZATION_ID_LEFT_CLICK_ACTION_STATIC, LOCALIZATION_ID_RIGHT_CLICK_ACTION_STATIC, LOCALIZATION_ID_MOUSE_WHEEL_ACTION_STATIC, + LOCALIZATION_ID_ESCAPE_CLOSES_CHECKBOX, LOCALIZATION_ID_COMMANDS_STATIC, LOCALIZATION_ID_SETTINGS_FOR_SELECTED_COMMAND, LOCALIZATION_ID_ADD_KEY_BUTTON, diff --git a/src/localization_en_us.h b/src/localization_en_us.h index 5747262c..48c966cd 100644 --- a/src/localization_en_us.h +++ b/src/localization_en_us.h @@ -235,6 +235,7 @@ static const utf8_t *_localization_string_array_en_us[LOCALIZATION_ID_COUNT] = "&Left click action:", // LOCALIZATION_ID_LEFT_CLICK_ACTION_STATIC, "&Right click action:", // LOCALIZATION_ID_RIGHT_CLICK_ACTION_STATIC, "&Mouse wheel action:", // LOCALIZATION_ID_MOUSE_WHEEL_ACTION_STATIC, + "Escape &key closes the viewer", // LOCALIZATION_ID_ESCAPE_CLOSES_CHECKBOX, "&Commands:", // LOCALIZATION_ID_COMMANDS_STATIC, "Settings for selected command", // LOCALIZATION_ID_SETTINGS_FOR_SELECTED_COMMAND, "&Add...", // LOCALIZATION_ID_ADD_KEY_BUTTON, diff --git a/src/localization_zh_cn.h b/src/localization_zh_cn.h index 3d135697..2795ac4c 100644 --- a/src/localization_zh_cn.h +++ b/src/localization_zh_cn.h @@ -236,6 +236,7 @@ static const utf8_t *_localization_string_array_zh_cn[LOCALIZATION_ID_COUNT] = "左键操作(&L):", // LOCALIZATION_ID_LEFT_CLICK_ACTION_STATIC, "右键操作(&R):", // LOCALIZATION_ID_RIGHT_CLICK_ACTION_STATIC, "鼠标滚轮操作(&M):", // LOCALIZATION_ID_MOUSE_WHEEL_ACTION_STATIC, + "按 Esc 键关闭查看器(&K)", // LOCALIZATION_ID_ESCAPE_CLOSES_CHECKBOX, "命令(&C):", // LOCALIZATION_ID_COMMANDS_STATIC, "所选命令的设置", // LOCALIZATION_ID_SETTINGS_FOR_SELECTED_COMMAND, "添加(&A)...", // LOCALIZATION_ID_ADD_KEY_BUTTON, diff --git a/src/viv.c b/src/viv.c index deff4526..21ec119e 100644 --- a/src/viv.c +++ b/src/viv.c @@ -6409,6 +6409,16 @@ static int _viv_is_msg(MSG *msg) k = k->next; } } + + // close the viewer with escape. + // cancelling an action, leaving fullscreen and a command bound to escape all take priority. + // ignore key repeats so holding escape to leave fullscreen doesn't also close the viewer. + if ((config_escape_closes) && (key_flags == 0) && (msg->wParam == VK_ESCAPE) && (!(msg->lParam & 0x40000000))) + { + _viv_exit(); + + return 1; + } } } @@ -8248,6 +8258,9 @@ static INT_PTR CALLBACK _viv_options_controls_proc(HWND hwnd,UINT msg,WPARAM wPa os_ComboBox_AddString_localization_id(hwnd,IDC_MOUSEWHEELACTION_COMBOBOX,LOCALIZATION_ID_OPTIONS_ACTION_PREV_NEXT_COMBOBOXITEM); ComboBox_SetCurSel(GetDlgItem(hwnd,IDC_MOUSEWHEELACTION_COMBOBOX),config_mouse_wheel_action); + os_SetDlgItemText_localization_id(hwnd,IDC_ESCAPE_CLOSES_CHECKBOX,LOCALIZATION_ID_ESCAPE_CLOSES_CHECKBOX); + CheckDlgButton(hwnd,IDC_ESCAPE_CLOSES_CHECKBOX,config_escape_closes ? BST_CHECKED : BST_UNCHECKED); + os_SetDlgItemText_localization_id(hwnd,IDC_COMMANDS_STATIC,LOCALIZATION_ID_COMMANDS_STATIC); os_SetDlgItemText_localization_id(hwnd,IDC_SETTINGS_FOR_SELECTED_COMMAND_STATIC,LOCALIZATION_ID_SETTINGS_FOR_SELECTED_COMMAND); os_SetDlgItemText_localization_id(hwnd,IDC_ADD_KEY_BUTTON,LOCALIZATION_ID_ADD_KEY_BUTTON); @@ -8713,6 +8726,7 @@ static INT_PTR CALLBACK _viv_options_proc(HWND hwnd,UINT msg,WPARAM wParam,LPARA config_left_click_action = ComboBox_GetCurSel(GetDlgItem(controls_page,IDC_LEFTCLICKACTION_COMBOBOX)); config_right_click_action = ComboBox_GetCurSel(GetDlgItem(controls_page,IDC_RIGHTCLICKACTION_COMBOBOX)); config_mouse_wheel_action = ComboBox_GetCurSel(GetDlgItem(controls_page,IDC_MOUSEWHEELACTION_COMBOBOX)); + config_escape_closes = IsDlgButtonChecked(controls_page,IDC_ESCAPE_CLOSES_CHECKBOX) == BST_CHECKED ? 1 : 0; if (ComboBox_GetCurSel(GetDlgItem(view_page,IDC_SHRINK_BLIT_MODE_COMBOBOX)) == 1) {