Skip to content

Migrate existing keycode-based keybindings - #16049

Merged
y5nw merged 11 commits into
luanti-org:masterfrom
y5nw:dlg-rebind-keys
May 14, 2025
Merged

y5nw merged 11 commits into
luanti-org:masterfrom
y5nw:dlg-rebind-keys

Conversation

@y5nw

@y5nw y5nw commented Apr 20, 2025 •

Copy link
Copy Markdown
Contributor

Followup for #14964; mentioned (using the "check for keycode-based setting" approach here) in #14964 (comment)

  • How does the PR work?
    It automatically converts older keycodes to scancodes using a newly introduced core.normalized_keycode function. The warning dialog is shown if the setting for a key is changed.
  • Does it resolve any reported issue?
    No.
  • Does this relate to a goal in the roadmap?
    No.
  • If not a bug fix, why is this PR needed? What usecases does it solve?
    UX. It was agreed that this is needed to notify users about this change.

To do

This PR is Ready for Review.

How to test

Set e.g.

keymap_zoom = Z

and observe that

  • This is changed to a scancode-based setting that starts with SYSTEM_SCANCODE_.
  • A warning dialog is shown:

Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
Comment thread builtin/common/misc_helpers.lua Resolved
Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
@SmallJoker
SmallJoker self-requested a review May 4, 2025 18:15

@appgurueu appgurueu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dialog seems to work if you have non-default keybindings set 👍

Shouldn't we however apply a list of keycode defaults first? e.g. for me zoom changes from Z to Y due to the new default being a scancode rather than a keycode, but I won't be shown this dialog.

@SmallJoker SmallJoker left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT:

Shouldn't we however apply a list of keycode defaults first?

That's a good point, however keys that used to be set to the default are not saved in minetest.conf, thus it might be rather cumbersome to find that out.


  1. The dialog looks good. The link (now) does have a good contrast.
  2. No issues found using the Linux Irrlicht device (no dialog shown by default)

Output of print(value, normalized):

KEY_END	KEY_END
KEY_F4	KEY_F4
KEY_KEY_G	KEY_KEY_G
KEY_PRIOR	KEY_PRIOR
KEY_F7	KEY_F7
KEY_KEY_P	KEY_KEY_P
KEY_PERIOD	KEY_PERIOD
KEY_KEY_F	KEY_KEY_F
KEY_KEY_C	KEY_KEY_C
KEY_NEXT	KEY_NEXT
KEY_F9	KEY_F9
KEY_ADD	KEY_ADD
KEY_HOME	KEY_HOME
KEY_KEY_R	KEY_KEY_R
KEY_F8	KEY_F8
KEY_SUBTRACT	KEY_SUBTRACT

@appgurueu

Copy link
Copy Markdown
Contributor

it might be rather cumbersome to find that out

I was thinking we could simply take the defaults from https://github.com/luanti-org/luanti/pull/14964/files#diff-c28e817ab2f95efdc57a5c4697751d2b4a607b75571f812738808ff7137e61c2, stuff them in a table, and call it a day.

@y5nw
y5nw force-pushed the dlg-rebind-keys branch from 4bd85a2 to af30b67 Compare May 5, 2025 20:19
@y5nw y5nw changed the title Migrate existing keycode-based keybindings; add warning dialog about migration (No sq) Migrate existing keycode-based keybindings; add warning dialog about migration May 5, 2025
@y5nw y5nw changed the title (No sq) Migrate existing keycode-based keybindings; add warning dialog about migration [No sq] Migrate existing keycode-based keybindings; add warning dialog about migration May 5, 2025
@y5nw

y5nw commented May 5, 2025 •

Copy link
Copy Markdown
Contributor Author

No issues found using the Linux Irrlicht device (no dialog shown by default)

This should be correct even before this PR, given that the normalization is basically done with KeyPress(str).sym() (-> non-SDL devices continue to normalize keycodes to keycodes).

Shouldn't we however apply a list of keycode defaults first? e.g. for me zoom changes from Z to Y due to the new default being a scancode rather than a keycode, but I won't be shown this dialog.

810b405 for the zoom key (and some more). Not sure about others:

  • Viewing range: different layouts inconsistently have + on the regular or shifted state (compare US vs German layouts), so this is hard to detect correctly. The scancode-based defaults are IMO also not too problematic; these are next to each other, while + and - are not (always) next to each other.
  • Inventory key: IMO we don't need to bikeshed that here ...

@y5nw
y5nw force-pushed the dlg-rebind-keys branch from af30b67 to 810b405 Compare May 5, 2025 20:39
@y5nw
y5nw requested a review from SmallJoker May 5, 2025 20:39
@y5nw y5nw changed the title [No sq] Migrate existing keycode-based keybindings; add warning dialog about migration [No sq] Migrate existing keycode-based keybindings May 5, 2025
@grorp

grorp commented May 5, 2025 •

Copy link
Copy Markdown
Member

It looks like 810b405 reintroduces keycode-based defaults for some keybindings. Didn't we decide against mixing keycode-based and scancode-based defaults? (Does the keycode-based keymap_cmd default make #14545 applicable again?)

(I think what appgurueu asked for is merely showing the dialog as well if you use the default keybindings, and the default keybindings have changed on your keyboard layout due to the move from keycodes to scancodes. Currently you would only see the dialog if you have non-default keybindings set.)

@y5nw

y5nw commented May 6, 2025 •

Copy link
Copy Markdown
Contributor Author

It looks like 810b405 reintroduces keycode-based defaults for some keybindings. Didn't we decide against mixing keycode-based and scancode-based defaults?

We did (and I did as well). However, the approach here is IMO better than the idea at the time of putting keycode-based keybindings directly into defaultsettings.cpp (which I still oppose, for the record):

  • The keycode-based defaults are still backed using scancodes. These are converted to scancodes once (on startup), after which these effectively behave like scancode-based keybindings. In particular, it is possible to deterministically check for keybinding conflicts, even after changing keyboard layouts (although the keybindings would no longer be adjusted again unless the user reopens Luanti).
  • These defaults are adjusted based on the defaults from defaultsettings.cpp, so there is a non-conflicting fallback if the keycode-based keybinding is not usable (i.e. the key is not available or would produce a conflict). This avoids the problem with e.g. the zoom key on AZERTY, where putting KEY_KEY_Z directly in defaultsettings.cpp would lead to a conflict.

(Does the keycode-based keymap_cmd default make #14545 applicable again?)

Yes; although there is the possibility of going against binding keys in the (potentially) shifted state, which I decided for e.g. + and -.

(I think what appgurueu asked for is merely showing the dialog as well if you use the default keybindings, and the default keybindings have changed on your keyboard layout due to the move from keycodes to scancodes. Currently you would only see the dialog if you have non-default keybindings set.)

I know, but doing this for changed keybindings would not be much simpler (and: should we show this on startup for new installations? if not, we also need to be able to determine that), and IMO it is better UX-wise to adjust such keybindings ourselves now that this is doable without significant breakages (see above).

@grorp

grorp commented May 8, 2025 •

Copy link
Copy Markdown
Member

The "show dialog when default keybindings are used and have changed due to the move to scancodes" request is still valid with 810b405 though.
The approach in 810b405 does not cover all possible affected default keys on all possible keyboard layouts. It cannot, unless you just make everything use keycode defaults again. We don't want that for obvious reasons, and even if we wanted, it wouldn't work out due to #14545

Yes; although there is the possibility of going against binding keys in the (potentially) shifted state, which I decided for e.g. + and -.

Well then at least a keycode default for keymap_cmd is not an option, is it?

should we show this on startup for new installations?

No, we shouldn't. That's something I was also going to bring up. The only approach to detect this I really see is "assume first launch when creating a new minetest.conf, store setting indicating that dialog should not be shown", which is not as straightforward as it would ideally be. (A hacky alternative could be checking some unrelated setting that's only present after first launch.)
On the other hand, showing the dialog for new users as well might not be too bad either, considering that we have portable Windows builds where every upgrade essentially results in a new installation.

@y5nw

y5nw commented May 8, 2025

Copy link
Copy Markdown
Contributor Author

Well then at least a keycode default for keymap_cmd is not an option, is it?

It can still be used for situations where / is in the unshifted position. Otherwise (=> core.normalize_keycode("/") == "") the default from defaultsettings.cpp is used:

if normalized ~= "" and not has_key[normalized] then
has_key[default_settings[name]] = nil
has_key[normalized] = name
core.default_settings:set(name, value)
end

should we show this on startup for new installations?

No, we shouldn't. That's something I was also going to bring up. The only approach to detect this I really see is "assume first launch when creating a new minetest.conf, store setting indicating that dialog should not be shown", which is not as straightforward as it would ideally be. (A hacky alternative could be checking some unrelated setting that's only present after first launch.)

Another (simpler) idea would be to reword the dialog to prompt the user (once) to change keybindings as the default may be suboptimal (related: #16053).

Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
Co-authored-by: grorp <gregor.parzefall@posteo.de>
@y5nw
y5nw force-pushed the dlg-rebind-keys branch from 810b405 to 2fda797 Compare May 12, 2025 12:15
@y5nw

This comment was marked as resolved.

Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
@y5nw
y5nw force-pushed the dlg-rebind-keys branch from 2fda797 to f424286 Compare May 12, 2025 19:03
@y5nw

y5nw commented May 12, 2025

Copy link
Copy Markdown
Contributor Author

#16049 (comment)

No, we shouldn't. That's something I was also going to bring up. The only approach to detect this I really see is "assume first launch when creating a new minetest.conf, store setting indicating that dialog should not be shown", which is not as straightforward as it would ideally be.

This turned out to be not as complicated as I initially thought: 5cd5020

(That said, I decided to take the somewhat lazy path of unconditionally showing the migration warning if the user upgrades and no_keycode_migration_warning is unset. This would include situations where defaults remain unchanged after #14964, but that PR did also change the behavior of e.g. the numpad and shift keys.)

Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
Comment thread builtin/mainmenu/common.lua Resolved
Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved

@sfan5 sfan5 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good so far, will test later.

Comment thread src/main.cpp Resolved
Comment thread src/settings.h Resolved
Comment thread builtin/mainmenu/dlg_rebind_keys.lua Resolved
y5nw and others added 2 commits May 14, 2025 13:13
Co-authored-by: sfan5 <sfan5@live.de>
Co-authored-by: sfan5 <sfan5@live.de>

@SmallJoker SmallJoker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☑️ New installation (faked it) --> dialog is not shown
☑️ Existing installation without no_keycode_migration_warning --> dialog is shown
☑️ Existing installation with no_keycode_migration_warning = true --> dialog is not shown (because it was already shown before)
☑️ The setting values are preserved if there's no change (SDL -> SDL, Platform-Native -> Platform-Native. --> the dialog is shown anyway (once). This is also valid because / (in my case) Shift+7 was rebound to -.

For some reason, the German translation of "Dismiss" is currently "Ablehnen" (= reject/refuse/dismiss), which may match in some cases - here it's misleading because the change won't/can't be reverted. Might "Ignore" be a better choice?
Anyway - the PR works, thus I approve again.

@sfan5

sfan5 commented May 14, 2025

Copy link
Copy Markdown
Member

Might "Ignore" be a better choice?

Just "Close"?

@sfan5 sfan5 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works.

@grorp grorp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my earlier concerns have been resolved
code looks good
I haven't tested

@grorp

grorp commented May 14, 2025 •

Copy link
Copy Markdown
Member

Just "Close"?

(also doesn't necessarily have to be red. the MTG dialog's dismiss button was just red as a warning because it would effectively make your MTG worlds disappear from the menu.)

@y5nw

y5nw commented May 14, 2025

Copy link
Copy Markdown
Contributor Author

Just "Close"?

(also doesn't necessarily have to be red. the MTG dialog's dismiss button was just red as a warning because it would effectively make your MTG worlds disappear from the menu.)

Both done in 71bb3db

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants