Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 9, 2025

Closes #???

Related: #???, https://..., ...

What's new?

Mir was tracking keyboard modifiers based on physical scan codes, which don't change when XKB options remap keys. With altwin:swap_alt_win, pressing the Win key produced Alt_L keysym but Mir still reported Meta modifier active.

Solution: Query XKB's internal modifier state using xkb_state_mod_index_is_active() after each key event.

Implementation

  • Cache XKB modifier indices in XkbMappingState constructor for Shift, Ctrl, Alt, Logo (Meta/Super), Caps, Num
  • New update_modifier_from_xkb_state() method queries XKB for active modifiers instead of manual scan code tracking
  • Track pressed scancodes to determine left/right variants by checking keysyms of currently pressed keys
  • Replace press_modifier()/release_modifier() calls with XKB state queries that respect all keymap options

Technical Details

// Before: manual tracking based on scan codes
auto const mod_change = modifier_from_xkb_scan_code(scan_code);
press_modifier(mod_change);  // Broken with altwin:swap_alt_win

// After: query XKB state
xkb_state_update_key(state.get(), scan_code, XKB_KEY_DOWN);
update_modifier_from_xkb_state();  // XKB knows about remapping

When altwin:swap_alt_win is active:

  • Physical Win key → xkb_state_mod_index_is_active(mod_index_alt) returns true
  • Keysym query returns XKB_KEY_Alt_L for left/right distinction
  • Result: Alt modifier correctly reported

How to test

  1. Set keymap with miral::Keymap("us++altwin:swap_alt_win")
  2. Press physical Win key - should activate Alt modifier, not Meta
  3. Press physical Alt key - should activate Meta modifier, not Alt
  4. Without option, verify normal behavior (Win → Meta, Alt → Alt)

Checklist

  • Tests added and pass
  • Adequate documentation added
  • (optional) Added Screenshots or videos

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Setting the altwin:swap_alt_win keymap option using miral::Keymap has no effect on the modifiers</issue_title>
<issue_description>### Version

v2.22.0

Environment

OS: Ubuntu 24.04

What happened? What did you expect to happen?

I set miral::Keymap to use us+qwerty+altwin:swap_alt_win, but it did not successfully swap the alt and the win buttons.

When the win button is pressed, it is actually alt. And when alt is pressed, it is still alt. However, the modifiers remain unchanged.

Something is wrong with how we are handling XKB input.

Reproduction steps

  1. Set miral::Keymap("us+qwerty+altwin:swap_alt_win")
  2. Try to run a keybind that uses alt, expecting win to work
  3. Note that win will not work, but alt will still work

Relevant log output

```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits December 9, 2025 22:14
Instead of manually tracking modifiers based on scan codes, query XKB's
modifier state after each key event. This ensures XKB options like
altwin:swap_alt_win are properly respected.

- Add XKB modifier index caching in XkbMappingState constructor
- Implement update_modifier_from_xkb_state() to query XKB for active modifiers
- Track pressed scancodes to determine left/right modifier distinction
- Remove reliance on modifier_from_xkb_scan_code() for modifier tracking

Co-authored-by: mattkae <25062299+mattkae@users.noreply.github.com>
- Add comprehensive documentation for pressed_scancodes member
- Expand comment for cached XKB modifier indices
- Combine Alt and Meta modifier loops into single iteration for better performance
- Pre-check if Alt/Meta are active before iterating pressed scancodes

Co-authored-by: mattkae <25062299+mattkae@users.noreply.github.com>
- Use find() instead of count() for existence checks (more efficient)
- Add detailed comment explaining why we query keysyms for left/right detection

Co-authored-by: mattkae <25062299+mattkae@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix altwin keymap option not affecting modifiers Fix altwin:swap_alt_win keymap option by querying XKB state Dec 9, 2025
Copilot AI requested a review from mattkae December 9, 2025 22:24
@Saviq Saviq force-pushed the main branch 4 times, most recently from 39740d9 to 43ac49a Compare December 15, 2025 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting the altwin:swap_alt_win keymap option using miral::Keymap has no effect on the modifiers

2 participants