Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extensible key map to configuration #248

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dopamane
Copy link

@dopamane dopamane commented Oct 13, 2024

Add keys map to TMConfig. #83

src/Termonad/Types.hs Outdated Show resolved Hide resolved
src/Termonad/Types.hs Outdated Show resolved Hide resolved
}

instance Show TMConfig where
show cfg = (show . options) cfg <> (show . hooks) cfg
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdepillabout Not sure about this. Let me know what you think. Is show used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in the Show instance of TMState'.

@dopamane
Copy link
Author

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

@KonstantinDjairo
Copy link

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
Copy link
Owner

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
Copy link
Owner

@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:

  • Keyboard shortcuts that are triggered by gtk menu actions (like copy and paste).
  • Keyboard shortcuts that aren't triggered by gtk menu actions (like the key map that is currently in this PR).

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".

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.

3 participants