Word Unperfect
public
Read
Owner: themaster
Branch: main
Commits: 0
Git CLI clone URL
git clone https://www.xt-emporium.com/git/word-unperfect.git
Fullscreen desktop URL
Code
Commits
History
Branches
Bug Reports
Discussions
Compare
Settings
word-unperfect
/
rev
/
wp_key_dispatcher.c
File editor
#include "wp_key_dispatcher.h" #include <stddef.h> #include <string.h> static bool wp_key_is_yes(uint16_t scancode) { return scancode == 'Y' || scancode == 'y'; } static bool wp_key_is_no(uint16_t scancode) { return scancode == 'N' || scancode == 'n' || scancode == 0x01; /* Esc */ } static void wp_key_set_command(WpKeyState *ks, WpCommand command) { ks->pending_command = command; ks->last_command = command; } WpCommand wp_key_command_for_scancode(uint16_t scancode, uint8_t modifiers) { if (scancode >= 0x3BU && scancode <= 0x44U) { int f_num = (int)scancode - 0x3A; switch (f_num) { case 1: return WP_CMD_CANCEL; case 3: return (modifiers & WP_MOD_ALT) ? WP_CMD_REVEAL : WP_CMD_HELP; case 5: return WP_CMD_LIST; case 7: return (modifiers & WP_MOD_SHIFT) ? WP_CMD_PRINT : WP_CMD_EXIT; case 10: return WP_CMD_SAVE; default: break; } } return WP_CMD_NONE; } bool wp_key_decode_binding(uint16_t raw_entry, WpKeyBindingAction *out_action) { WpKeyBindingAction action; if (out_action == NULL) { return false; } memset(&action, 0, sizeof(action)); action.raw_entry = raw_entry; action.id = (uint8_t)raw_entry; switch (raw_entry & 0xFF00U) { case 0x0000U: action.kind = raw_entry == 0U ? WP_KEY_BINDING_EMPTY : WP_KEY_BINDING_OTHER; break; case 0xFE00U: action.kind = WP_KEY_BINDING_LITERAL; break; case 0xFD00U: action.kind = WP_KEY_BINDING_MACRO; break; case 0x8000U: action.kind = WP_KEY_BINDING_COMMAND; action.command = wp_key_command_for_scancode(action.id, 0U); break; case 0xFC00U: action.kind = WP_KEY_BINDING_MACRO_COMMAND; break; case 0xFF00U: if (raw_entry == 0xFFFFU) { action.kind = WP_KEY_BINDING_EMPTY; } else { action.kind = WP_KEY_BINDING_OTHER; } break; default: action.kind = WP_KEY_BINDING_OTHER; break; } *out_action = action; return true; } void wp_key_init(WpKeyState *ks) { if (ks != NULL) { memset(ks, 0, sizeof(*ks)); } } void wp_key_process(WpKeyState *ks, uint16_t scancode, uint8_t modifiers) { if (ks == NULL) { return; } ks->last_key = scancode; ks->modifiers = modifiers; if (ks->waiting_for_confirmation) { if (wp_key_is_yes(scancode)) { ks->waiting_for_confirmation = false; ks->last_command = ks->pending_command; } else if (wp_key_is_no(scancode)) { ks->waiting_for_confirmation = false; ks->pending_command = WP_CMD_NONE; ks->last_command = WP_CMD_NONE; } return; } ks->pending_command = WP_CMD_NONE; if (wp_key_command_for_scancode(scancode, modifiers) == WP_CMD_EXIT && (modifiers & WP_MOD_SHIFT) == 0U) { ks->pending_command = WP_CMD_EXIT; ks->waiting_for_confirmation = true; } else { WpCommand command = wp_key_command_for_scancode(scancode, modifiers); if (command != WP_CMD_NONE) { wp_key_set_command(ks, command); } } } WpCommand wp_key_consume_command(WpKeyState *ks) { WpCommand command; if (ks == NULL || ks->waiting_for_confirmation) { return WP_CMD_NONE; } command = ks->pending_command; ks->pending_command = WP_CMD_NONE; return command; } void wp_macro_execute(const char *filename) { /* Macro playback is intentionally separate from the keyboard state machine; * later passes can parse .WPM tokens and feed wp_key_process(). */ (void)filename; }
Commit message
This repository is read-only for this account.
Repository snapshot
Current branch
main
Visibility
public
Your access
Read
Remote
None
File activity
View file history