summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-11-08 08:56:45 +0100
committerMitya Selivanov <automainint@guattari.tech>2024-11-08 08:56:45 +0100
commitb12ca99506c7538a74cb2ed39ce0e1781e934a2a (patch)
treeb22c0f8d5be056c8604c744c44a29b4c9b767eca
parentdc95a43da475b8ce55f25b670c9848d9dabf1cb7 (diff)
downloadreduced_system_layer-b12ca99506c7538a74cb2ed39ce0e1781e934a2a.zip
Update input
-rw-r--r--graphics.c3
-rw-r--r--index.htm45
-rwxr-xr-xreduced_system_layer.c347
3 files changed, 269 insertions, 126 deletions
diff --git a/graphics.c b/graphics.c
index d58f0d8..014ec83 100644
--- a/graphics.c
+++ b/graphics.c
@@ -386,6 +386,9 @@ void fill_rectangle(u32 op, u32 color, f64 x0, f64 y0, f64 width, f64 height) {
}
void fill_triangle(u32 op, u32 color, f64 x0, f64 y0, f64 x1, f64 y1, f64 x2, f64 y2) {
+ // FIXME PERF:
+ // Implement better algorithm.
+
i64 min_x = (i64) floor(min3(x0, x1, x2));
i64 min_y = (i64) floor(min3(y0, y1, y2));
i64 max_x = (i64) ceil (max3(x0, x1, x2));
diff --git a/index.htm b/index.htm
index 3b1fd3b..2c42d74 100644
--- a/index.htm
+++ b/index.htm
@@ -98,10 +98,11 @@
if (!wait_for_events) {
if (sleep_duration > 0) {
+ let timeout = sleep_duration;
sleep_duration = 0;
setTimeout(() => {
window.requestAnimationFrame(animation_frame);
- }, sleep_duration);
+ }, timeout);
} else
window.requestAnimationFrame(animation_frame);
}
@@ -126,24 +127,42 @@
window.requestAnimationFrame(animation_frame);
});
- canvas.addEventListener("mouseenter", (ev) => {
- console.log(ev);
- window.requestAnimationFrame(animation_frame);
- });
+ let key_from_code = (code) => {
+ switch (code) {
+ case "KeyA": return 97;
+ }
+ return 0;
+ };
- canvas.addEventListener("mouseleave", (ev) => {
- console.log(ev);
- window.requestAnimationFrame(animation_frame);
- });
+ let mod_from_event = (ev) => {
+ let mod = 0;
+ if (ev.ctrlKey) mod |= 1;
+ if (ev.shiftKey) mod |= 2;
+ if (ev.altKey) mod |= 4;
+ if (ev.metaKey) mod |= 8;
+ return mod;
+ };
window.addEventListener("keydown", (ev) => {
- console.log(ev);
- window.requestAnimationFrame(animation_frame);
+ ev.preventDefault();
+ if (!ev.repeat) {
+ let mod = mod_from_event(ev);
+ let key = key_from_code(ev.code);
+ if (key != 0)
+ program.instance.exports.js_keydown(key, mod);
+ window.requestAnimationFrame(animation_frame);
+ }
});
window.addEventListener("keyup", (ev) => {
- console.log(ev);
- window.requestAnimationFrame(animation_frame);
+ ev.preventDefault();
+ if (!ev.repeat) {
+ let mod = mod_from_event(ev);
+ let key = key_from_code(ev.code);
+ if (key != 0)
+ program.instance.exports.js_keyup(key, mod);
+ window.requestAnimationFrame(animation_frame);
+ }
});
window.requestAnimationFrame(animation_frame);
diff --git a/reduced_system_layer.c b/reduced_system_layer.c
index 211cf1b..38562eb 100755
--- a/reduced_system_layer.c
+++ b/reduced_system_layer.c
@@ -134,36 +134,129 @@ enum {
IPv4_UDP = 1,
IPv6_UDP = 2,
- KEY_LEFT = 128,
- KEY_RIGHT,
- KEY_UP,
- KEY_DOWN,
- KEY_LCTRL,
- KEY_RCTRL,
- KEY_LSHIFT,
- KEY_RSHIFT,
- KEY_LALT,
- KEY_RALT,
- KEY_ESCAPE,
- KEY_PRINTSCREEN,
- KEY_DELETE,
- KEY_PAUSE,
- KEY_INSERT,
- KEY_HOME,
- KEY_END,
- KEY_PAGEUP,
- KEY_PAGEDOWN,
- BUTTON_LEFT,
- BUTTON_MIDDLE,
- BUTTON_RIGHT,
- MOD_CTRL,
- MOD_SHIFT,
- MOD_ALT,
- MOD_CAPS,
- MOD_NUM,
- MOD_SCROLL,
- KEY_F_,
- KEY_KP_ = KEY_F_ + 64,
+ MOD_CTRL = 1,
+ MOD_SHIFT = 2,
+ MOD_ALT = 3,
+ MOD_CAPS = 4,
+ MOD_NUM = 5,
+ MOD_SCROLL = 6,
+ MOD_META = 7,
+ KEY_BACKSPACE = 8,
+ KEY_TAB = 9,
+ KEY_ENTER = 10,
+ KEY_LCTRL = 11,
+ KEY_RCTRL = 12,
+ KEY_LSHIFT = 13,
+ KEY_RSHIFT = 14,
+ KEY_LALT = 15,
+ KEY_RALT = 16,
+ KEY_LEFT = 17,
+ KEY_RIGHT = 18,
+ KEY_UP = 19,
+ KEY_DOWN = 20,
+ KEY_PAUSE = 21,
+ KEY_INSERT = 22,
+ KEY_HOME = 23,
+ KEY_END = 24,
+ KEY_PAGEUP = 25,
+ KEY_PAGEDOWN = 26,
+ KEY_ESCAPE = 27,
+ KEY_PRINTSCREEN = 28,
+ BUTTON_LEFT = 29,
+ BUTTON_MIDDLE = 30,
+ BUTTON_RIGHT = 31,
+ KEY_SPACE = 32,
+ KEY_LMETA = 33,
+ KEY_RMETA = 34,
+ KEY_QUOTE = 39,
+ KEY_COMMA = 44,
+ KEY_MINUS = 45,
+ KEY_PERIOD = 46,
+ KEY_SLASH = 47,
+ KEY_0 = 48,
+ KEY_1 = 49,
+ KEY_2 = 50,
+ KEY_3 = 51,
+ KEY_4 = 52,
+ KEY_5 = 53,
+ KEY_6 = 54,
+ KEY_7 = 55,
+ KEY_8 = 56,
+ KEY_9 = 57,
+ KEY_COLON = 59,
+ KEY_EQUAL = 61,
+ KEY_LBRACE = 91,
+ KEY_BACKSLASH = 92,
+ KEY_RBRACE = 93,
+ KEY_TILDE = 96,
+ KEY_A = 97,
+ KEY_B = 98,
+ KEY_C = 99,
+ KEY_D = 100,
+ KEY_E = 101,
+ KEY_F = 102,
+ KEY_G = 103,
+ KEY_H = 104,
+ KEY_I = 105,
+ KEY_J = 106,
+ KEY_K = 107,
+ KEY_L = 108,
+ KEY_M = 109,
+ KEY_N = 110,
+ KEY_O = 111,
+ KEY_P = 112,
+ KEY_Q = 113,
+ KEY_R = 114,
+ KEY_S = 115,
+ KEY_T = 116,
+ KEY_U = 117,
+ KEY_V = 118,
+ KEY_W = 119,
+ KEY_X = 120,
+ KEY_Y = 121,
+ KEY_Z = 122,
+ KEY_DELETE = 127,
+ KEY_KP_0 = 128,
+ KEY_KP_1 = 129,
+ KEY_KP_2 = 130,
+ KEY_KP_3 = 131,
+ KEY_KP_4 = 132,
+ KEY_KP_5 = 133,
+ KEY_KP_6 = 134,
+ KEY_KP_7 = 135,
+ KEY_KP_8 = 136,
+ KEY_KP_9 = 137,
+ KEY_KP_ENTER = 138,
+ KEY_KP_DIVIDE = 139,
+ KEY_KP_MULTIPLY = 140,
+ KEY_KP_ADD = 141,
+ KEY_KP_SUBTRACT = 142,
+ KEY_KP_DECIMAL = 143,
+ KEY_KP_SEPARATOR = 144,
+ KEY_F1 = 145,
+ KEY_F2 = 146,
+ KEY_F3 = 147,
+ KEY_F4 = 148,
+ KEY_F5 = 149,
+ KEY_F6 = 150,
+ KEY_F7 = 151,
+ KEY_F8 = 152,
+ KEY_F9 = 153,
+ KEY_F10 = 154,
+ KEY_F11 = 155,
+ KEY_F12 = 156,
+ KEY_F13 = 157,
+ KEY_F14 = 158,
+ KEY_F15 = 159,
+ KEY_F16 = 160,
+ KEY_F17 = 161,
+ KEY_F18 = 162,
+ KEY_F19 = 163,
+ KEY_F20 = 164,
+ KEY_F21 = 165,
+ KEY_F22 = 166,
+ KEY_F23 = 167,
+ KEY_F24 = 168,
};
typedef struct {
@@ -173,6 +266,7 @@ typedef struct {
b8 caps : 1;
b8 num : 1;
b8 scroll : 1;
+ b8 meta : 1;
u16 key;
c32 c;
} Input_Key;
@@ -709,76 +803,78 @@ void p_init(void) {
_key_table[XKeysymToKeycode(_display, XK_Right)] = KEY_RIGHT;
_key_table[XKeysymToKeycode(_display, XK_Up)] = KEY_UP;
_key_table[XKeysymToKeycode(_display, XK_Down)] = KEY_DOWN;
- _key_table[XKeysymToKeycode(_display, XK_1)] = '1';
- _key_table[XKeysymToKeycode(_display, XK_2)] = '2';
- _key_table[XKeysymToKeycode(_display, XK_3)] = '3';
- _key_table[XKeysymToKeycode(_display, XK_4)] = '4';
- _key_table[XKeysymToKeycode(_display, XK_5)] = '5';
- _key_table[XKeysymToKeycode(_display, XK_6)] = '6';
- _key_table[XKeysymToKeycode(_display, XK_7)] = '7';
- _key_table[XKeysymToKeycode(_display, XK_8)] = '8';
- _key_table[XKeysymToKeycode(_display, XK_9)] = '9';
- _key_table[XKeysymToKeycode(_display, XK_0)] = '0';
- _key_table[XKeysymToKeycode(_display, XK_A)] = 'a';
- _key_table[XKeysymToKeycode(_display, XK_B)] = 'b';
- _key_table[XKeysymToKeycode(_display, XK_C)] = 'c';
- _key_table[XKeysymToKeycode(_display, XK_D)] = 'd';
- _key_table[XKeysymToKeycode(_display, XK_E)] = 'e';
- _key_table[XKeysymToKeycode(_display, XK_F)] = 'f';
- _key_table[XKeysymToKeycode(_display, XK_G)] = 'g';
- _key_table[XKeysymToKeycode(_display, XK_H)] = 'h';
- _key_table[XKeysymToKeycode(_display, XK_I)] = 'i';
- _key_table[XKeysymToKeycode(_display, XK_J)] = 'j';
- _key_table[XKeysymToKeycode(_display, XK_K)] = 'k';
- _key_table[XKeysymToKeycode(_display, XK_L)] = 'l';
- _key_table[XKeysymToKeycode(_display, XK_M)] = 'm';
- _key_table[XKeysymToKeycode(_display, XK_N)] = 'n';
- _key_table[XKeysymToKeycode(_display, XK_O)] = 'o';
- _key_table[XKeysymToKeycode(_display, XK_P)] = 'p';
- _key_table[XKeysymToKeycode(_display, XK_Q)] = 'q';
- _key_table[XKeysymToKeycode(_display, XK_R)] = 'r';
- _key_table[XKeysymToKeycode(_display, XK_S)] = 's';
- _key_table[XKeysymToKeycode(_display, XK_T)] = 't';
- _key_table[XKeysymToKeycode(_display, XK_U)] = 'u';
- _key_table[XKeysymToKeycode(_display, XK_V)] = 'v';
- _key_table[XKeysymToKeycode(_display, XK_W)] = 'w';
- _key_table[XKeysymToKeycode(_display, XK_X)] = 'x';
- _key_table[XKeysymToKeycode(_display, XK_Y)] = 'y';
- _key_table[XKeysymToKeycode(_display, XK_Z)] = 'z';
- _key_table[XKeysymToKeycode(_display, XK_space)] = ' ';
- _key_table[XKeysymToKeycode(_display, XK_braceleft)] = '[';
- _key_table[XKeysymToKeycode(_display, XK_braceright)] = ']';
- _key_table[XKeysymToKeycode(_display, XK_colon)] = ';';
- _key_table[XKeysymToKeycode(_display, XK_quotedbl)] = '\'';
- _key_table[XKeysymToKeycode(_display, XK_asciitilde)] = '`';
- _key_table[XKeysymToKeycode(_display, XK_backslash)] = '\\';
- _key_table[XKeysymToKeycode(_display, XK_comma)] = ',';
- _key_table[XKeysymToKeycode(_display, XK_greater)] = '.';
- _key_table[XKeysymToKeycode(_display, XK_question)] = '/';
- _key_table[XKeysymToKeycode(_display, XK_minus)] = '-';
- _key_table[XKeysymToKeycode(_display, XK_equal)] = '=';
- _key_table[XKeysymToKeycode(_display, XK_F1)] = KEY_F_ + 1;
- _key_table[XKeysymToKeycode(_display, XK_F2)] = KEY_F_ + 2;
- _key_table[XKeysymToKeycode(_display, XK_F3)] = KEY_F_ + 3;
- _key_table[XKeysymToKeycode(_display, XK_F4)] = KEY_F_ + 4;
- _key_table[XKeysymToKeycode(_display, XK_F5)] = KEY_F_ + 5;
- _key_table[XKeysymToKeycode(_display, XK_F6)] = KEY_F_ + 6;
- _key_table[XKeysymToKeycode(_display, XK_F7)] = KEY_F_ + 7;
- _key_table[XKeysymToKeycode(_display, XK_F8)] = KEY_F_ + 8;
- _key_table[XKeysymToKeycode(_display, XK_F9)] = KEY_F_ + 9;
- _key_table[XKeysymToKeycode(_display, XK_F10)] = KEY_F_ + 10;
- _key_table[XKeysymToKeycode(_display, XK_F11)] = KEY_F_ + 11;
- _key_table[XKeysymToKeycode(_display, XK_F12)] = KEY_F_ + 12;
+ _key_table[XKeysymToKeycode(_display, XK_1)] = KEY_1;
+ _key_table[XKeysymToKeycode(_display, XK_2)] = KEY_2;
+ _key_table[XKeysymToKeycode(_display, XK_3)] = KEY_3;
+ _key_table[XKeysymToKeycode(_display, XK_4)] = KEY_4;
+ _key_table[XKeysymToKeycode(_display, XK_5)] = KEY_5;
+ _key_table[XKeysymToKeycode(_display, XK_6)] = KEY_6;
+ _key_table[XKeysymToKeycode(_display, XK_7)] = KEY_7;
+ _key_table[XKeysymToKeycode(_display, XK_8)] = KEY_8;
+ _key_table[XKeysymToKeycode(_display, XK_9)] = KEY_9;
+ _key_table[XKeysymToKeycode(_display, XK_0)] = KEY_0;
+ _key_table[XKeysymToKeycode(_display, XK_A)] = KEY_A;
+ _key_table[XKeysymToKeycode(_display, XK_B)] = KEY_B;
+ _key_table[XKeysymToKeycode(_display, XK_C)] = KEY_C;
+ _key_table[XKeysymToKeycode(_display, XK_D)] = KEY_D;
+ _key_table[XKeysymToKeycode(_display, XK_E)] = KEY_E;
+ _key_table[XKeysymToKeycode(_display, XK_F)] = KEY_F;
+ _key_table[XKeysymToKeycode(_display, XK_G)] = KEY_G;
+ _key_table[XKeysymToKeycode(_display, XK_H)] = KEY_H;
+ _key_table[XKeysymToKeycode(_display, XK_I)] = KEY_I;
+ _key_table[XKeysymToKeycode(_display, XK_J)] = KEY_J;
+ _key_table[XKeysymToKeycode(_display, XK_K)] = KEY_K;
+ _key_table[XKeysymToKeycode(_display, XK_L)] = KEY_L;
+ _key_table[XKeysymToKeycode(_display, XK_M)] = KEY_M;
+ _key_table[XKeysymToKeycode(_display, XK_N)] = KEY_N;
+ _key_table[XKeysymToKeycode(_display, XK_O)] = KEY_O;
+ _key_table[XKeysymToKeycode(_display, XK_P)] = KEY_P;
+ _key_table[XKeysymToKeycode(_display, XK_Q)] = KEY_Q;
+ _key_table[XKeysymToKeycode(_display, XK_R)] = KEY_R;
+ _key_table[XKeysymToKeycode(_display, XK_S)] = KEY_S;
+ _key_table[XKeysymToKeycode(_display, XK_T)] = KEY_T;
+ _key_table[XKeysymToKeycode(_display, XK_U)] = KEY_U;
+ _key_table[XKeysymToKeycode(_display, XK_V)] = KEY_V;
+ _key_table[XKeysymToKeycode(_display, XK_W)] = KEY_W;
+ _key_table[XKeysymToKeycode(_display, XK_X)] = KEY_X;
+ _key_table[XKeysymToKeycode(_display, XK_Y)] = KEY_Y;
+ _key_table[XKeysymToKeycode(_display, XK_Z)] = KEY_Z;
+ _key_table[XKeysymToKeycode(_display, XK_space)] = KEY_SPACE;
+ _key_table[XKeysymToKeycode(_display, XK_braceleft)] = KEY_LBRACE;
+ _key_table[XKeysymToKeycode(_display, XK_braceright)] = KEY_RBRACE;
+ _key_table[XKeysymToKeycode(_display, XK_colon)] = KEY_COLON;
+ _key_table[XKeysymToKeycode(_display, XK_quotedbl)] = KEY_QUOTE;
+ _key_table[XKeysymToKeycode(_display, XK_asciitilde)] = KEY_TILDE;
+ _key_table[XKeysymToKeycode(_display, XK_backslash)] = KEY_BACKSLASH;
+ _key_table[XKeysymToKeycode(_display, XK_comma)] = KEY_COMMA;
+ _key_table[XKeysymToKeycode(_display, XK_greater)] = KEY_PERIOD;
+ _key_table[XKeysymToKeycode(_display, XK_question)] = KEY_SLASH;
+ _key_table[XKeysymToKeycode(_display, XK_minus)] = KEY_MINUS;
+ _key_table[XKeysymToKeycode(_display, XK_equal)] = KEY_EQUAL;
+ _key_table[XKeysymToKeycode(_display, XK_F1)] = KEY_F1;
+ _key_table[XKeysymToKeycode(_display, XK_F2)] = KEY_F2;
+ _key_table[XKeysymToKeycode(_display, XK_F3)] = KEY_F3;
+ _key_table[XKeysymToKeycode(_display, XK_F4)] = KEY_F4;
+ _key_table[XKeysymToKeycode(_display, XK_F5)] = KEY_F5;
+ _key_table[XKeysymToKeycode(_display, XK_F6)] = KEY_F6;
+ _key_table[XKeysymToKeycode(_display, XK_F7)] = KEY_F7;
+ _key_table[XKeysymToKeycode(_display, XK_F8)] = KEY_F8;
+ _key_table[XKeysymToKeycode(_display, XK_F9)] = KEY_F9;
+ _key_table[XKeysymToKeycode(_display, XK_F10)] = KEY_F10;
+ _key_table[XKeysymToKeycode(_display, XK_F11)] = KEY_F11;
+ _key_table[XKeysymToKeycode(_display, XK_F12)] = KEY_F12;
_key_table[XKeysymToKeycode(_display, XK_Control_L)] = KEY_LCTRL;
_key_table[XKeysymToKeycode(_display, XK_Control_R)] = KEY_RCTRL;
_key_table[XKeysymToKeycode(_display, XK_Shift_L)] = KEY_LSHIFT;
_key_table[XKeysymToKeycode(_display, XK_Shift_R)] = KEY_RSHIFT;
_key_table[XKeysymToKeycode(_display, XK_Alt_L)] = KEY_LALT;
_key_table[XKeysymToKeycode(_display, XK_Alt_R)] = KEY_RALT;
+ _key_table[XKeysymToKeycode(_display, XK_Meta_L)] = KEY_LMETA;
+ _key_table[XKeysymToKeycode(_display, XK_Meta_R)] = KEY_RMETA;
_key_table[XKeysymToKeycode(_display, XK_Escape)] = KEY_ESCAPE;
- _key_table[XKeysymToKeycode(_display, XK_BackSpace)] = '\b';
- _key_table[XKeysymToKeycode(_display, XK_Tab)] = '\t';
- _key_table[XKeysymToKeycode(_display, XK_Return)] = '\n';
+ _key_table[XKeysymToKeycode(_display, XK_BackSpace)] = KEY_BACKSPACE;
+ _key_table[XKeysymToKeycode(_display, XK_Tab)] = KEY_TAB;
+ _key_table[XKeysymToKeycode(_display, XK_Return)] = KEY_ENTER;
_key_table[XKeysymToKeycode(_display, XK_Print)] = KEY_PRINTSCREEN;
_key_table[XKeysymToKeycode(_display, XK_Delete)] = KEY_DELETE;
_key_table[XKeysymToKeycode(_display, XK_Pause)] = KEY_PAUSE;
@@ -787,23 +883,23 @@ void p_init(void) {
_key_table[XKeysymToKeycode(_display, XK_End)] = KEY_END;
_key_table[XKeysymToKeycode(_display, XK_Page_Up)] = KEY_PAGEUP;
_key_table[XKeysymToKeycode(_display, XK_Page_Down)] = KEY_PAGEDOWN;
- _key_table[XKeysymToKeycode(_display, XK_KP_0)] = KEY_KP_ + '0';
- _key_table[XKeysymToKeycode(_display, XK_KP_1)] = KEY_KP_ + '1';
- _key_table[XKeysymToKeycode(_display, XK_KP_2)] = KEY_KP_ + '2';
- _key_table[XKeysymToKeycode(_display, XK_KP_3)] = KEY_KP_ + '3';
- _key_table[XKeysymToKeycode(_display, XK_KP_4)] = KEY_KP_ + '4';
- _key_table[XKeysymToKeycode(_display, XK_KP_5)] = KEY_KP_ + '5';
- _key_table[XKeysymToKeycode(_display, XK_KP_6)] = KEY_KP_ + '6';
- _key_table[XKeysymToKeycode(_display, XK_KP_7)] = KEY_KP_ + '7';
- _key_table[XKeysymToKeycode(_display, XK_KP_8)] = KEY_KP_ + '8';
- _key_table[XKeysymToKeycode(_display, XK_KP_9)] = KEY_KP_ + '9';
- _key_table[XKeysymToKeycode(_display, XK_KP_Enter)] = KEY_KP_ + '\n';
- _key_table[XKeysymToKeycode(_display, XK_KP_Divide)] = KEY_KP_ + '/';
- _key_table[XKeysymToKeycode(_display, XK_KP_Multiply)] = KEY_KP_ + '*';
- _key_table[XKeysymToKeycode(_display, XK_KP_Add)] = KEY_KP_ + '+';
- _key_table[XKeysymToKeycode(_display, XK_KP_Subtract)] = KEY_KP_ + '-';
- _key_table[XKeysymToKeycode(_display, XK_KP_Decimal)] = KEY_KP_ + '.';
- _key_table[XKeysymToKeycode(_display, XK_KP_Separator)] = KEY_KP_ + ',';
+ _key_table[XKeysymToKeycode(_display, XK_KP_0)] = KEY_KP_0;
+ _key_table[XKeysymToKeycode(_display, XK_KP_1)] = KEY_KP_1;
+ _key_table[XKeysymToKeycode(_display, XK_KP_2)] = KEY_KP_2;
+ _key_table[XKeysymToKeycode(_display, XK_KP_3)] = KEY_KP_3;
+ _key_table[XKeysymToKeycode(_display, XK_KP_4)] = KEY_KP_4;
+ _key_table[XKeysymToKeycode(_display, XK_KP_5)] = KEY_KP_5;
+ _key_table[XKeysymToKeycode(_display, XK_KP_6)] = KEY_KP_6;
+ _key_table[XKeysymToKeycode(_display, XK_KP_7)] = KEY_KP_7;
+ _key_table[XKeysymToKeycode(_display, XK_KP_8)] = KEY_KP_8;
+ _key_table[XKeysymToKeycode(_display, XK_KP_9)] = KEY_KP_9;
+ _key_table[XKeysymToKeycode(_display, XK_KP_Enter)] = KEY_KP_ENTER;
+ _key_table[XKeysymToKeycode(_display, XK_KP_Divide)] = KEY_KP_DIVIDE;
+ _key_table[XKeysymToKeycode(_display, XK_KP_Multiply)] = KEY_KP_MULTIPLY;
+ _key_table[XKeysymToKeycode(_display, XK_KP_Add)] = KEY_KP_ADD;
+ _key_table[XKeysymToKeycode(_display, XK_KP_Subtract)] = KEY_KP_SUBTRACT;
+ _key_table[XKeysymToKeycode(_display, XK_KP_Decimal)] = KEY_KP_DECIMAL;
+ _key_table[XKeysymToKeycode(_display, XK_KP_Separator)] = KEY_KP_SEPARATOR;
i32 screen = DefaultScreen(_display);
i32 depth = DefaultDepth (_display, screen);
@@ -974,6 +1070,7 @@ i32 p_handle_events(void) {
platform.key_down[MOD_CAPS] = !!(ev.xkey.state & LockMask);
platform.key_down[MOD_NUM] = !!(ev.xkey.state & Mod2Mask);
platform.key_down[MOD_SCROLL] = !!(ev.xkey.state & Mod3Mask);
+ platform.key_down[MOD_META] = !!(ev.xkey.state & Mod4Mask);
if (platform.input_size < MAX_INPUT_SIZE) {
if (k < 32 || k >= 128)
@@ -984,6 +1081,7 @@ i32 p_handle_events(void) {
.caps = !!(ev.xkey.state & LockMask),
.num = !!(ev.xkey.state & Mod2Mask),
.scroll = !!(ev.xkey.state & Mod3Mask),
+ .meta = !!(ev.xkey.state & Mod4Mask),
.key = k,
.c = 0,
};
@@ -998,6 +1096,7 @@ i32 p_handle_events(void) {
.caps = !!(ev.xkey.state & LockMask),
.num = !!(ev.xkey.state & Mod2Mask),
.scroll = !!(ev.xkey.state & Mod3Mask),
+ .meta = !!(ev.xkey.state & Mod4Mask),
.key = k,
.c = utf8_read(len, buf),
};
@@ -1025,6 +1124,7 @@ i32 p_handle_events(void) {
platform.key_down[MOD_CAPS] = !!(ev.xkey.state & LockMask);
platform.key_down[MOD_NUM] = !!(ev.xkey.state & Mod2Mask);
platform.key_down[MOD_SCROLL] = !!(ev.xkey.state & Mod3Mask);
+ platform.key_down[MOD_META] = !!(ev.xkey.state & Mod4Mask);
} break;
case SelectionRequest:
@@ -1220,11 +1320,15 @@ void p_queue_sound(i64 delay, i64 num_samples, f32 *samples) {
#ifdef __wasm__
-static u32 _buffer[MAX_NUM_PIXELS] = {0};
-static i32 _num_events = 0;
-static b8 _key_pressed[MAX_NUM_KEYS] = {0};
+static u32 _buffer[MAX_NUM_PIXELS] = {0};
+static Input_Key _input[MAX_INPUT_SIZE] = {0};
+static i32 _num_events = 0;
+static i32 _input_size = 0;
+static b8 _key_pressed[MAX_NUM_KEYS] = {0};
i32 p_handle_events(void) {
+ platform.input_size = _input_size;
+ _input_size = 0;
for (i64 i = 0; i < MAX_NUM_KEYS; ++i)
platform.key_pressed[i] = _key_pressed[i];
for (i64 i = 0; i < MAX_NUM_KEYS; ++i)
@@ -1270,6 +1374,7 @@ __attribute__((export_name("js_main"))) void js_main(c8 *href) {
__attribute__((export_name("js_init"))) void js_init(void) {
platform.pixels = _buffer;
+ platform.input = _input;
platform.done = 1;
}
@@ -1318,6 +1423,22 @@ __attribute__((export_name("js_mouseup"))) void js_mouseup(u32 buttons) {
if (!(buttons & 4)) platform.key_down[BUTTON_MIDDLE] = 0;
}
+__attribute__((export_name("js_keydown"))) void js_keydown(u32 key, u32 mod) {
+ ++_num_events;
+ _key_pressed[key] = 1;
+ platform.key_down[key] = 1;
+ if (platform.input_size < MAX_INPUT_SIZE)
+ platform.input[_input_size++] = (Input_Key) {
+ .key = key,
+ .c = key,
+ };
+}
+
+__attribute__((export_name("js_keyup"))) void js_keyup(u32 key, u32 mod) {
+ ++_num_events;
+ platform.key_down[key] = 0;
+}
+
#endif // __wasm__
// ================================================================