Discussion:
rxvt-unicode's strange handling of function keys (with modifiers)
Daniel Hahler
2014-12-20 05:02:22 UTC
Permalink
Hello,

urxvt/rxvt-unicode has a strange method of handling function keys.

It defines kf1=\E[11~ to kf20=\E[34~ in its terminfo, but only has a concept
of 10 function keys (kf1 to kf10), and then uses kf11 to kf20 for the
shifted variants.

For F11/F12 it sends the same code as for Shift-F1/F2.

I've used to use a hack, which makes URXvt behave like xterm, by
defining all the special keybindings
(http://www.netswarm.net/misc/urxvt-xtermcompat.txt), but that then also
requires to set TERM to xterm-*, which has other drawbacks and felt too
much of a hack.

I've tried to address this in tty-keys.c, without being sure what should
get done about the conflicts (Shift-F1 vs. F11), but then it did not
work properly with the "xterm-keys" option anyway, which probably uses the
common concept of 12 function keys, too?!

I think it would be nice if F11/F12 could be ignored with rxvt-unicode
by default.

diff --git i/tty-keys.c w/tty-keys.c
index a987c44..60344d1 100644
--- i/tty-keys.c
+++ w/tty-keys.c
@@ -120,16 +120,19 @@ const struct tty_default_key_raw tty_default_raw_keys[] = {
{ "\033[6^", KEYC_NPAGE|KEYC_CTRL },
{ "\033[5^", KEYC_PPAGE|KEYC_CTRL },

- { "\033[11$", KEYC_F1|KEYC_SHIFT },
- { "\033[12$", KEYC_F2|KEYC_SHIFT },
- { "\033[13$", KEYC_F3|KEYC_SHIFT },
- { "\033[14$", KEYC_F4|KEYC_SHIFT },
- { "\033[15$", KEYC_F5|KEYC_SHIFT },
- { "\033[17$", KEYC_F6|KEYC_SHIFT },
- { "\033[18$", KEYC_F7|KEYC_SHIFT },
- { "\033[19$", KEYC_F8|KEYC_SHIFT },
- { "\033[20$", KEYC_F9|KEYC_SHIFT },
- { "\033[21$", KEYC_F10|KEYC_SHIFT },
+ /* rxvt-unicode only has 10 function keys.
+ * Shift-f1 to shift-f10 are kf11 to kf20 from terminfo.
+ * F11/F12 send the same code as Shift-F1/Shift-F12. */
+ { "\033[23~", KEYC_F1|KEYC_SHIFT },
+ { "\033[24~", KEYC_F2|KEYC_SHIFT },
+ { "\033[25~", KEYC_F3|KEYC_SHIFT },
+ { "\033[26~", KEYC_F4|KEYC_SHIFT },
+ { "\033[28~", KEYC_F5|KEYC_SHIFT },
+ { "\033[29~", KEYC_F6|KEYC_SHIFT },
+ { "\033[31~", KEYC_F7|KEYC_SHIFT },
+ { "\033[32~", KEYC_F8|KEYC_SHIFT },
+ { "\033[33~", KEYC_F9|KEYC_SHIFT },
+ { "\033[34~", KEYC_F10|KEYC_SHIFT },
{ "\033[23$", KEYC_F11|KEYC_SHIFT },
{ "\033[24$", KEYC_F12|KEYC_SHIFT },
{ "\033[2$", KEYC_IC|KEYC_SHIFT },
@@ -139,16 +142,16 @@ const struct tty_default_key_raw tty_default_raw_keys[] = {
{ "\033[6$", KEYC_NPAGE|KEYC_SHIFT },
{ "\033[5$", KEYC_PPAGE|KEYC_SHIFT },

- { "\033[11@", KEYC_F1|KEYC_CTRL|KEYC_SHIFT },
- { "\033[12@", KEYC_F2|KEYC_CTRL|KEYC_SHIFT },
- { "\033[13@", KEYC_F3|KEYC_CTRL|KEYC_SHIFT },
- { "\033[14@", KEYC_F4|KEYC_CTRL|KEYC_SHIFT },
- { "\033[15@", KEYC_F5|KEYC_CTRL|KEYC_SHIFT },
- { "\033[17@", KEYC_F6|KEYC_CTRL|KEYC_SHIFT },
- { "\033[18@", KEYC_F7|KEYC_CTRL|KEYC_SHIFT },
- { "\033[19@", KEYC_F8|KEYC_CTRL|KEYC_SHIFT },
- { "\033[20@", KEYC_F9|KEYC_CTRL|KEYC_SHIFT },
- { "\033[21@", KEYC_F10|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[23^", KEYC_F1|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[24^", KEYC_F2|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[25^", KEYC_F3|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[26^", KEYC_F4|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[28^", KEYC_F5|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[29^", KEYC_F6|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[31^", KEYC_F7|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[32^", KEYC_F8|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[33^", KEYC_F9|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[34^", KEYC_F10|KEYC_CTRL|KEYC_SHIFT },
{ "\033[23@", KEYC_F11|KEYC_CTRL|KEYC_SHIFT },
{ "\033[24@", KEYC_F12|KEYC_CTRL|KEYC_SHIFT },
{ "\033[2@", KEYC_IC|KEYC_CTRL|KEYC_SHIFT },

This can probably also get addressed using terminal-overrides probably,
and instead of changing the code, it could have a default for
rxvt(-unicode) then.


btw: the last commit changing code in this area was the following.
I've not managed to trigger the `KEYC_F<X>|KEYC_SHIFT` cases therein.
Is the code correct?
Shouldn't it at least define all the shifted variants?

commit 2056a9ef9e91996c294b5db0a3d01ed415e95e56
Author: nicm <nicm>
Date: Mon Jul 21 10:25:48 2014 +0000

Drop explicit support for F13-F20 and change to match the xterm terminfo
entry:

F13-F24 are S-F1 to S-F12
F25-F36 are C-F1 to C-F12
F37-F48 are C-S-F1 to C-S-F12
F49-F60 are M-F1 to M-F12
and F61-F63 are M-S-F1 to M-S-F3

This should be no difference for applications inside tmux, but means
that any key binding for F13 will need to be replaced by S-F1 and so on.

diff --git a/input-keys.c b/input-keys.c
index 24566df..c75e28d 100644
--- a/input-keys.c
+++ b/input-keys.c
@@ -57,14 +57,14 @@ const struct input_key_ent input_keys[] = {
{ KEYC_F10, "\033[21~", 0 },
{ KEYC_F11, "\033[23~", 0 },
{ KEYC_F12, "\033[24~", 0 },
- { KEYC_F13, "\033[25~", 0 },
- { KEYC_F14, "\033[26~", 0 },
- { KEYC_F15, "\033[28~", 0 },
- { KEYC_F16, "\033[29~", 0 },
- { KEYC_F17, "\033[31~", 0 },
- { KEYC_F18, "\033[32~", 0 },
- { KEYC_F19, "\033[33~", 0 },
- { KEYC_F20, "\033[34~", 0 },
+ { KEYC_F1|KEYC_SHIFT, "\033[25~", 0 },
+ { KEYC_F2|KEYC_SHIFT, "\033[26~", 0 },
+ { KEYC_F3|KEYC_SHIFT, "\033[28~", 0 },
+ { KEYC_F4|KEYC_SHIFT, "\033[29~", 0 },
+ { KEYC_F5|KEYC_SHIFT, "\033[31~", 0 },
+ { KEYC_F6|KEYC_SHIFT, "\033[32~", 0 },
+ { KEYC_F7|KEYC_SHIFT, "\033[33~", 0 },
+ { KEYC_F8|KEYC_SHIFT, "\033[34~", 0 },
{ KEYC_IC, "\033[2~", 0 },
{ KEYC_DC, "\033[3~", 0 },


Thanks,
Daniel.
--
http://daniel.hahler.de/
Nicholas Marriott
2014-12-21 11:09:23 UTC
Permalink
Your mailer has mangled this patch, please send it as an attachment.
Post by Daniel Hahler
Hello,
urxvt/rxvt-unicode has a strange method of handling function keys.
It defines kf1=\E[11~ to kf20=\E[34~ in its terminfo, but only has a concept
of 10 function keys (kf1 to kf10), and then uses kf11 to kf20 for the
shifted variants.
For F11/F12 it sends the same code as for Shift-F1/F2.
I've used to use a hack, which makes URXvt behave like xterm, by
defining all the special keybindings
(http://www.netswarm.net/misc/urxvt-xtermcompat.txt), but that then also
requires to set TERM to xterm-*, which has other drawbacks and felt too
much of a hack.
I've tried to address this in tty-keys.c, without being sure what should
get done about the conflicts (Shift-F1 vs. F11), but then it did not
work properly with the "xterm-keys" option anyway, which probably uses the
common concept of 12 function keys, too?!
I think it would be nice if F11/F12 could be ignored with rxvt-unicode
by default.
diff --git i/tty-keys.c w/tty-keys.c
index a987c44..60344d1 100644
--- i/tty-keys.c
+++ w/tty-keys.c
@@ -120,16 +120,19 @@ const struct tty_default_key_raw tty_default_raw_keys[] = {
{ "\033[6^", KEYC_NPAGE|KEYC_CTRL },
{ "\033[5^", KEYC_PPAGE|KEYC_CTRL },
- { "\033[11$", KEYC_F1|KEYC_SHIFT },
- { "\033[12$", KEYC_F2|KEYC_SHIFT },
- { "\033[13$", KEYC_F3|KEYC_SHIFT },
- { "\033[14$", KEYC_F4|KEYC_SHIFT },
- { "\033[15$", KEYC_F5|KEYC_SHIFT },
- { "\033[17$", KEYC_F6|KEYC_SHIFT },
- { "\033[18$", KEYC_F7|KEYC_SHIFT },
- { "\033[19$", KEYC_F8|KEYC_SHIFT },
- { "\033[20$", KEYC_F9|KEYC_SHIFT },
- { "\033[21$", KEYC_F10|KEYC_SHIFT },
+ /* rxvt-unicode only has 10 function keys.
+ * Shift-f1 to shift-f10 are kf11 to kf20 from terminfo.
+ * F11/F12 send the same code as Shift-F1/Shift-F12. */
+ { "\033[23~", KEYC_F1|KEYC_SHIFT },
+ { "\033[24~", KEYC_F2|KEYC_SHIFT },
+ { "\033[25~", KEYC_F3|KEYC_SHIFT },
+ { "\033[26~", KEYC_F4|KEYC_SHIFT },
+ { "\033[28~", KEYC_F5|KEYC_SHIFT },
+ { "\033[29~", KEYC_F6|KEYC_SHIFT },
+ { "\033[31~", KEYC_F7|KEYC_SHIFT },
+ { "\033[32~", KEYC_F8|KEYC_SHIFT },
+ { "\033[33~", KEYC_F9|KEYC_SHIFT },
+ { "\033[34~", KEYC_F10|KEYC_SHIFT },
{ "\033[23$", KEYC_F11|KEYC_SHIFT },
{ "\033[24$", KEYC_F12|KEYC_SHIFT },
{ "\033[2$", KEYC_IC|KEYC_SHIFT },
@@ -139,16 +142,16 @@ const struct tty_default_key_raw tty_default_raw_keys[] = {
{ "\033[6$", KEYC_NPAGE|KEYC_SHIFT },
{ "\033[5$", KEYC_PPAGE|KEYC_SHIFT },
+ { "\033[23^", KEYC_F1|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[24^", KEYC_F2|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[25^", KEYC_F3|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[26^", KEYC_F4|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[28^", KEYC_F5|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[29^", KEYC_F6|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[31^", KEYC_F7|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[32^", KEYC_F8|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[33^", KEYC_F9|KEYC_CTRL|KEYC_SHIFT },
+ { "\033[34^", KEYC_F10|KEYC_CTRL|KEYC_SHIFT },
This can probably also get addressed using terminal-overrides probably,
and instead of changing the code, it could have a default for
rxvt(-unicode) then.
btw: the last commit changing code in this area was the following.
I've not managed to trigger the `KEYC_F<X>|KEYC_SHIFT` cases therein.
Is the code correct?
Shouldn't it at least define all the shifted variants?
commit 2056a9ef9e91996c294b5db0a3d01ed415e95e56
Author: nicm <nicm>
Date: Mon Jul 21 10:25:48 2014 +0000
Drop explicit support for F13-F20 and change to match the xterm terminfo
F13-F24 are S-F1 to S-F12
F25-F36 are C-F1 to C-F12
F37-F48 are C-S-F1 to C-S-F12
F49-F60 are M-F1 to M-F12
and F61-F63 are M-S-F1 to M-S-F3
This should be no difference for applications inside tmux, but means
that any key binding for F13 will need to be replaced by S-F1 and so on.
diff --git a/input-keys.c b/input-keys.c
index 24566df..c75e28d 100644
--- a/input-keys.c
+++ b/input-keys.c
@@ -57,14 +57,14 @@ const struct input_key_ent input_keys[] = {
{ KEYC_F10, "\033[21~", 0 },
{ KEYC_F11, "\033[23~", 0 },
{ KEYC_F12, "\033[24~", 0 },
- { KEYC_F13, "\033[25~", 0 },
- { KEYC_F14, "\033[26~", 0 },
- { KEYC_F15, "\033[28~", 0 },
- { KEYC_F16, "\033[29~", 0 },
- { KEYC_F17, "\033[31~", 0 },
- { KEYC_F18, "\033[32~", 0 },
- { KEYC_F19, "\033[33~", 0 },
- { KEYC_F20, "\033[34~", 0 },
+ { KEYC_F1|KEYC_SHIFT, "\033[25~", 0 },
+ { KEYC_F2|KEYC_SHIFT, "\033[26~", 0 },
+ { KEYC_F3|KEYC_SHIFT, "\033[28~", 0 },
+ { KEYC_F4|KEYC_SHIFT, "\033[29~", 0 },
+ { KEYC_F5|KEYC_SHIFT, "\033[31~", 0 },
+ { KEYC_F6|KEYC_SHIFT, "\033[32~", 0 },
+ { KEYC_F7|KEYC_SHIFT, "\033[33~", 0 },
+ { KEYC_F8|KEYC_SHIFT, "\033[34~", 0 },
{ KEYC_IC, "\033[2~", 0 },
{ KEYC_DC, "\033[3~", 0 },
Thanks,
Daniel.
--
http://daniel.hahler.de/
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
https://lists.sourceforge.net/lists/listinfo/tmux-users
Loading...