xquartz: expose the Option layer as a real XKB level - #14
Open
lummi-ch23 wants to merge 1 commit into
Open
lummi-ch23 wants to merge 1 commit into
lummi-ch23 wants to merge 1 commit into
Conversation
On a non-US Mac keyboard layout, Option+key characters (the AltGr / level-3 layer, e.g. @ on Option+G, # on Option+3 on Swiss German) do not reach XKB-native clients (GTK, Qt) over X11. xev reports the correct keysym, but GTK apps get the base glyph. DarwinBuildModifierMaps rewrites the Option key to XK_Mode_switch when !XQuartzOptionSendsAlt, and the four glyphs per key are consumed as two core-protocol groups. Core clients reach the Option layer as group 2 via Mode_switch, but XKB-native clients resolve levels through the XKB state, where the key types built from the width-4 core map are two-level; level 3 is unreachable and the app falls back to the base glyph. Map the Option key to XK_ISO_Level3_Shift on Mod5 and, after XkbApplyMappingChange, install a FOUR_LEVEL key type and switch each Option-bearing key to one group of it via XkbChangeTypesOfKey, which resizes the symbol map and keeps width/offset/ group_info consistent. XKB-native clients then reach the Option layer as level 3. The new type slot is memset and its level_names/preserve populated before use: XkbAllocClientMap does not clear a slot that fits existing slack, and an uninitialised level_names pointer crashed XkbCopyKeymap (memmove) during device-class copy on the next key event. Assigning types with XkbChangeTypesOfKey rather than hand-editing width/offset is what keeps the keymap copy-safe. Tested on Apple Silicon (2.8.6 SDK, -Dxcsecurity=true): Option+G yields @ and Option+3 yields # in GTK apps, verified via xev and xkbcomp; ssh -X works. Signed-off-by: Christoph Lumme <christoph.lumme@siemens.com>
lummi-ch23
force-pushed
the
xquartz-option-level3
branch
from
September 11, 2026 23:37
f208803 to
68f6c1c
Compare
Author
|
Updated the branch: the first revision crashed the server (SIGSEGV in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a non-US Mac keyboard layout,
Option+key characters (the AltGr / level-3layer, e.g.
@onOption+G,#onOption+3on Swiss German) do not reachXKB-native clients (GTK, Qt) over X11.
xevreports the correct keysym, but GTKapps get the base glyph (
ginstead of@).Cause
DarwinBuildModifierMapsrewrites the Option key toXK_Mode_switchwhen!XQuartzOptionSendsAlt, and the four glyphs per key are consumed as twocore-protocol groups. Core clients reach the Option layer as group 2 via
Mode_switch, but XKB-native clients resolve levels/groups through the XKB state,where
Mode_switchis a level shifter and the key types built from the width-4core map are two-level. Level 3 is therefore unreachable and the app falls back to
the base glyph. The existing code even comments "Yes, this is ugly."
Fix
Map the Option key to
XK_ISO_Level3_ShiftonMod5and, afterXkbApplyMappingChange, install a genuineFOUR_LEVELkey type for each key thatcarries an Option-layer glyph, laying the four glyphs out as one group of four
levels (
base, shift, option, option+shift). XKB-native clients then reach theOption layer as level 3, matching how a native Linux
ch(de_mac)layout presentsit. Core-protocol behaviour is unchanged.
Testing
Built on Apple Silicon against the 2.8.6 SDK (
-Dxquartz=true -Dsecure-rpc=false -Dxcsecurity=true), installed overX11.bin. Verified with a real keypress:Option+Gyields@andOption+3yields#in GTK apps (Intune portal,xfce4-terminal); confirmed via
xevandxkbcomp -xkbthat the G key now has afour-level type with
@at level 3 and Option on Mod5.ssh -Xuntrustedforwarding works (SECURITY extension enabled).