Skip to content

Support multi-layout keyboard setups#1

Open
UmutEmreOnder wants to merge 1 commit intoSporif:masterfrom
UmutEmreOnder:feat/multi-layout-support
Open

Support multi-layout keyboard setups#1
UmutEmreOnder wants to merge 1 commit intoSporif:masterfrom
UmutEmreOnder:feat/multi-layout-support

Conversation

@UmutEmreOnder
Copy link

@UmutEmreOnder UmutEmreOnder commented Mar 20, 2026

Problem

KWtype only searches the active XKB layout for keysym matches. On multi-layout setups (e.g. English + Turkish), characters unique to the secondary layout (şçöğüı) are never found and fall through to the Ctrl+Shift+U unicode fallback, which doesn't work in most applications.

The root cause is that the compositor sends a single keymap containing all configured layouts, but kwtype's internal XKB state always defaults to layout 0 and never receives layout-change events to stay in sync.

Solution

  • Search all layouts in the keymap for keysym matches, not just the effective layout
  • Use KWin's DBus API (org.kde.KeyboardLayouts.setLayout) to switch layouts at the compositor level when a character belongs to a different layout
  • Poll getLayout after setLayout to confirm the compositor has applied the switch before sending keys
  • Restore the original layout after typing is complete

Why DBus instead of simulating shortcut keys

DBus is deterministic and doesn't depend on user-configured keybindings (Meta+Space, Alt+Shift, etc.). It's KWin's official API for layout management.

Additional fix

  • Add missing <unistd.h> include for close() — required on newer GCC versions (16+)

KWtype only searched the first XKB layout for keysym matches,
so characters unique to a secondary layout (e.g. Turkish şçöğüı
on an English+Turkish setup) were never found. They fell through
to the Ctrl+Shift+U unicode fallback, which doesn't work in
most applications.

- Search all layouts in the keymap because the compositor
  reports a single keymap containing every configured layout,
  but the internal XKB state always defaults to layout 0.
  Relying on xkb_state_serialize_layout is wrong here since
  kwtype never receives layout-change events from the
  compositor to keep its state in sync.

- Use KWin's DBus API (org.kde.KeyboardLayouts) to switch
  layouts at the compositor level instead of simulating
  shortcut keys. DBus is the correct interface because it is
  deterministic and avoids depending on user-configured
  keybindings. Poll getLayout after setLayout to wait for
  the compositor to confirm the switch before sending keys.

- Restore the original layout after typing is complete so the
  user's keyboard state is not affected as a side effect.

- Add missing <unistd.h> include for close() on newer GCC
  versions where implicit declarations are an error.
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.

1 participant