From 3164e0ecc4ecf49045f8442489a4ff5bda6d3d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Fri, 6 Jan 2023 08:15:41 +0100 Subject: [PATCH 4/9] winecfg: Add a keyboard layout selection config option. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=30984 Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45605 --- programs/winecfg/input.c | 48 ++++++++++++++++++++++++++++++++++++- programs/winecfg/resource.h | 3 +++ programs/winecfg/winecfg.rc | 9 +++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/programs/winecfg/input.c b/programs/winecfg/input.c index 115161b9040..f2f035df80f 100644 --- a/programs/winecfg/input.c +++ b/programs/winecfg/input.c @@ -35,7 +35,9 @@ static BOOL updating_ui; static void init_dialog( HWND dialog ) { - WCHAR *buffer; + WCHAR auto_detect_layout[256]; + WCHAR *buffer, *layout; + HWND layouts; convert_x11_desktop_key(); @@ -46,6 +48,23 @@ static void init_dialog( HWND dialog ) else CheckDlgButton( dialog, IDC_FULLSCREEN_GRAB, BST_UNCHECKED ); free( buffer ); + layouts = GetDlgItem( dialog, IDC_KEYBOARD_LAYOUT ); + LoadStringW( GetModuleHandleW( NULL ), IDS_INPUT_AUTO_DETECT_LAYOUT, auto_detect_layout, + ARRAY_SIZE(auto_detect_layout) ); + + SendMessageW( layouts, CB_RESETCONTENT, 0, 0 ); + SendMessageW( layouts, CB_ADDSTRING, 0, (LPARAM)auto_detect_layout ); + + buffer = get_reg_key( config_key, keypath( L"X11 Driver" ), L"KeyboardLayoutList", L"" ); + for (layout = buffer; *layout; layout += wcslen( layout ) + 1) + SendMessageW( layouts, CB_ADDSTRING, 0, (LPARAM)layout ); + free( buffer ); + + buffer = get_reg_key( config_key, keypath( L"X11 Driver" ), L"KeyboardLayout", L"" ); + if (!buffer || !buffer[0]) SendMessageW( layouts, CB_SETCURSEL, 0, 0 ); + else SendMessageW( layouts, CB_SELECTSTRING, -1, (LPARAM)buffer ); + free( buffer ); + updating_ui = FALSE; } @@ -56,6 +75,24 @@ static void on_fullscreen_grab_clicked( HWND dialog ) else set_reg_key( config_key, keypath( L"X11 Driver" ), L"GrabFullscreen", L"N" ); } +static void on_keyboard_layout_changed( HWND dialog ) +{ + int len, index; + WCHAR *buffer; + + if (!(index = SendMessageW( GetDlgItem( dialog, IDC_KEYBOARD_LAYOUT ), CB_GETCURSEL, 0, 0 ))) + set_reg_key( config_key, keypath( L"X11 Driver" ), L"KeyboardLayout", L"" ); + else + { + len = SendMessageW( GetDlgItem( dialog, IDC_KEYBOARD_LAYOUT ), CB_GETLBTEXTLEN, index, 0 ) + 1; + if (!(buffer = malloc( len * sizeof(WCHAR) ))) return; + + SendMessageW( GetDlgItem( dialog, IDC_KEYBOARD_LAYOUT ), CB_GETLBTEXT, index, (LPARAM)buffer ); + set_reg_key( config_key, keypath( L"X11 Driver" ), L"KeyboardLayout", buffer ); + free( buffer ); + } +} + INT_PTR CALLBACK InputDlgProc( HWND dialog, UINT message, WPARAM wparam, LPARAM lparam ) { TRACE( "dialog %p, message %#x, wparam %#Ix, lparam %#Ix\n", dialog, message, wparam, lparam ); @@ -77,6 +114,15 @@ INT_PTR CALLBACK InputDlgProc( HWND dialog, UINT message, WPARAM wparam, LPARAM case IDC_FULLSCREEN_GRAB: on_fullscreen_grab_clicked( dialog ); break; } break; + + case CBN_SELCHANGE: + if (updating_ui) break; + SendMessageW( GetParent( dialog ), PSM_CHANGED, 0, 0 ); + switch (LOWORD(wparam)) + { + case IDC_KEYBOARD_LAYOUT: on_keyboard_layout_changed( dialog ); break; + } + break; } break; diff --git a/programs/winecfg/resource.h b/programs/winecfg/resource.h index 78deb1a23a2..485bc18a217 100644 --- a/programs/winecfg/resource.h +++ b/programs/winecfg/resource.h @@ -231,3 +231,6 @@ /* input tab */ #define IDC_FULLSCREEN_GRAB 1501 +#define IDC_KEYBOARD_LAYOUT 1502 + +#define IDS_INPUT_AUTO_DETECT_LAYOUT 8501 diff --git a/programs/winecfg/winecfg.rc b/programs/winecfg/winecfg.rc index 605ec54632c..e0742794357 100644 --- a/programs/winecfg/winecfg.rc +++ b/programs/winecfg/winecfg.rc @@ -130,6 +130,11 @@ BEGIN IDC_SYSPARAMS_MENUBAR "Menu Bar" END +STRINGTABLE +BEGIN + IDS_INPUT_AUTO_DETECT_LAYOUT "(Auto detect)" +END + IDD_ABOUTCFG DIALOGEX 0, 0, 260, 220 STYLE WS_CHILD FONT 8, "MS Shell Dlg" @@ -330,6 +335,10 @@ FONT 8, "MS Shell Dlg" BEGIN GROUPBOX "Mouse settings",IDC_STATIC,8,4,244,64 CONTROL "Automatically capture the &mouse in full-screen windows",IDC_FULLSCREEN_GRAB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,20,230,10 + + GROUPBOX "Keyboard settings",IDC_STATIC,8,70,244,64 + LTEXT "&Layout:",IDC_STATIC,15,82,230,8 + COMBOBOX IDC_KEYBOARD_LAYOUT,110,80,135,60,CBS_DROPDOWNLIST | CBS_HASSTRINGS | CBS_SORT | WS_VSCROLL | WS_TABSTOP END LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -- 2.39.1