diff --git a/docs/widgets/(Widget)-Language.md b/docs/widgets/(Widget)-Language.md index 65267df..8bf17ca 100644 --- a/docs/widgets/(Widget)-Language.md +++ b/docs/widgets/(Widget)-Language.md @@ -22,7 +22,7 @@ language: ``` ## Description of Options -- **label:** The format string for the label. You can use placeholders like `{lang[language_code]}`, `{lang[country_code]}`, `{lang[full_name]}`, `{lang[native_country_name]}`, `{lang[native_lang_name]}`, +- **label:** The format string for the label. You can use placeholders like `{lang[language_code]}`, `{lang[country_code]}`, `{lang[full_name]}`, `{lang[native_country_name]}`, `{lang[native_lang_name]}`, `{lang[layout_name]}`, `{lang[full_layout_name]}`, `{lang[layout_country_name]}`. - **label_alt:** The alternative format string for the label. Useful for displaying the full language name. - **update_interval:** The interval in seconds to update the language information. Must be between 1 and 3600. - **callbacks:** A dictionary specifying the callbacks for mouse events. The keys are `on_left`, `on_middle`, and `on_right`, and the values are the names of the callback functions. diff --git a/src/core/widgets/yasb/language.py b/src/core/widgets/yasb/language.py index ee2e326..2f93431 100644 --- a/src/core/widgets/yasb/language.py +++ b/src/core/widgets/yasb/language.py @@ -11,8 +11,10 @@ LOCALE_SISO3166CTRYNAME = 0x5A LOCALE_SLANGUAGE = 0x2 LOCALE_SCOUNTRY = 0x6 +LOCALE_SNAME = 0x5c LOCALE_SNATIVECTRYNAME = 0x07 LOCALE_SNATIVELANGNAME = 0x04 + # Define necessary ctypes structures and functions user32 = ctypes.WinDLL('user32', use_last_error=True) kernel32 = ctypes.WinDLL('kernel32', use_last_error=True) @@ -126,10 +128,12 @@ def _get_current_keyboard_language(self): hwnd = user32.GetForegroundWindow() # Get the thread id of the foreground window thread_id = user32.GetWindowThreadProcessId(hwnd, None) - # Get the keyboard layout for the thread - hkl = user32.GetKeyboardLayout(thread_id) - # Get the language identifier from the HKL - lang_id = hkl & 0xFFFF + # Get the active input locale identifier for the thread + input_locale_id = user32.GetKeyboardLayout(thread_id) + # Extract the low word (language identifier) and high word (keyboard layout identifier) from the active input locale identifier + lang_id = input_locale_id & 0xFFFF + layout_id = (input_locale_id >> 16) & 0xFFFF + # Buffers for the language and country names lang_name = ctypes.create_unicode_buffer(LOCALE_NAME_MAX_LENGTH) country_name = ctypes.create_unicode_buffer(LOCALE_NAME_MAX_LENGTH) @@ -137,6 +141,10 @@ def _get_current_keyboard_language(self): full_country_name = ctypes.create_unicode_buffer(LOCALE_NAME_MAX_LENGTH) native_country_name = ctypes.create_unicode_buffer(LOCALE_NAME_MAX_LENGTH) native_lang_name = ctypes.create_unicode_buffer(LOCALE_NAME_MAX_LENGTH) + layout_locale_name = ctypes.create_unicode_buffer(LOCALE_NAME_MAX_LENGTH) + full_layout_locale_name = ctypes.create_unicode_buffer(LOCALE_NAME_MAX_LENGTH) + layout_country_name = ctypes.create_unicode_buffer(LOCALE_NAME_MAX_LENGTH) + # Get the ISO language name kernel32.GetLocaleInfoW(lang_id, LOCALE_SISO639LANGNAME, lang_name, LOCALE_NAME_MAX_LENGTH) # Get the ISO country name @@ -147,8 +155,15 @@ def _get_current_keyboard_language(self): kernel32.GetLocaleInfoW(lang_id, LOCALE_SCOUNTRY, full_country_name, LOCALE_NAME_MAX_LENGTH) # Get the native country name kernel32.GetLocaleInfoW(lang_id, LOCALE_SNATIVECTRYNAME, native_country_name, LOCALE_NAME_MAX_LENGTH) - + # Get the native language name kernel32.GetLocaleInfoW(lang_id, LOCALE_SNATIVELANGNAME, native_lang_name, LOCALE_NAME_MAX_LENGTH) + # Get the full name of the keyboard layout + kernel32.GetLocaleInfoW(layout_id, LOCALE_SNAME, layout_locale_name, LOCALE_NAME_MAX_LENGTH) + # Get the full language name of the keyboard layout + kernel32.GetLocaleInfoW(layout_id, LOCALE_SLANGUAGE, full_layout_locale_name, LOCALE_NAME_MAX_LENGTH) + # Get the full country name of the keyboard layout + kernel32.GetLocaleInfoW(layout_id, LOCALE_SCOUNTRY, layout_country_name, LOCALE_NAME_MAX_LENGTH) + language_code = lang_name.value country_code = country_name.value full_name = f"{full_lang_name.value}" @@ -157,5 +172,8 @@ def _get_current_keyboard_language(self): 'country_code': country_code, 'full_name': full_name, 'native_country_name': native_country_name.value, - 'native_lang_name': native_lang_name.value + 'native_lang_name': native_lang_name.value, + 'layout_name': layout_locale_name.value, + 'full_layout_name': full_layout_locale_name.value, + 'layout_country_name': layout_country_name.value } \ No newline at end of file