summaryrefslogtreecommitdiff
path: root/src/user/knob/key.c
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2021-01-24 12:00:11 -0500
committerBenji Dial <benji6283@gmail.com>2021-01-24 12:00:11 -0500
commitbce944d1498eaa3b6940ee234c863b3548a66b37 (patch)
treeea40c087ab4f0f236aee8d158cf68550f5209f72 /src/user/knob/key.c
parentca731aa747214919df7b3dfe3478dbe787ce5b68 (diff)
downloadportland-os-bce944d1498eaa3b6940ee234c863b3548a66b37.tar.gz
graphics!
Diffstat (limited to 'src/user/knob/key.c')
-rw-r--r--src/user/knob/key.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/user/knob/key.c b/src/user/knob/key.c
new file mode 100644
index 0000000..1506f3b
--- /dev/null
+++ b/src/user/knob/key.c
@@ -0,0 +1,67 @@
+#include <keypack.h>
+
+static const char no_mod[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, '\t','\n', 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ ' ', 0, 0, 0, 0, 0, 0, '\'', 0, 0, 0, 0, ',', '-', '.', '/',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0, ';', 0, '=', 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '[','\\', ']', 0, 0,
+ '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 0, 0, 0, 0
+};
+
+static const char shifted[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, '\t','\n', 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ ' ', 0, 0, 0, 0, 0, 0, '"', 0, 0, 0, 0, '<', '_', '>', '?',
+ ')', '!', '@', '#', '$', '%', '^', '&', '*', '(', 0, ':', 0, '+', 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '{', '|', '}', 0, 0,
+ '~', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0, 0, 0, 0, 0
+};
+
+static const char caps[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, '\t','\n', 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ ' ', 0, 0, 0, 0, 0, 0, '\'', 0, 0, 0, 0, ',', '-', '.', '/',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0, ';', 0, '=', 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '[','\\', ']', 0, 0,
+ '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0, 0, 0, 0, 0
+};
+
+static const char sh_caps[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, '\t','\n', 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ ' ', 0, 0, 0, 0, 0, 0, '"', 0, 0, 0, 0, '<', '_', '>', '?',
+ ')', '!', '@', '#', '$', '%', '^', '&', '*', '(', 0, ':', 0, '+', 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '{', '|', '}', 0, 0,
+ '~', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 0, 0, 0, 0
+};
+
+static const char num[] = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '+', '\n', '-', '.', '/'
+};
+
+__attribute__ ((pure))
+char key_to_char(struct key_packet kp) {
+ if (kp.key_id < 0x80) {
+ const char ch = (kp.modifiers & SHIFTS
+ ? kp.modifiers & CAPS
+ ? sh_caps : shifted
+ : kp.modifiers & CAPS
+ ? caps : no_mod)[kp.key_id];
+ return ch ? kp.modifiers & ALTS ? 0x80 & ch : ch : 0;
+ }
+
+ else if ((kp.modifiers & NUM) && ((kp.key_id & 0xf0) == 0xb0))
+ return num[kp.key_id & 0x0f];
+
+ else
+ return 0;
+} \ No newline at end of file