diff options
| author | Eli Zaretskii | 2021-02-07 17:52:30 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2021-02-07 17:52:30 +0200 |
| commit | abedf3a8653829f5170ff72b2fc7adad0e6f80d4 (patch) | |
| tree | f45210093b04d7612eaf0b00b35b149abb2c8bdd /src | |
| parent | 8b8708eadd94fcdad4c426a20370ff4ab13df258 (diff) | |
| download | emacs-abedf3a8653829f5170ff72b2fc7adad0e6f80d4.tar.gz emacs-abedf3a8653829f5170ff72b2fc7adad0e6f80d4.zip | |
Fix language-environment and font selection on MS-Windows
These changes improve setting the language-environment and font
selection when MS-Windows returns useless "ZZZ" as the "language
name", which then disrupts all the setup of the locale-dependent
stuff, and in particular font selection.
* lisp/w32-fns.el (w32-charset-info-alist): Add an element for
"iso8859-5", in case LANG is set to something unusable, like
"ZZZ". This allows fonts capable of displaying Cyrillic
characters to be used even when language preferences are screwed.
* src/w32.c (init_environment): If GetLocaleInfo returns "ZZZ" as
the "language name" for LOCALE_USER_DEFAULT, try again with locale
ID based on what GetUserDefaultUILanguage returns. (Bug#39286)
Diffstat (limited to 'src')
| -rw-r--r-- | src/w32.c | 51 |
1 files changed, 51 insertions, 0 deletions
| @@ -346,6 +346,7 @@ static BOOL g_b_init_get_adapters_addresses; | |||
| 346 | static BOOL g_b_init_reg_open_key_ex_w; | 346 | static BOOL g_b_init_reg_open_key_ex_w; |
| 347 | static BOOL g_b_init_reg_query_value_ex_w; | 347 | static BOOL g_b_init_reg_query_value_ex_w; |
| 348 | static BOOL g_b_init_expand_environment_strings_w; | 348 | static BOOL g_b_init_expand_environment_strings_w; |
| 349 | static BOOL g_b_init_get_user_default_ui_language; | ||
| 349 | 350 | ||
| 350 | BOOL g_b_init_compare_string_w; | 351 | BOOL g_b_init_compare_string_w; |
| 351 | BOOL g_b_init_debug_break_process; | 352 | BOOL g_b_init_debug_break_process; |
| @@ -533,6 +534,7 @@ DWORD multiByteToWideCharFlags; | |||
| 533 | typedef LONG (WINAPI *RegOpenKeyExW_Proc) (HKEY,LPCWSTR,DWORD,REGSAM,PHKEY); | 534 | typedef LONG (WINAPI *RegOpenKeyExW_Proc) (HKEY,LPCWSTR,DWORD,REGSAM,PHKEY); |
| 534 | typedef LONG (WINAPI *RegQueryValueExW_Proc) (HKEY,LPCWSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD); | 535 | typedef LONG (WINAPI *RegQueryValueExW_Proc) (HKEY,LPCWSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD); |
| 535 | typedef DWORD (WINAPI *ExpandEnvironmentStringsW_Proc) (LPCWSTR,LPWSTR,DWORD); | 536 | typedef DWORD (WINAPI *ExpandEnvironmentStringsW_Proc) (LPCWSTR,LPWSTR,DWORD); |
| 537 | typedef LANGID (WINAPI *GetUserDefaultUILanguage_Proc) (void); | ||
| 536 | 538 | ||
| 537 | /* ** A utility function ** */ | 539 | /* ** A utility function ** */ |
| 538 | static BOOL | 540 | static BOOL |
| @@ -1489,6 +1491,28 @@ expand_environment_strings_w (LPCWSTR lpSrc, LPWSTR lpDst, DWORD nSize) | |||
| 1489 | return s_pfn_Expand_Environment_Strings_w (lpSrc, lpDst, nSize); | 1491 | return s_pfn_Expand_Environment_Strings_w (lpSrc, lpDst, nSize); |
| 1490 | } | 1492 | } |
| 1491 | 1493 | ||
| 1494 | static LANGID WINAPI | ||
| 1495 | get_user_default_ui_language (void) | ||
| 1496 | { | ||
| 1497 | static GetUserDefaultUILanguage_Proc s_pfn_GetUserDefaultUILanguage = NULL; | ||
| 1498 | HMODULE hm_kernel32 = NULL; | ||
| 1499 | |||
| 1500 | if (is_windows_9x () == TRUE) | ||
| 1501 | return 0; | ||
| 1502 | |||
| 1503 | if (g_b_init_get_user_default_ui_language == 0) | ||
| 1504 | { | ||
| 1505 | g_b_init_get_user_default_ui_language = 1; | ||
| 1506 | hm_kernel32 = LoadLibrary ("Kernel32.dll"); | ||
| 1507 | if (hm_kernel32) | ||
| 1508 | s_pfn_GetUserDefaultUILanguage = (GetUserDefaultUILanguage_Proc) | ||
| 1509 | get_proc_addr (hm_kernel32, "GetUserDefaultUILanguage"); | ||
| 1510 | } | ||
| 1511 | if (s_pfn_GetUserDefaultUILanguage == NULL) | ||
| 1512 | return 0; | ||
| 1513 | return s_pfn_GetUserDefaultUILanguage (); | ||
| 1514 | } | ||
| 1515 | |||
| 1492 | 1516 | ||
| 1493 | 1517 | ||
| 1494 | /* Return 1 if P is a valid pointer to an object of size SIZE. Return | 1518 | /* Return 1 if P is a valid pointer to an object of size SIZE. Return |
| @@ -2927,6 +2951,32 @@ init_environment (char ** argv) | |||
| 2927 | LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP, | 2951 | LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP, |
| 2928 | locale_name, sizeof (locale_name))) | 2952 | locale_name, sizeof (locale_name))) |
| 2929 | { | 2953 | { |
| 2954 | /* Microsoft are migrating away of locale IDs, replacing them | ||
| 2955 | with locale names, such as "en-US", and are therefore | ||
| 2956 | deprecating the APIs which use LCID etc. As part of that | ||
| 2957 | deprecation, they don't bother inventing LCID and LANGID | ||
| 2958 | codes for new locales and language/culture combinations; | ||
| 2959 | instead, those get LCID of 0xC000 and LANGID of 0x2000, for | ||
| 2960 | which the LCID/LANGID oriented APIs return "ZZZ" as the | ||
| 2961 | "language name". Such "language name" is useless for our | ||
| 2962 | purposes. So we instead use the default UI language, in the | ||
| 2963 | hope of getting something usable. */ | ||
| 2964 | if (strcmp (locale_name, "ZZZ") == 0) | ||
| 2965 | { | ||
| 2966 | LANGID lang_id = get_user_default_ui_language (); | ||
| 2967 | |||
| 2968 | if (lang_id != 0) | ||
| 2969 | { | ||
| 2970 | /* Disregard the sorting order differences between cultures. */ | ||
| 2971 | LCID def_lcid = MAKELCID (lang_id, SORT_DEFAULT); | ||
| 2972 | char locale_name_def[32]; | ||
| 2973 | |||
| 2974 | if (GetLocaleInfo (def_lcid, | ||
| 2975 | LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP, | ||
| 2976 | locale_name_def, sizeof (locale_name_def))) | ||
| 2977 | strcpy (locale_name, locale_name_def); | ||
| 2978 | } | ||
| 2979 | } | ||
| 2930 | for (i = 0; i < N_ENV_VARS; i++) | 2980 | for (i = 0; i < N_ENV_VARS; i++) |
| 2931 | { | 2981 | { |
| 2932 | if (strcmp (env_vars[i].name, "LANG") == 0) | 2982 | if (strcmp (env_vars[i].name, "LANG") == 0) |
| @@ -10451,6 +10501,7 @@ globals_of_w32 (void) | |||
| 10451 | g_b_init_expand_environment_strings_w = 0; | 10501 | g_b_init_expand_environment_strings_w = 0; |
| 10452 | g_b_init_compare_string_w = 0; | 10502 | g_b_init_compare_string_w = 0; |
| 10453 | g_b_init_debug_break_process = 0; | 10503 | g_b_init_debug_break_process = 0; |
| 10504 | g_b_init_get_user_default_ui_language = 0; | ||
| 10454 | num_of_processors = 0; | 10505 | num_of_processors = 0; |
| 10455 | /* The following sets a handler for shutdown notifications for | 10506 | /* The following sets a handler for shutdown notifications for |
| 10456 | console apps. This actually applies to Emacs in both console and | 10507 | console apps. This actually applies to Emacs in both console and |