Xmonad 可以区别对待左右 alt 吗?

Xmonad 可以区别对待左右 alt 吗?

ALT_R我有一个使用+ENTER来执行功能的应用程序。在 Xmonad 中使用此应用程序时,组合Mod1+ENTER会触发“将当前窗口与主窗口交换”功能。默认情况下,ALT_LALT_R映射到Mod1.

在我的 中.xinitrc,在启动 Xmonad 之前,我已经更改了我的键映射,xmodmapALT_R不是Mod1定义的一部分。尽管如此,Xmonad 在输入ALT_R+时仍然执行窗口交换行为ENTER。 Xmonad 似乎不知道Mod1不再包含ALT_R.

这是我的.xinitrc

# Java's GUI can't handle some non-reparenting window managers like
# Xmonad without being told how to behave
export _JAVA_AWT_WM_NONREPARENTING=1

# The right Alt key is useful in IntelliJ, tell Xmonad to ignore it
xmodmap ~/.Xmodmap

# Start Xmonad
xmonad

xmodmap这是Xmonad 启动后的输出。

xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3      
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

我已经记录了该序列xev并确认该ENTER序列从未注册过。相反,在记录后会发生多个FocusIn/FocusOut事件。ALT_R

KeyPress event, serial 32, synthetic NO, window 0x1200001,
    root 0xc0, subw 0x0, time 1432589, (92,374), root:(93,375),
    state 0x0, keycode 108 (keysym 0xffea, Alt_R), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

FocusOut event, serial 32, synthetic NO, window 0x1200001,
    mode NotifyGrab, detail NotifyAncestor

PropertyNotify event, serial 32, synthetic NO, window 0x1200001,
    atom 0x155 (WM_STATE), time 1433760, state PropertyNewValue

FocusOut event, serial 32, synthetic NO, window 0x1200001,
    mode NotifyUngrab, detail NotifyPointer

FocusIn event, serial 32, synthetic NO, window 0x1200001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 32, synthetic NO, window 0x0,
    keys:  0   0   0   0   0   0   0   0   0   0   0   0   0   16  0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

KeyRelease event, serial 32, synthetic NO, window 0x1200001,
    root 0xc0, subw 0x0, time 1434117, (92,374), root:(93,375),
    state 0x8, keycode 108 (keysym 0xffea, Alt_R), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

另一个有趣的观察是,无论是否按下或正在按下,每个按键事件的xev报告为 8。常数in定义为 8。以下序列是+后跟+ 。stateALT_LALT_RMod1Mask/usr/include/X11/X.hALT_LfALT_Rf

KeyPress event, serial 32, synthetic NO, window 0x1000001,
    root 0xc0, subw 0x0, time 4126632, (85,488), root:(86,489),
    state 0x0, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 32, synthetic NO, window 0x1000001,
    root 0xc0, subw 0x0, time 4126850, (85,488), root:(86,489),
    state 0x8, keycode 41 (keysym 0x66, f), same_screen YES,
    XLookupString gives 1 bytes: (66) "f"
    XmbLookupString gives 1 bytes: (66) "f"
    XFilterEvent returns: False

KeyRelease event, serial 32, synthetic NO, window 0x1000001,
    root 0xc0, subw 0x0, time 4126930, (85,488), root:(86,489),
    state 0x8, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 32, synthetic NO, window 0x1000001,
    root 0xc0, subw 0x0, time 4126969, (85,488), root:(86,489),
    state 0x0, keycode 41 (keysym 0x66, f), same_screen YES,
    XLookupString gives 1 bytes: (66) "f"
    XFilterEvent returns: False

KeyPress event, serial 32, synthetic NO, window 0x1000001,
    root 0xc0, subw 0x0, time 4127907, (85,488), root:(86,489),
    state 0x0, keycode 108 (keysym 0xffea, Alt_R), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 32, synthetic NO, window 0x1000001,
    root 0xc0, subw 0x0, time 4128123, (85,488), root:(86,489),
    state 0x8, keycode 41 (keysym 0x66, f), same_screen YES,
    XLookupString gives 1 bytes: (66) "f"
    XmbLookupString gives 1 bytes: (66) "f"
    XFilterEvent returns: False

KeyRelease event, serial 32, synthetic NO, window 0x1000001,
    root 0xc0, subw 0x0, time 4128164, (85,488), root:(86,489),
    state 0x8, keycode 108 (keysym 0xffea, Alt_R), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 32, synthetic NO, window 0x1000001,
    root 0xc0, subw 0x0, time 4128203, (85,488), root:(86,489),
    state 0x0, keycode 41 (keysym 0x66, f), same_screen YES,
    XLookupString gives 1 bytes: (66) "f"
    XFilterEvent returns: False

所以现在的问题是,如果xmodmask说不是ALT_Rmod1为什么X报告ALT_R+f好像是?

答案1

仅当您使用不同的修饰符掩码时,Xmonad 才能执行此操作。在其源代码中提到了一个特殊情况,例如:

-- modMask lets you specify which modkey you want to use. The default
-- is mod1Mask ("left alt").  You may also consider using mod3Mask
-- ("right alt"), which does not conflict with emacs keybindings. The
-- "windows key" is usually mod4Mask.
--
myModMask       = mod1Mask

建议使用修饰符掩码,因为 X 中没有预定义的键修饰符包含alt(或者meta) 钥匙。这些包括转移,,控制— 和 5 个未指定的修饰键。除了(阅读源代码)Shift 和 Lock 之外,Xmonad 对这些键没有任何特殊了解。

所以你必须分配Alt_LAlt_R如果您希望它们在 Xmonad 中用于不同目的,请分隔修饰符掩码。

答案2

将+Xmonad视为+的原因是因为正在设置字段中的位,如问题中的输出所示。不知道正在按下的键,因为告诉它是用 按下的。ALT_RENTERmod1ENTERXmod1MaskstateKeyEventxevXmonadALT_RXENTERstate = mod1Mask

为什么X不尊重xmodmap是一个单独的问题,在这里问: 为什么 X 不以与 Mod1 不同的方式对待 ALT_L 和 ALT_R

相关内容