Hi,

being a ctwm user for exactly 20 years this month, I made myself a little
anniversary present digging further into ctwms not-so-well-known features.
Indeed, I stumbled over this by chance, but I like it so much that I though
it might be useful for other users, too.

So here's a little use case for ctwms "alternate context". I used to run xmms
for listening mp3s with my headphones when the familiy is sleeping, and I
lay myself on the couch, turn of the screen and blindly control volume and 
forward/backward only with the arrow keys.

That worked fine with xmms, but now that I had to switch to qmmp, it turned
out that qmmp inc/dec the volume by 5 (hard coded), and together with the
strange pulseaudio interference, the volume jumps up and down by more 
than 10%. No fine-grained control possible.

So I finally ended up with ctwm taking control over the arrow keys and
setting volume by my own commands whenever I use qmmp. Here's how to
do that:

### Begin

# start my "music mode" with f8:
"F8"  =  :all       : f.function "tft_xmms"

Function "tft_xmms" {
  # raise qmmp and give it the focus
  f.exec "HOME/bin/goto_qmmp"

  # turn off the screen
  f.exec "/usr/bin/tft off"

  # turn on alternativ key map
  f.altcontext
}

# Now define what certain keys should do in "alternate context"
# Note: any other key will leave the context
"Up"     = :alter               : f.function "up"
"Down"   = :alter               : f.function "down"
"Left"   = :alter               : f.function "left"
"Right"  = :alter               : f.function "right"

# turn screen on again. Note: this disables the alternate context as we 
# don't activate it again.
"F9"     = :alter               : f.exec "usr/bin/tft on"
# If we left alternate context already by some other keypress, we
# need the "normal" F9, too:
"F9"     = :all                 : f.exec "usr/bin/tft on"

# raise volume by 1, and VERY IMPORTANT: stay in the alternate context
Function "up" { f.exec "aumix -v +1" f.altcontext }
# Same for the other functions:
Function "down" { f.exec "aumix -v -1" f.altcontext }
Function "right" { f.exec "qmmp --seek-fwd 10" f.altcontext }
Function "left" { f.exec "qmmp --seek-bwd 10" f.altcontext }

### End

Thus, when I press F8 I get focus on the qmmp window and as long as
I only use the four arrow keys, I will always stay in the alternate
context, and ctwm will not send the keystrokes to qmmp but handle
them itself. The moment I press any other key, I'm back to the normal
mode.

Note that with f.altkeymap one can even define several keymaps and
explicitely chose which one to use.

I really like the idea of temporarily withdrawing control from a
program and letting ctwm handle certain keys, and I guess I will
find some other useful scenarios now that I stark thinking about it :-)

Have fun!
cu,
Frank





-- 
Dipl.-Inform. Frank Steiner   Web:  http://www.bio.ifi.lmu.de/~steiner/
Lehrstuhl f. Bioinformatik    Mail: http://www.bio.ifi.lmu.de/~steiner/m/
LMU, Amalienstr. 17           Phone: +49 89 2180-4049
80333 Muenchen, Germany       Fax:   +49 89 2180-99-4049
* Rekursion kann man erst verstehen, wenn man Rekursion verstanden hat. *

Reply via email to