cdepillabout / termonad

Terminal emulator configurable in Haskell.
https://hackage.haskell.org/package/termonad
BSD 3-Clause "New" or "Revised" License
401 stars 49 forks source link

Add extensible key map to configuration #248

Open dopamane opened 1 month ago

dopamane commented 1 month ago

Add keys map to TMConfig. #83

dopamane commented 1 month ago

I tested this out on my branch dev/dopamane/extensible-keys-toggle-theme, works great.

KonstantinDjairo commented 3 weeks ago

I tested this out on my branch dev/dopamane/extensible-keys-toggle-theme, works great.

can you add support for emacs-like keybindings? like we have in xmonad (example from my config)


myKeys =
  [ (otherModMasks ++ "M-" ++ key, action tag)
  | (tag, key) <- zip workspacen (words "1 2 3 4 5 6 7 8 9 0")
  , (otherModMasks, action) <-
      [ ("z-"  , windows . W.greedyView)
      , ("S-", windows . W.shift)
      , ("C-", windows .copy)
      ]
  ] ++
  [ ("M-d", spawn "rofi -show run")
  , ("M-s", spawn "bash -c dictpopup")
  , ("M-e", runOrRaise "goldendict" (className =? "GoldenDict-ng"))
  , ("M-p", runOrRaise "librewolf" (className =? "librewolf-default"))
  , ("M-S-g", easySwap)
  , ("M-S-c", spawnAndShift "ws8" "qbittorrent")
  , ("M-S-p", runOrRaise "nyxt" (className =? "Nyxt"))
  , ("M-t", withFocused $ windows . W.sink)  -- Toggle float for the focused window
  , ("M-`", runOrRaise "emacsclient -c" (className =? "Emacs"))
  , ("M-a", spawn "emacsclient -c")
  , ("M-S-q", return ())  -- Unbind Mod + Shift + Q, to avoid quiting the wm.
  , ("M-q", kill)  -- Change the keybinding for closing windows to Mod + Q
  , ("M-m", spawn "mpv  --idle")
  , ("M-S-d", spawn "~/.local/bin/recent_journal.py | popup")
  , ("M-r", runOrRaise "~/.local/bin/run_anki.sh" (className =? "Anki"))
  , ("M-g", runOrRaise "foliate" (className =? "com.github.johnfactotum.Foliate"))
  , ("M-S-f", sendToEmptyWorkspace)  -- View an empty workspace
  , ("M-f", viewEmptyWorkspace)  -- View an empty workspace
  , ("M-S-w", spawn "flameshot gui --path=/mnt/Data/mpv-screenshots/screenshots")
  , ("M-w", spawn "~/.local/bin/copy_image.sh")
  , ("M-S-b", spawn "kill -9 $(pgrep mpv)")
  , ("M-v", spawn "maim --select --hidecursor --format=png --quality 1 /tmp/manga/screenshot.png")
  ]
cdepillabout commented 2 weeks ago

can you add support for emacs-like keybindings? like we have in xmonad

Do you mean where you can make key bindings that require the user to press, for example, META and SHIFT at the same time as the key?

I believe the Key data type allows this:

data Key = Key
  { keyVal :: !Word32
  , keyMods :: !(Set ModifierType)
  } deriving (Eq, Ord, Show)

I think the ModifierType represents things like the control key, the shift key, the meta key, etc.

cdepillabout commented 2 weeks ago

@dopamane Sorry for taking a while to get to this.

I'm somewhat hesitant to introduce an extensible key map like this. I'd ideally like to expose an abstraction to the end-user like in:

Basically, right now Termonad has two types of keyboard shortcuts:

I'd ideally like to expose some sort of abstraction to end users to be able to configure and set both of these types of keyboard shortcuts.

This PR currently only allows setting keyboard shortcuts that aren't triggered by gtk menu actions, which means we'll have to have some sort of (breaking?) change when introducing a way to for users to also manipulate keyboard shortcuts that are triggered by gtk menu actions.

One thought I had was to potentially just do away with the keyboard shortcuts that aren't triggered by gtk menu actions. One positive(?) side effect of this is that all keyboard shortcuts will be much more discoverable within the UI, since all shortcut actions must be visible in the GTK menu. (Although this does feel unnecessarily limiting.)

On the other hand, not having any way to set keyboard bindings is pretty limiting, and quite surprising to anyone coming from XMonad. There have been multiple people asking for this. So maybe it is a good idea to try to come up with something, even if it isn't perfect. "Don't let perfect be the enemy of good".