Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reloading the config resets the keyboard layout #8941

Open
3 of 6 tasks
evtn opened this issue Jan 3, 2025 · 4 comments
Open
3 of 6 tasks

Reloading the config resets the keyboard layout #8941

evtn opened this issue Jan 3, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@evtn
Copy link

evtn commented Jan 3, 2025

Already reported ? *

  • I have searched the existing open and closed issues.

Regression?

I don't know, I started using Hyprland only recently

System Info and Hyprland Version

System/Version info
Hyprland 0.46.2 built from branch  at commit 0bd541f2fd902dbfa04c3ea2ccf679395e316887  (version: bump to 0.46.2).
Date: Thu Dec 19 19:26:47 2024
Tag: v0.46.2, commits: 5566
built against:
 aquamarine 0.5.1
 hyprlang 0.6.0
 hyprutils 0.3.0
 hyprcursor 0.1.11
 hyprgraphics 0.1.1


flags set:
debug


System Information:
System name: Linux
Node name: hyperjija
Release: 6.12.7-arch1-1
Version: #1 SMP PREEMPT_DYNAMIC Fri, 27 Dec 2024 14:24:37 +0000


GPU information: 
c7:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Phoenix3 [1002:1900] (rev c5) (prog-if 00 [VGA controller])


os-release: NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://gitlab.archlinux.org/groups/archlinux/-/issues"
PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"
LOGO=archlinux-logo


plugins:

Description

I have three keyboard layouts with this setup:

input {
    kb_layout = us,ru,ge
    kb_variant =
    kb_model =
    kb_options = grp:alt_shift_toggle,compose:rwin,caps:hyper
    kb_rules =

    follow_mouse = 1

    touchpad {
        natural_scroll = no
    }

    sensitivity = 0
}

I'm using wpaperd (wallpaper manager) with wallpapers changing randomly every N minutes (around 20-30, not important)
Then a script takes the accent color and uses it to color the window border, changing the file I import in config via source.
Then the current layout resets to English.

And a few times every day I happen to write something in non-English layout at that point in time and some word turns into a garbled mess.

How to reproduce

  1. Have more than one keyboard layout
  2. Switch to any layout except first one
  3. Save hyprland config
  4. ???
  5. Profit: layout has changed

Attach not paste

  • I understand that all text files must be attached, and not pasted directly. If not respected, this issue will likely get closed as spam

Checklist of files to include below

  • Hyprland config - hyprctl systeminfo -c (always include)
  • Crash report (always include in case of crash)
  • Video (always include in case of a visual bug)
  • Logs (might contain useful info such as errors)

Additional info & File uploads

hyprctl_systeminfo_c.txt

@evtn evtn added the bug Something isn't working label Jan 3, 2025
@khushal-solves
Copy link
Contributor

khushal-solves commented Jan 4, 2025

When should it reset? or in other words, when is it expected to reset.

Because after reloading configuration. It is expected to load first configured layout, isn't it?
One more question how do switch between different configured layouts? some keybinding?

@evtn
Copy link
Author

evtn commented Jan 4, 2025

I expect that reloading config shouldn't reset layout at all.
At least if the input options didn't change.

For the other question — I switch between layouts via Shift+Alt, yes, that's grp:alt_shift_toggle

@MahouShoujoMivutilde
Copy link
Contributor

I've meant to add this with #7486, but seems to have missed that it only works when numlock_by_default = yes. Sorry about that.

In the meantime you could use numlock_by_default = yes.

Trying to figure it out, I did some things:

Testing

This patch

diff --git a/src/devices/IKeyboard.cpp b/src/devices/IKeyboard.cpp
index d1119772..bfa2406f 100644
--- a/src/devices/IKeyboard.cpp
+++ b/src/devices/IKeyboard.cpp
@@ -118,11 +118,12 @@ void IKeyboard::setKeymap(const SStringRuleNames& rules) {

         if (IDX != XKB_MOD_INVALID)
             modifiersState.locked |= (uint32_t)1 << IDX;
-
-        // 0 to avoid mods getting stuck if depressed during reload
-        updateModifiers(0, 0, modifiersState.locked, modifiersState.group);
     }

+    // 0 to avoid mods getting stuck if depressed during reload;
+    // keep current keyboard *locks state and layout during the reload
+    updateModifiers(0, 0, modifiersState.locked, modifiersState.group);
+
     for (size_t i = 0; i < LEDNAMES.size(); ++i) {
         ledIndexes.at(i) = xkb_map_led_get_index(xkbKeymap, LEDNAMES.at(i));
         Debug::log(LOG, "xkb: LED index {} (name {}) got index {}", i, LEDNAMES.at(i), ledIndexes.at(i));

It works for me on latest git.

Tested and so far:

  • ✔️ layout (including typing and typing after pressing some mod key test) is always preserved.
  • ✔️ mods depressed during the reload don't get stuck.
  • ✔️ caps is preserved.
  • ❌ but numlock is inactive despite the LED being on when numlock_by_default = yes and it was off before the reload, until you toggle it off and on, or press some mod key ??
  • ❓ keys that were latched (typing ã etc) during the reload stay latched after, but trigger once fine and don't get stuck... They shouldn't be kept at all, because 0 for latched, but I guess it's fine so long as they don't get stuck.

I remember seeing issue like that, with numlock, but it was fixed. And there shouldn't be a difference between the patch and the current behavior when numlock_by_default = yes. Strange.

Let's check a few things:

  • Is numlock broken until the any mod is pressed when unpatched? - it works on launch; if you toggle it off it wont turn on after the reload until you press some modifier key, then it'll turn on and will work.

The numlock issue, at least after some preliminary testing, is fixed by modifying the patch like so

patch 2

diff --git a/src/devices/IKeyboard.cpp b/src/devices/IKeyboard.cpp
index d1119772..326d8325 100644
--- a/src/devices/IKeyboard.cpp
+++ b/src/devices/IKeyboard.cpp
@@ -112,17 +112,20 @@ void IKeyboard::setKeymap(const SStringRuleNames& rules) {

     const auto NUMLOCKON = g_pConfigManager->getDeviceInt(hlName, "numlock_by_default", "input:numlock_by_default");

+    auto locked = modifiersState.locked;
     if (NUMLOCKON == 1) {
         // lock numlock
         const auto IDX = xkb_map_mod_get_index(xkbKeymap, XKB_MOD_NAME_NUM);

         if (IDX != XKB_MOD_INVALID)
-            modifiersState.locked |= (uint32_t)1 << IDX;
-
-        // 0 to avoid mods getting stuck if depressed during reload
-        updateModifiers(0, 0, modifiersState.locked, modifiersState.group);
+            // indirect modification so we always emit event
+            locked |= (uint32_t)1 << IDX;
     }

+    // 0 to avoid mods getting stuck if depressed during reload;
+    // keeps keyboard's current *locks state and layout during the reload
+    updateModifiers(0, 0, locked, modifiersState.group);
+
     for (size_t i = 0; i < LEDNAMES.size(); ++i) {
         ledIndexes.at(i) = xkb_map_led_get_index(xkbKeymap, LEDNAMES.at(i));
         Debug::log(LOG, "xkb: LED index {} (name {}) got index {}", i, LEDNAMES.at(i), ledIndexes.at(i));

This, however, is almost the same as here, which didn't change anything for the issue, but it was in fact some other PR that fixed it, at least for me.

Anyway, for the current issue patch 2 seems to work and not break anything (?). Needs more testing.

This is all with

Hyprland 0.46.0 built from branch main at commit b0bae15499ad57bbfeae8be958df8c022201e583  (master: make loop around optional when cycling (8926)).
Date: Sat Jan 4 19:40:33 2025
Tag: v0.46.0-73-gb0bae154, commits: 5628
built against:
 aquamarine 0.5.1
 hyprlang 0.6.0
 hyprutils 0.3.1
 hyprcursor 0.1.11
 hyprgraphics 0.1.1
no flags were set

@evtn
Copy link
Author

evtn commented Jan 5, 2025

Well, I have tried this option (I have TKL keyboard, so no NumLock), and it works for me, layouts are preserved.

For my case it's good to go, won't close since I guess patches above should be tested (by someone with actual numlock)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants