xmonad / xmonad-contrib

Contributed modules for xmonad
https://xmonad.org
BSD 3-Clause "New" or "Revised" License
589 stars 274 forks source link

EZConfig: add Modifier Keys' KeySyms to specialKeys in additionalKeysP #648

Closed ArtemSmaznov closed 2 years ago

ArtemSmaznov commented 2 years ago

Problem Description

additionalKeysP does not allow setting Modifier Keys (Alt_L, Alt_R, Shift_L, etc.) as KeySyms (i.e. setting keybindings with just modifier keys such as Shift+Alt for switching keyboard layouts)

This approach works fine with additionalKeys by appending xK_ like with all the other keys.

Steps to Reproduce

  1. Add this to additionalKeysP:
    , ("S-<Alt_L>", spawn "xterm"  )
  2. Recompile and Restart XMonad
  3. Press Shift + Left Alt
  4. xterm should open

If you add this to additionalKeys though, the keybinding works just fine and spawns the script:

    , ((shiftMask, xK_Alt_L), spawn "xterm"  )

Configuration File

Apologies for the incomplete config example. I am still very new to xmonad and having trouble understanding much of the config to be able to trim mine to a minimum working version.

module Main (main) where

import XMonad
import XMonad.Util.EZConfig

main :: IO ()
main = xmonad def 
    { ...
    } `additionalKeysP` myKeysP `additionalKeys` myKeys

-- This Doesn't Work
myKeysP =
    [ ("S-<Alt_L>", spawn "xterm"  ) -- Language Switching
    ]

-- This Works
myKeys =
   [ ((shiftMask, xK_Alt_R), spawn "xterm"  ) -- Language Switching
   ]

Checklist

Notes

I do not know yet how to compile xmonad-contrib myself to test this but it looks to me that adding these to specialKeys in EZConfig.hs is what is needed here (as well as to the commented out sections before that where, I assume, the documentation is built from).

I am not sure if this might have any unforeseen consequences that I am not seeing. And once again I am only guessing that this is all that is required for this functionality.

If someone can confirm that this is indeed how this works and that this should be safe to update I am happy to submit a PR

-- | A list of special key names and their corresponding KeySyms.
specialKeys :: [(String, KeySym)]
specialKeys = [ ("Backspace"  , xK_BackSpace)
+             , ("Shift_L"    , xK_Shift_L)
+             , ("Shift_R"    , xK_Shift_R)
+             , ("Caps_Lock"  , xK_Caps_Lock)
+             , ("Alt_L"      , xK_Alt_L)
+             , ("Alt_R"      , xK_Alt_R)
+             , ("Meta_L"     , xK_Meta_L)
+             , ("Control_L"  , xK_Control_L)
+             , ("Control_R"  , xK_Control_R)
+             , ("Num_Lock"   , xK_Num_Lock)
+             , ("Super_L"    , xK_Super_L)
+             , ("Super_R"    , xK_Super_R)
+             , ("Hyper_L"    , xK_Hyper_L)
              , ("Tab"        , xK_Tab)
              , ("Return"     , xK_Return)
              , ("Pause"      , xK_Pause)
              , ("Scroll_lock", xK_Scroll_Lock)
              , etc...
geekosaur commented 2 years ago

That should be it, yes, although I do wonder where xK_Meta_R and xK_Hyper_R ran off to.

ArtemSmaznov commented 2 years ago

Cool thanks I will submit a PR then tomorrow after work.

I got these from xmodmap output and I think they are missing for me as I only have one super key. Will include those 2 as well

geekosaur commented 2 years ago

Right, that would do it. I used /usr/include/X11/keysymdef.h which along with /usr/include/X11/XF86keysym.h is the master list of defined KeySyms.