aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2022-02-15 16:41:19 +0000
committerMichael Brown <mcb30@ipxe.org>2022-02-15 16:46:58 +0000
commit419b2e71da689ded944c3789c87b7ae3646c7a7c (patch)
treef4010535ce5b80d1d556ec97822ec10268573c7b
parent4a37b050081cbb9ea384a203502eca09a2d8038c (diff)
downloadipxe-419b2e71da689ded944c3789c87b7ae3646c7a7c.zip
ipxe-419b2e71da689ded944c3789c87b7ae3646c7a7c.tar.gz
ipxe-419b2e71da689ded944c3789c87b7ae3646c7a7c.tar.bz2
[console] Fix definition of unreachability for remapped keys
The AltGr remapping table is constructed to include only keys that are not reachable after applying the basic remapping table. The logic currently fails to include keys that are omitted entirely from the basic remapping table since they would map to a non-ASCII character. Fix this logic by allowing the remapping tables to include null mappings, which are then elided only at the point of constructing the C code fragment. Reported-by: Christian Nilsson <nikize@gmail.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/hci/keymap/keymap_al.c5
-rw-r--r--src/hci/keymap/keymap_cf.c1
-rw-r--r--src/hci/keymap/keymap_cz.c8
-rw-r--r--src/hci/keymap/keymap_de.c5
-rw-r--r--src/hci/keymap/keymap_dk.c7
-rw-r--r--src/hci/keymap/keymap_es.c13
-rw-r--r--src/hci/keymap/keymap_et.c10
-rw-r--r--src/hci/keymap/keymap_fi.c6
-rw-r--r--src/hci/keymap/keymap_fr.c6
-rw-r--r--src/hci/keymap/keymap_hu.c18
-rw-r--r--src/hci/keymap/keymap_it.c6
-rw-r--r--src/hci/keymap/keymap_lt.c4
-rw-r--r--src/hci/keymap/keymap_mt.c5
-rw-r--r--src/hci/keymap/keymap_no-latin1.c5
-rw-r--r--src/hci/keymap/keymap_no.c7
-rw-r--r--src/hci/keymap/keymap_pt.c1
-rw-r--r--src/hci/keymap/keymap_se.c5
-rw-r--r--src/hci/keymap/keymap_sg.c2
-rwxr-xr-xsrc/util/genkeymap.py46
19 files changed, 137 insertions, 23 deletions
diff --git a/src/hci/keymap/keymap_al.c b/src/hci/keymap/keymap_al.c
index 4d27917..6e14395 100644
--- a/src/hci/keymap/keymap_al.c
+++ b/src/hci/keymap/keymap_al.c
@@ -37,10 +37,15 @@ static struct keymap_key al_basic[] = {
/** "al" AltGr remapping */
static struct keymap_key al_altgr[] = {
+ { 0x21, 0x7e }, /* '!' => '~' */
+ { 0x26, 0x60 }, /* '&' => '`' */
{ 0x30, 0x7e }, /* '0' => '~' */
{ 0x31, 0x7e }, /* '1' => '~' */
{ 0x34, 0x7e }, /* '4' => '~' */
{ 0x37, 0x60 }, /* '7' => '`' */
+ { 0x3a, 0x7e }, /* ':' => '~' */
+ { 0x56, 0x60 }, /* 'V' => '`' */
+ { 0x7c, 0x7e }, /* '|' => '~' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_cf.c b/src/hci/keymap/keymap_cf.c
index 434e338..55bbfc1 100644
--- a/src/hci/keymap/keymap_cf.c
+++ b/src/hci/keymap/keymap_cf.c
@@ -33,6 +33,7 @@ static struct keymap_key cf_altgr[] = {
{ 0x27, 0x7b }, /* '\'' => '{' */
{ 0x32, 0x40 }, /* '2' => '@' */
{ 0x3b, 0x7e }, /* ';' => '~' */
+ { 0x5c, 0x7d }, /* '\\' => '}' */
{ 0x60, 0x5c }, /* '`' => '\\' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_cz.c b/src/hci/keymap/keymap_cz.c
index fb072b1..08e9638 100644
--- a/src/hci/keymap/keymap_cz.c
+++ b/src/hci/keymap/keymap_cz.c
@@ -50,6 +50,9 @@ static struct keymap_key cz_basic[] = {
/** "cz" AltGr remapping */
static struct keymap_key cz_altgr[] = {
+ { 0x21, 0x7e }, /* '!' => '~' */
+ { 0x24, 0x7e }, /* '$' => '~' */
+ { 0x29, 0x7e }, /* ')' => '~' */
{ 0x2c, 0x3c }, /* ',' => '<' */
{ 0x2e, 0x3e }, /* '.' => '>' */
{ 0x2f, 0x2a }, /* '/' => '*' */
@@ -60,10 +63,15 @@ static struct keymap_key cz_altgr[] = {
{ 0x37, 0x26 }, /* '7' => '&' */
{ 0x38, 0x2a }, /* '8' => '*' */
{ 0x39, 0x7b }, /* '9' => '{' */
+ { 0x3a, 0x7e }, /* ':' => '~' */
{ 0x3b, 0x24 }, /* ';' => '$' */
+ { 0x4b, 0x26 }, /* 'K' => '&' */
+ { 0x58, 0x3e }, /* 'X' => '>' */
+ { 0x5a, 0x3c }, /* 'Z' => '<' */
{ 0x61, 0x7e }, /* 'a' => '~' */
{ 0x62, 0x7b }, /* 'b' => '{' */
{ 0x63, 0x26 }, /* 'c' => '&' */
+ { 0x66, 0x5b }, /* 'f' => '[' */
{ 0x67, 0x5d }, /* 'g' => ']' */
{ 0x6e, 0x7d }, /* 'n' => '}' */
{ 0x76, 0x40 }, /* 'v' => '@' */
diff --git a/src/hci/keymap/keymap_de.c b/src/hci/keymap/keymap_de.c
index bbd3952..ca5e4a9 100644
--- a/src/hci/keymap/keymap_de.c
+++ b/src/hci/keymap/keymap_de.c
@@ -47,8 +47,13 @@ static struct keymap_key de_basic[] = {
static struct keymap_key de_altgr[] = {
{ 0x2d, 0x5c }, /* '-' => '\\' */
{ 0x30, 0x7d }, /* '0' => '}' */
+ { 0x37, 0x7b }, /* '7' => '{' */
+ { 0x38, 0x5b }, /* '8' => '[' */
{ 0x39, 0x5d }, /* '9' => ']' */
+ { 0x3b, 0x7e }, /* ';' => '~' */
+ { 0x5d, 0x7e }, /* ']' => '~' */
{ 0x71, 0x40 }, /* 'q' => '@' */
+ { 0x7c, 0x7e }, /* '|' => '~' */
{ 0xdc, 0x7c }, /* Pseudo-'\\' => '|' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_dk.c b/src/hci/keymap/keymap_dk.c
index 6d2e60a..5b22902 100644
--- a/src/hci/keymap/keymap_dk.c
+++ b/src/hci/keymap/keymap_dk.c
@@ -39,7 +39,14 @@ static struct keymap_key dk_basic[] = {
static struct keymap_key dk_altgr[] = {
{ 0x30, 0x7d }, /* '0' => '}' */
{ 0x32, 0x40 }, /* '2' => '@' */
+ { 0x34, 0x24 }, /* '4' => '$' */
+ { 0x37, 0x7b }, /* '7' => '{' */
+ { 0x38, 0x5b }, /* '8' => '[' */
+ { 0x39, 0x5d }, /* '9' => ']' */
+ { 0x3a, 0x7e }, /* ':' => '~' */
{ 0x3d, 0x7c }, /* '=' => '|' */
+ { 0x5c, 0x7e }, /* '\\' => '~' */
+ { 0x5d, 0x7e }, /* ']' => '~' */
{ 0x71, 0x40 }, /* 'q' => '@' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_es.c b/src/hci/keymap/keymap_es.c
index 614ca7b..93d87f2 100644
--- a/src/hci/keymap/keymap_es.c
+++ b/src/hci/keymap/keymap_es.c
@@ -37,14 +37,27 @@ static struct keymap_key es_basic[] = {
/** "es" AltGr remapping */
static struct keymap_key es_altgr[] = {
+ { 0x22, 0x7b }, /* '"' => '{' */
{ 0x27, 0x7b }, /* '\'' => '{' */
+ { 0x2b, 0x7e }, /* '+' => '~' */
+ { 0x2d, 0x5c }, /* '-' => '\\' */
{ 0x30, 0x7d }, /* '0' => '}' */
+ { 0x31, 0x7c }, /* '1' => '|' */
{ 0x32, 0x40 }, /* '2' => '@' */
+ { 0x33, 0x23 }, /* '3' => '#' */
+ { 0x34, 0x7e }, /* '4' => '~' */
{ 0x37, 0x7b }, /* '7' => '{' */
{ 0x38, 0x5b }, /* '8' => '[' */
{ 0x39, 0x5d }, /* '9' => ']' */
+ { 0x3a, 0x7e }, /* ':' => '~' */
+ { 0x3b, 0x7e }, /* ';' => '~' */
+ { 0x3d, 0x7e }, /* '=' => '~' */
{ 0x5c, 0x7d }, /* '\\' => '}' */
+ { 0x60, 0x5c }, /* '`' => '\\' */
{ 0x71, 0x40 }, /* 'q' => '@' */
+ { 0x7c, 0x7e }, /* '|' => '~' */
+ { 0x7e, 0x5c }, /* '~' => '\\' */
+ { 0xdc, 0x7c }, /* Pseudo-'\\' => '|' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_et.c b/src/hci/keymap/keymap_et.c
index f3eb02e..4d76326 100644
--- a/src/hci/keymap/keymap_et.c
+++ b/src/hci/keymap/keymap_et.c
@@ -35,8 +35,18 @@ static struct keymap_key et_basic[] = {
/** "et" AltGr remapping */
static struct keymap_key et_altgr[] = {
+ { 0x26, 0x7b }, /* '&' => '{' */
+ { 0x28, 0x5d }, /* '(' => ']' */
+ { 0x29, 0x7d }, /* ')' => '}' */
+ { 0x2a, 0x5b }, /* '*' => '[' */
{ 0x2d, 0x5c }, /* '-' => '\\' */
+ { 0x30, 0x7d }, /* '0' => '}' */
{ 0x32, 0x40 }, /* '2' => '@' */
+ { 0x34, 0x24 }, /* '4' => '$' */
+ { 0x37, 0x7b }, /* '7' => '{' */
+ { 0x38, 0x5b }, /* '8' => '[' */
+ { 0x39, 0x5d }, /* '9' => ']' */
+ { 0x5f, 0x5c }, /* '_' => '\\' */
{ 0xdc, 0x7c }, /* Pseudo-'\\' => '|' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_fi.c b/src/hci/keymap/keymap_fi.c
index 622f062..ac69813 100644
--- a/src/hci/keymap/keymap_fi.c
+++ b/src/hci/keymap/keymap_fi.c
@@ -38,6 +38,12 @@ static struct keymap_key fi_altgr[] = {
{ 0x2d, 0x5c }, /* '-' => '\\' */
{ 0x30, 0x7d }, /* '0' => '}' */
{ 0x32, 0x40 }, /* '2' => '@' */
+ { 0x34, 0x24 }, /* '4' => '$' */
+ { 0x37, 0x7b }, /* '7' => '{' */
+ { 0x38, 0x5b }, /* '8' => '[' */
+ { 0x39, 0x5d }, /* '9' => ']' */
+ { 0x49, 0x7c }, /* 'I' => '|' */
+ { 0x5d, 0x7e }, /* ']' => '~' */
{ 0xdc, 0x7c }, /* Pseudo-'\\' => '|' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_fr.c b/src/hci/keymap/keymap_fr.c
index c002bf9..ad797f8 100644
--- a/src/hci/keymap/keymap_fr.c
+++ b/src/hci/keymap/keymap_fr.c
@@ -68,9 +68,15 @@ static struct keymap_key fr_altgr[] = {
{ 0x2d, 0x5d }, /* '-' => ']' */
{ 0x30, 0x40 }, /* '0' => '@' */
{ 0x33, 0x23 }, /* '3' => '#' */
+ { 0x34, 0x7b }, /* '4' => '{' */
{ 0x35, 0x5b }, /* '5' => '[' */
+ { 0x36, 0x7c }, /* '6' => '|' */
+ { 0x37, 0x60 }, /* '7' => '`' */
{ 0x38, 0x5c }, /* '8' => '\\' */
+ { 0x3d, 0x7d }, /* '=' => '}' */
+ { 0x5c, 0x60 }, /* '\\' => '`' */
{ 0x61, 0x40 }, /* 'a' => '@' */
+ { 0xdc, 0x7c }, /* Pseudo-'\\' => '|' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_hu.c b/src/hci/keymap/keymap_hu.c
index 8f2d70a..d64baae 100644
--- a/src/hci/keymap/keymap_hu.c
+++ b/src/hci/keymap/keymap_hu.c
@@ -37,18 +37,36 @@ static struct keymap_key hu_basic[] = {
/** "hu" AltGr remapping */
static struct keymap_key hu_altgr[] = {
+ { 0x21, 0x7e }, /* '!' => '~' */
+ { 0x23, 0x5e }, /* '#' => '^' */
+ { 0x26, 0x60 }, /* '&' => '`' */
+ { 0x2c, 0x3b }, /* ',' => ';' */
{ 0x2e, 0x3e }, /* '.' => '>' */
{ 0x2f, 0x2a }, /* '/' => '*' */
+ { 0x30, 0x7e }, /* '0' => '~' */
+ { 0x31, 0x7e }, /* '1' => '~' */
{ 0x32, 0x5e }, /* '2' => '^' */
{ 0x33, 0x5e }, /* '3' => '^' */
+ { 0x34, 0x7e }, /* '4' => '~' */
{ 0x37, 0x60 }, /* '7' => '`' */
{ 0x3b, 0x24 }, /* ';' => '$' */
+ { 0x4b, 0x26 }, /* 'K' => '&' */
+ { 0x58, 0x3e }, /* 'X' => '>' */
+ { 0x5a, 0x3c }, /* 'Z' => '<' */
+ { 0x62, 0x7b }, /* 'b' => '{' */
{ 0x63, 0x26 }, /* 'c' => '&' */
+ { 0x66, 0x5b }, /* 'f' => '[' */
+ { 0x67, 0x5d }, /* 'g' => ']' */
{ 0x6d, 0x3c }, /* 'm' => '<' */
+ { 0x6e, 0x7d }, /* 'n' => '}' */
+ { 0x71, 0x5c }, /* 'q' => '\\' */
{ 0x76, 0x40 }, /* 'v' => '@' */
+ { 0x77, 0x7c }, /* 'w' => '|' */
{ 0x78, 0x23 }, /* 'x' => '#' */
{ 0x7a, 0x3e }, /* 'z' => '>' */
+ { 0x7c, 0x7e }, /* '|' => '~' */
{ 0xdc, 0x3c }, /* Pseudo-'\\' => '<' */
+ { 0xfc, 0x3e }, /* Pseudo-'|' => '>' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_it.c b/src/hci/keymap/keymap_it.c
index a55dafe..2511bb7 100644
--- a/src/hci/keymap/keymap_it.c
+++ b/src/hci/keymap/keymap_it.c
@@ -37,13 +37,19 @@ static struct keymap_key it_basic[] = {
/** "it" AltGr remapping */
static struct keymap_key it_altgr[] = {
+ { 0x23, 0x7e }, /* '#' => '~' */
+ { 0x27, 0x23 }, /* '\'' => '#' */
{ 0x2d, 0x60 }, /* '-' => '`' */
{ 0x30, 0x7d }, /* '0' => '}' */
+ { 0x37, 0x7b }, /* '7' => '{' */
+ { 0x38, 0x5b }, /* '8' => '[' */
{ 0x39, 0x5d }, /* '9' => ']' */
{ 0x3b, 0x40 }, /* ';' => '@' */
{ 0x3d, 0x7e }, /* '=' => '~' */
+ { 0x40, 0x7e }, /* '@' => '~' */
{ 0x5c, 0x60 }, /* '\\' => '`' */
{ 0x71, 0x40 }, /* 'q' => '@' */
+ { 0x7c, 0x7e }, /* '|' => '~' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_lt.c b/src/hci/keymap/keymap_lt.c
index 5d6ee5a..a237b1d 100644
--- a/src/hci/keymap/keymap_lt.c
+++ b/src/hci/keymap/keymap_lt.c
@@ -17,6 +17,10 @@ static struct keymap_key lt_basic[] = {
/** "lt" AltGr remapping */
static struct keymap_key lt_altgr[] = {
+ { 0x22, 0x5e }, /* '"' => '^' */
+ { 0x27, 0x5e }, /* '\'' => '^' */
+ { 0x4b, 0x26 }, /* 'K' => '&' */
+ { 0x71, 0x40 }, /* 'q' => '@' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_mt.c b/src/hci/keymap/keymap_mt.c
index 0a9a110..a95c5b4 100644
--- a/src/hci/keymap/keymap_mt.c
+++ b/src/hci/keymap/keymap_mt.c
@@ -22,6 +22,11 @@ static struct keymap_key mt_basic[] = {
/** "mt" AltGr remapping */
static struct keymap_key mt_altgr[] = {
+ { 0x30, 0x7d }, /* '0' => '}' */
+ { 0x37, 0x7b }, /* '7' => '{' */
+ { 0x38, 0x5b }, /* '8' => '[' */
+ { 0x39, 0x5d }, /* '9' => ']' */
+ { 0x5c, 0x60 }, /* '\\' => '`' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_no-latin1.c b/src/hci/keymap/keymap_no-latin1.c
index 63fe855..1f4cc38 100644
--- a/src/hci/keymap/keymap_no-latin1.c
+++ b/src/hci/keymap/keymap_no-latin1.c
@@ -39,10 +39,15 @@ static struct keymap_key no_latin1_basic[] = {
/** "no-latin1" AltGr remapping */
static struct keymap_key no_latin1_altgr[] = {
+ { 0x22, 0x5b }, /* '"' => '[' */
+ { 0x27, 0x7b }, /* '\'' => '{' */
{ 0x30, 0x7d }, /* '0' => '}' */
{ 0x32, 0x40 }, /* '2' => '@' */
+ { 0x37, 0x7b }, /* '7' => '{' */
+ { 0x38, 0x5b }, /* '8' => '[' */
{ 0x39, 0x5d }, /* '9' => ']' */
{ 0x5b, 0x7d }, /* '[' => '}' */
+ { 0x7b, 0x5d }, /* '{' => ']' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_no.c b/src/hci/keymap/keymap_no.c
index 4b2f726..239e3ae 100644
--- a/src/hci/keymap/keymap_no.c
+++ b/src/hci/keymap/keymap_no.c
@@ -41,6 +41,13 @@ static struct keymap_key no_basic[] = {
static struct keymap_key no_altgr[] = {
{ 0x30, 0x7d }, /* '0' => '}' */
{ 0x32, 0x40 }, /* '2' => '@' */
+ { 0x34, 0x24 }, /* '4' => '$' */
+ { 0x37, 0x7b }, /* '7' => '{' */
+ { 0x38, 0x5b }, /* '8' => '[' */
+ { 0x39, 0x5d }, /* '9' => ']' */
+ { 0x3a, 0x7e }, /* ':' => '~' */
+ { 0x5c, 0x7e }, /* '\\' => '~' */
+ { 0x5d, 0x7e }, /* ']' => '~' */
{ 0x71, 0x40 }, /* 'q' => '@' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_pt.c b/src/hci/keymap/keymap_pt.c
index f294e95..75bf565 100644
--- a/src/hci/keymap/keymap_pt.c
+++ b/src/hci/keymap/keymap_pt.c
@@ -44,6 +44,7 @@ static struct keymap_key pt_altgr[] = {
{ 0x32, 0x40 }, /* '2' => '@' */
{ 0x37, 0x7b }, /* '7' => '{' */
{ 0x38, 0x5b }, /* '8' => '[' */
+ { 0x39, 0x5d }, /* '9' => ']' */
{ 0x71, 0x40 }, /* 'q' => '@' */
{ 0, 0 }
};
diff --git a/src/hci/keymap/keymap_se.c b/src/hci/keymap/keymap_se.c
index 6ca9904..9c6cf64 100644
--- a/src/hci/keymap/keymap_se.c
+++ b/src/hci/keymap/keymap_se.c
@@ -40,6 +40,11 @@ static struct keymap_key se_altgr[] = {
{ 0x2d, 0x5c }, /* '-' => '\\' */
{ 0x30, 0x7d }, /* '0' => '}' */
{ 0x32, 0x40 }, /* '2' => '@' */
+ { 0x34, 0x24 }, /* '4' => '$' */
+ { 0x37, 0x7b }, /* '7' => '{' */
+ { 0x38, 0x5b }, /* '8' => '[' */
+ { 0x39, 0x5d }, /* '9' => ']' */
+ { 0x5d, 0x7e }, /* ']' => '~' */
{ 0x71, 0x40 }, /* 'q' => '@' */
{ 0xdc, 0x7c }, /* Pseudo-'\\' => '|' */
{ 0, 0 }
diff --git a/src/hci/keymap/keymap_sg.c b/src/hci/keymap/keymap_sg.c
index 9a6db9c..2afe59c 100644
--- a/src/hci/keymap/keymap_sg.c
+++ b/src/hci/keymap/keymap_sg.c
@@ -45,9 +45,11 @@ static struct keymap_key sg_basic[] = {
/** "sg" AltGr remapping */
static struct keymap_key sg_altgr[] = {
+ { 0x27, 0x7b }, /* '\'' => '{' */
{ 0x32, 0x40 }, /* '2' => '@' */
{ 0x33, 0x23 }, /* '3' => '#' */
{ 0x37, 0x7c }, /* '7' => '|' */
+ { 0x3d, 0x7e }, /* '=' => '~' */
{ 0x5c, 0x7d }, /* '\\' => '}' */
{ 0, 0 }
};
diff --git a/src/util/genkeymap.py b/src/util/genkeymap.py
index 8df9496..632f71e 100755
--- a/src/util/genkeymap.py
+++ b/src/util/genkeymap.py
@@ -33,6 +33,10 @@ import textwrap
from typing import ClassVar, Optional
+BACKSPACE = chr(0x7f)
+"""Backspace character"""
+
+
class KeyType(IntEnum):
"""Key types"""
@@ -174,7 +178,7 @@ class KeyLayout(UserDict[KeyModifiers, Sequence[Key]]):
KeyModifiers.NONE: [(KEY_NON_US, ord('\\'))],
KeyModifiers.SHIFT: [(KEY_NON_US, ord('|'))],
# Treat Ctrl-Backspace as producing Backspace rather than Ctrl-H
- KeyModifiers.CTRL: [(KEY_BACKSPACE, 0x7f)],
+ KeyModifiers.CTRL: [(KEY_BACKSPACE, ord(BACKSPACE))],
},
'il': {
# Redefine some otherwise unreachable ASCII characters
@@ -200,11 +204,6 @@ class KeyLayout(UserDict[KeyModifiers, Sequence[Key]]):
"""Basic shifted keyboard layout"""
return self[KeyModifiers.SHIFT]
- @property
- def altgr(self):
- """AltGr keyboard layout"""
- return self.get(KeyModifiers.ALTGR, self.unshifted)
-
@classmethod
def load(cls, name: str) -> KeyLayout:
"""Load keymap using 'loadkeys -b'"""
@@ -281,7 +280,7 @@ class BiosKeyLayout(KeyLayout):
return inverse
-class KeymapKeys(UserDict[str, str]):
+class KeymapKeys(UserDict[str, Optional[str]]):
"""An ASCII character remapping"""
@classmethod
@@ -312,7 +311,8 @@ class KeymapKeys(UserDict[str, str]):
self.ascii_name(source), self.ascii_name(target)
)
for source, target in self.items()
- if ord(source) & ~BiosKeyLayout.KEY_PSEUDO != ord(target)
+ if target
+ and ord(source) & ~BiosKeyLayout.KEY_PSEUDO != ord(target)
) + '\t{ 0, 0 }\n}'
@@ -335,13 +335,12 @@ class Keymap:
# Construct raw mapping from source ASCII to target ASCII
raw = {source: self.target[key.modifiers][key.keycode].ascii
for source, key in self.source.inverse.items()}
- # Eliminate any null mappings, mappings that attempt to remap
- # the backspace key, or identity mappings
+ # Eliminate any identity mappings, or mappings that attempt to
+ # remap the backspace key
table = {source: target for source, target in raw.items()
- if target
- and ord(source) != 0x7f
- and ord(target) != 0x7f
- and source != target}
+ if source != target
+ and source != BACKSPACE
+ and target != BACKSPACE}
# Recursively delete any mappings that would produce
# unreachable alphanumerics (e.g. the "il" keymap, which maps
# away the whole lower-case alphabet)
@@ -354,8 +353,8 @@ class Keymap:
# Sanity check: ensure that all numerics are reachable using
# the same shift state
digits = '1234567890'
- unshifted = ''.join(table.get(x, x) for x in '1234567890')
- shifted = ''.join(table.get(x, x) for x in '!@#$%^&*()')
+ unshifted = ''.join(table.get(x) or x for x in '1234567890')
+ shifted = ''.join(table.get(x) or x for x in '!@#$%^&*()')
if digits not in (shifted, unshifted):
raise ValueError("Inconsistent numeric remapping %s / %s" %
(unshifted, shifted))
@@ -365,21 +364,22 @@ class Keymap:
def altgr(self) -> KeymapKeys:
"""AltGr remapping table"""
# Construct raw mapping from source ASCII to target ASCII
- raw = {source: self.target.altgr[key.keycode].ascii
- for source, key in self.source.inverse.items()
- if key.modifiers == KeyModifiers.NONE}
+ raw = {
+ source:
+ self.target.get((key.modifiers | KeyModifiers.ALTGR),
+ self.target[key.modifiers])[key.keycode].ascii
+ for source, key in self.source.inverse.items()
+ }
# Identify printable keys that are unreachable via the basic map
basic = self.basic
unmapped = set(x for x in basic.keys()
if x.isascii() and x.isprintable())
remapped = set(basic.values())
unreachable = unmapped - remapped
- # Eliminate any null mappings, mappings for unprintable
- # characters, or mappings for characters that are reachable
- # via the basic map
+ # Eliminate any mappings for unprintable characters, or
+ # mappings for characters that are reachable via the basic map
table = {source: target for source, target in raw.items()
if source.isprintable()
- and target
and target in unreachable}
# Check that all characters are now reachable
unreachable -= set(table.values())