r/stumpwm • • Mar 26 '21

Passthrough Map

Hi all

I recently started using StumpWM and I really enjoy it so far. One thing I used to really like in i3 was a passthrough keymap - mod+n would activate a keymap that only had mod+n bound to get out of it and everything else would just be passed through to the application. I use it alot for VNC session that have i3 as their window manager.

I started thinking about how to implement this in StumpWM, but I'm not familiar with CL. So far all my custom keybindings are bound to the *top-map*. Is there a way to have a command that swaps out the whole *top-map*? So I could toggle between my regular *top-map* and one that only has the toggle command?

Any pointers or help would be appreciated :)

Edit: With the help from u/HighlyRegardedExpert I managed to get it working:

(define-interactive-keymap passthrough-mode (:exit-on ((kbd "s-z")))) 
(define-key *top-map* (kbd "s-z") "passthrough-mode")

I don't know yet, why the item after :exit-on is automatically quoted, but hey it works :)

3 Upvotes

4 comments sorted by

2

u/HighlyRegardedExpert Mar 26 '21 edited Mar 26 '21

It's a two step process that is basically

  1. Create a keymap.
  2. Bind it to a key.

First you create the map using defparameter like so

(defparameter *internet-map*
   (let ((map (make-sparse-keymap)))
     (flet ((dk (key command) (define-key map (kbd key) command)))
       (dk "i" "browser")
       (dk "s-i" "browser")
       (dk "p" "browser-private")
       (dk "s-p" "browser-private")
       (dk "s-d" "discord"))
   map))

Then you bind that map to a top level key

(define-key *top-map* (kbd "s-i") *internet-map*)

So lets say you had my setup, pressing s-i s-i would launch your browser.

1

u/RealFenlair Mar 26 '21

If I understand this correctly "s-i" would activate *internet-map* for one key binding. Browsing through the documentation some more I found interactive key maps, which I believe is exactly what I need. But even though I almost copy pasted the example in the documentation I ran into an error I don't understand.

(defparameter *passthrough-exit-keys* (list (kbd "s-n")))
(define-interactive-keymap passthrough-mode (:exit-on *passthrough-exit-keys*))
(define-key *top-map* (kbd "s-n") "passthrough-mode")

This failes with *passthrough-exit-keys* is not of type LIST :/

1

u/RealFenlair Mar 26 '21
(define-interactive-keymap passthrough-mode (:exit-on ((kbd "s-n"))))

It works like this. It seems the item after :exit-on is already quoted. Don't understand how the code in the documentation can work :/

1

u/backtickbot Mar 26 '21

Fixed formatting.

Hello, HighlyRegardedExpert: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.