keyboard add ability to specify temporary custom layouts

rb core allows you to load custom keyboard layouts

this patch adds the ability to load a keyboard layout in a buffer
the custom layout is temporary and does not overwrite the current layout

use like so:

    unsigned short kbd[64];
    unsigned short *kbd_p = kbd;
    if (!kbd_create_layout("ABCD1234\n", kbd, sizeof(kbd)))
        kbd_p = NULL;

    rb->kbd_input(buf,sizeof(buf), kbd_p);

Change-Id: I7be2bd4a1b4797a147fa70228a9749dc56ac052a
This commit is contained in:
William Wilgus 2020-07-21 02:33:53 -04:00
parent a5df94beb5
commit cb94b3ae2e
37 changed files with 173 additions and 69 deletions

View file

@ -842,7 +842,7 @@ static void add_memo(struct shown *shown, int type)
{
bool saved = false;
struct memo *memo = &memos[memos_in_memory];
if (rb->kbd_input(memo->message, MAX_CHAR_MEMO_LEN) == 0)
if (rb->kbd_input(memo->message, MAX_CHAR_MEMO_LEN, NULL) == 0)
{
if (memo->message[0])
{
@ -920,7 +920,7 @@ static bool edit_memo(int change, struct shown *shown)
case 1: /* edit */
if(rb->kbd_input(memos[change].message,
MAX_CHAR_MEMO_LEN) == 0)
MAX_CHAR_MEMO_LEN, NULL) == 0)
save_memo(change, true, shown);
return false;

View file

@ -92,7 +92,7 @@ enum plugin_status plugin_start(const void* parameter)
searchword[0] = '\0';
/* get the word to search */
if (rb->kbd_input(searchword, sizeof(searchword)) < 0)
if (rb->kbd_input(searchword, sizeof(searchword), NULL) < 0)
return PLUGIN_OK; /* input cancelled */
fIndex = rb->open(DICT_INDEX, O_RDONLY); /* index file */

View file

@ -195,7 +195,7 @@ zchar os_read_key(int timeout, bool show_cursor)
return zkey;
inputbuf[0] = '\0';
r = rb->kbd_input(inputbuf, 5);
r = rb->kbd_input(inputbuf, 5, NULL);
rb->lcd_setfont(FONT_SYSFIXED);
dumb_dump_screen();
if (!r)
@ -226,7 +226,7 @@ zchar os_read_line(int max, zchar *buf, int timeout, int width, int continued)
if (max > width)
max = width;
strcpy(inputbuf, buf);
r = rb->kbd_input(inputbuf, 256);
r = rb->kbd_input(inputbuf, 256, NULL);
rb->lcd_setfont(FONT_SYSFIXED);
dumb_dump_screen();
if (!r)

View file

@ -677,7 +677,7 @@ do_main_menu (void)
case MAIN_SAVE_AS:
rb->strcpy (new_save_file, save_file);
if (!rb->kbd_input (new_save_file, SAVE_FILE_LENGTH))
if (!rb->kbd_input(new_save_file, SAVE_FILE_LENGTH, NULL))
{
break;
}
@ -921,7 +921,7 @@ do_gameinfo_menu (void)
break;
}
rb->kbd_input (gameinfo_string, gameinfo_string_size);
rb->kbd_input(gameinfo_string, gameinfo_string_size, NULL);
sanitize_string (gameinfo_string);
set_game_modified();
break;
@ -1191,7 +1191,7 @@ do_comment_edit (void)
return false;
}
if (!rb->kbd_input (cbuffer, sizeof (cbuffer)))
if (!rb->kbd_input (cbuffer, sizeof (cbuffer), NULL))
{
/* user didn't edit, no reason to write it back */
return true;

View file

@ -196,12 +196,12 @@ static void add_entry(int selected_item)
rb->splash(HZ, "Enter title");
pw_list.entries[i].title[0] = '\0';
if (rb->kbd_input(pw_list.entries[i].title, FIELD_LEN) < 0)
if (rb->kbd_input(pw_list.entries[i].title, FIELD_LEN, NULL) < 0)
return;
rb->splash(HZ, "Enter name");
pw_list.entries[i].name[0] = '\0';
if (rb->kbd_input(pw_list.entries[i].name, FIELD_LEN) < 0)
if (rb->kbd_input(pw_list.entries[i].name, FIELD_LEN, NULL) < 0)
{
pw_list.entries[i].title[0] = '\0';
return;
@ -209,7 +209,7 @@ static void add_entry(int selected_item)
rb->splash(HZ, "Enter password");
pw_list.entries[i].password[0] = '\0';
if (rb->kbd_input(pw_list.entries[i].password, FIELD_LEN) < 0)
if (rb->kbd_input(pw_list.entries[i].password, FIELD_LEN, NULL) < 0)
{
pw_list.entries[i].title[0] = '\0';
pw_list.entries[i].name[0] = '\0';
@ -244,7 +244,7 @@ static void edit_title(int selected_item)
if (entry->next)
entry = entry->next;
}
if (rb->kbd_input(entry->title, FIELD_LEN) == 0)
if (rb->kbd_input(entry->title, FIELD_LEN, NULL) == 0)
data_changed = true;
}
@ -257,7 +257,7 @@ static void edit_name(int selected_item)
if (entry->next)
entry = entry->next;
}
if (rb->kbd_input(entry->name, FIELD_LEN) == 0)
if (rb->kbd_input(entry->name, FIELD_LEN, NULL) == 0)
data_changed = true;
}
@ -270,7 +270,7 @@ static void edit_pw(int selected_item)
if (entry->next)
entry = entry->next;
}
if (rb->kbd_input(entry->password, FIELD_LEN) == 0)
if (rb->kbd_input(entry->password, FIELD_LEN, NULL) == 0)
data_changed = true;
}
@ -513,11 +513,11 @@ static int enter_pw(char *pw_buf, size_t buflen, bool new_pw)
if (new_pw)
{
rb->splash(HZ, "Enter new master password");
if (rb->kbd_input(buf[0], sizeof(buf[0])) < 0)
if (rb->kbd_input(buf[0], sizeof(buf[0]), NULL) < 0)
return -1;
rb->splash(HZ, "Confirm master password");
if (rb->kbd_input(buf[1], sizeof(buf[1])) < 0)
if (rb->kbd_input(buf[1], sizeof(buf[1]), NULL) < 0)
return -1;
if (rb->strcmp(buf[0], buf[1]))
@ -534,7 +534,7 @@ static int enter_pw(char *pw_buf, size_t buflen, bool new_pw)
}
rb->splash(HZ, "Enter master password");
if (rb->kbd_input(pw_buf, buflen) < 0)
if (rb->kbd_input(pw_buf, buflen, NULL) < 0)
return -1;
hash_pw(&pwhash);
return 0;

View file

@ -69,6 +69,8 @@ bmp_smooth_scale.c
pluginlib_albumart.c
#endif
kbd_helper.c
#endif /* HAVE_LCD_BITMAP */
#ifdef HAVE_TOUCHSCREEN

View file

@ -0,0 +1,63 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2020 William Wilgus
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "plugin.h"
#include "kbd_helper.h"
/* USAGE:
unsigned short kbd[64];
unsigned short *kbd_p = kbd;
if (!kbd_create_layout("ABCD1234\n", kbd, sizeof(kbd)))
kbd_p = NULL;
rb->kbd_input(buf,sizeof(buf), kbd_p);
*/
/* create a custom keyboard layout for kbd_input
* success returns size of buffer used
* failure returns 0
*/
int kbd_create_layout(char *layout, unsigned short *buf, int bufsz)
{
unsigned short *pbuf;
const unsigned char *p = layout;
int len = 0;
pbuf = buf;
while (*p && (pbuf - buf + 8) < bufsz)
{
p = rb->utf8decode(p, &pbuf[len+1]);
if (pbuf[len+1] == '\n')
{
*pbuf = len;
pbuf += len+1;
len = 0;
}
else
len++;
}
if (len+1 < bufsz)
{
*pbuf = len;
pbuf[len+1] = 0xFEFF; /* mark end of characters */
return len + 1;
}
return 0;
}

View file

@ -0,0 +1,27 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2020 William Wilgus
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef KBD_HELPER_H
#define KBD_HELPER_H
/* create a custom keyboard layout for kbd_input */
int kbd_create_layout(char *layout, unsigned short *buf, int bufsz);
#endif /* KBD_HELPER_H */

View file

@ -2475,7 +2475,7 @@ static bool lrc_lyrics_menu(void)
#endif
case LRC_MENU_LRC_DIR:
rb->strcpy(temp_buf, prefs.lrc_directory);
if (!rb->kbd_input(temp_buf, sizeof(prefs.lrc_directory)))
if (!rb->kbd_input(temp_buf, sizeof(prefs.lrc_directory), NULL))
rb->strcpy(prefs.lrc_directory, temp_buf);
break;
case MENU_ATTACHED_USB:

View file

@ -152,7 +152,7 @@ RB_WRAP(kbd_input)
else
buffer[0] = '\0';
if(!rb->kbd_input(buffer, LUAL_BUFFERSIZE))
if(!rb->kbd_input(buffer, LUAL_BUFFERSIZE, NULL))
{
luaL_addstring(&b, buffer);
luaL_pushresult(&b);

View file

@ -411,10 +411,11 @@ static void add_acct_manual(void)
memset(accounts + next_slot, 0, sizeof(struct account_t));
rb->splash(HZ * 1, "Enter account name.");
if(rb->kbd_input(accounts[next_slot].name, sizeof(accounts[next_slot].name)) < 0)
char* buf = accounts[next_slot].name;
if(rb->kbd_input(buf, sizeof(accounts[next_slot].name), NULL) < 0)
return;
if(acct_exists(accounts[next_slot].name))
if(acct_exists(buf))
{
rb->splash(HZ * 2, "Duplicate account name!");
return;
@ -425,7 +426,7 @@ static void add_acct_manual(void)
char temp_buf[SECRET_MAX * 2];
memset(temp_buf, 0, sizeof(temp_buf));
if(rb->kbd_input(temp_buf, sizeof(temp_buf)) < 0)
if(rb->kbd_input(temp_buf, sizeof(temp_buf), NULL) < 0)
return;
if((accounts[next_slot].sec_len = base32_decode(accounts[next_slot].secret, SECRET_MAX, temp_buf)) <= 0)
@ -457,7 +458,7 @@ static void add_acct_manual(void)
temp_buf[1] = '0';
}
if(rb->kbd_input(temp_buf, sizeof(temp_buf)) < 0)
if(rb->kbd_input(temp_buf, sizeof(temp_buf), NULL) < 0)
return;
if(!accounts[next_slot].is_totp)
@ -470,7 +471,7 @@ static void add_acct_manual(void)
memset(temp_buf, 0, sizeof(temp_buf));
temp_buf[0] = '6';
if(rb->kbd_input(temp_buf, sizeof(temp_buf)) < 0)
if(rb->kbd_input(temp_buf, sizeof(temp_buf), NULL) < 0)
return;
accounts[next_slot].digits = rb->atoi(temp_buf);
@ -667,7 +668,7 @@ static void edit_menu(int acct)
case 0: // rename
rb->splash(HZ, "Enter new name.");
rb->strlcpy(data_buf, accounts[acct].name, sizeof(data_buf));
if(rb->kbd_input(data_buf, sizeof(data_buf)) < 0)
if(rb->kbd_input(data_buf, sizeof(data_buf), NULL) < 0)
break;
if(acct_exists(data_buf))
{
@ -695,7 +696,7 @@ static void edit_menu(int acct)
else
rb->snprintf(data_buf, sizeof(data_buf), "%d", accounts[acct].totp_period);
if(rb->kbd_input(data_buf, sizeof(data_buf)) < 0)
if(rb->kbd_input(data_buf, sizeof(data_buf), NULL) < 0)
break;
if(accounts[acct].is_totp)
@ -709,7 +710,7 @@ static void edit_menu(int acct)
break;
case 3: // digits
rb->snprintf(data_buf, sizeof(data_buf), "%d", accounts[acct].digits);
if(rb->kbd_input(data_buf, sizeof(data_buf)) < 0)
if(rb->kbd_input(data_buf, sizeof(data_buf), NULL) < 0)
break;
accounts[acct].digits = rb->atoi(data_buf);
@ -722,7 +723,7 @@ static void edit_menu(int acct)
memcpy(temp_sec, accounts[acct].secret, accounts[acct].sec_len);
base32_encode(accounts[acct].secret, accounts[acct].sec_len, data_buf, sizeof(data_buf));
if(rb->kbd_input(data_buf, sizeof(data_buf)) < 0)
if(rb->kbd_input(data_buf, sizeof(data_buf), NULL) < 0)
break;
int ret = base32_decode(accounts[acct].secret, sizeof(accounts[acct].secret), data_buf);

View file

@ -2411,7 +2411,7 @@ static bool do_configure_item(config_item *cfgs, int idx)
}
rb->strlcpy(newstr, cfg->u.string.sval, MAX_STRLEN);
if(rb->kbd_input(newstr, MAX_STRLEN) < 0)
if(rb->kbd_input(newstr, MAX_STRLEN, NULL) < 0)
{
sfree(newstr);
return false;

View file

@ -623,7 +623,7 @@ static void led_resistance_calc(void)
rb->splash(HZ*2, "(First) Input the supply voltage:");
memset(kbd_buffer,0,sizeof(kbd_buffer));
rb->kbd_input(kbd_buffer, sizeof(kbd_buffer));
rb->kbd_input(kbd_buffer, sizeof(kbd_buffer), NULL);
input_voltage = rb->atoi(kbd_buffer);
if(input_voltage == 0) break;
@ -660,7 +660,7 @@ static void led_resistance_calc(void)
rb->lcd_clear_display();
rb->splash(HZ*2, "Input the foreward current, in mA");
memset(fwd_kbd_buffer,0,sizeof(fwd_kbd_buffer));
rb->kbd_input(fwd_kbd_buffer, sizeof(fwd_kbd_buffer));
rb->kbd_input(fwd_kbd_buffer, sizeof(fwd_kbd_buffer), NULL);
foreward_current = ((rb->atoi(fwd_kbd_buffer))/10);
break;
}
@ -817,7 +817,7 @@ static void resistance_to_color(void)
NULL, false);
if(ret<0) break;
rb->kbd_input(kbd_buffer, sizeof(kbd_buffer));
rb->kbd_input(kbd_buffer, sizeof(kbd_buffer), NULL);
/* As stated above somewhere, we (I) need to make a calculator-like
keypad, that keyboard isn't all that fun to use. */
ret = rb->do_menu(&r_to_c_menu_tol, &menu_selection_tol,

View file

@ -276,7 +276,7 @@ static bool do_slot(int slot_id, bool is_load) {
if (!is_load)
{
slot_info(desc_buf, sizeof(desc_buf), slot_id, false);
if ( rb->kbd_input(desc_buf, sizeof(desc_buf)) < 0 )
if ( rb->kbd_input(desc_buf, sizeof(desc_buf), NULL) < 0 )
return false;
if ( !strlen(desc_buf) )
strlcpy(desc_buf, "Untitled", sizeof(desc_buf));

View file

@ -1794,7 +1794,7 @@ static void draw_text( int x, int y )
{
case TEXT_MENU_TEXT:
rb->lcd_set_foreground(COLOR_BLACK);
rb->kbd_input( buffer->text.text, MAX_TEXT );
rb->kbd_input( buffer->text.text, MAX_TEXT, NULL );
break;
case TEXT_MENU_FONT:
@ -2790,7 +2790,7 @@ static void goto_menu(void)
rb->lcd_set_foreground(COLOR_BLACK);
if (!filename[0])
rb->strcpy(filename,"/");
if( !rb->kbd_input( filename, MAX_PATH ) )
if( !rb->kbd_input( filename, MAX_PATH, NULL ) )
{
if( !check_extention( filename, ".bmp" ) )
rb->strcat(filename, ".bmp");

View file

@ -224,7 +224,7 @@ void CONSOLE_HandleInput()
//If console_buffer[0] strlen() != 0
//1. Push the dirty_buffer unto the console_buffer
//2. parse the text
rb->kbd_input(dirty_buffer, sizeof(dirty_buffer));
rb->kbd_input(dirty_buffer, sizeof(dirty_buffer), NULL);
CONSOLE_Printf("%s", dirty_buffer);
console_cursor_pos = 0;

View file

@ -151,7 +151,7 @@ keyname_t keynames[] =
/* Rockbox hack */
void rb_console(void)
{
rb->kbd_input(key_lines[edit_line] + 1, MAXCMDLINE-1);
rb->kbd_input(key_lines[edit_line] + 1, MAXCMDLINE-1, NULL);
}
/*

View file

@ -111,7 +111,7 @@ static void clear_display(void){
static bool search_init(const char* file){
rb->memset(search_string, 0, sizeof(search_string));
if (!rb->kbd_input(search_string,sizeof search_string)){
if (!rb->kbd_input(search_string,sizeof(search_string), NULL)){
clear_display();
rb->splash(0, "Searching...");
fd = rb->open_utf8(file, O_RDONLY);

View file

@ -1963,7 +1963,7 @@ static bool sokoban_loop(void)
*loc = '.';
}
if (!rb->kbd_input(buf, MAX_PATH))
if (!rb->kbd_input(buf, MAX_PATH, NULL))
save(buf, true);
} else
rb->splash(HZ*2, "Solution too long to save");

View file

@ -874,7 +874,7 @@ static void save_editor(struct mp3entry *mp3, int splittime)
break;
case SE_PART1_NAME:
rb->kbd_input(part1_name, MAX_PATH);
rb->kbd_input(part1_name, MAX_PATH, NULL);
break;
case SE_PART2_SAVE:
@ -882,7 +882,7 @@ static void save_editor(struct mp3entry *mp3, int splittime)
break;
case SE_PART2_NAME:
rb->kbd_input(part2_name, MAX_PATH);
rb->kbd_input(part2_name, MAX_PATH, NULL);
break;
case SE_SAVE:

View file

@ -983,7 +983,7 @@ static int sudoku_edit_menu(struct sudoku_state_t* state)
switch (result) {
case 0: /* Save new game */
rb->kbd_input(state->filename,MAX_PATH);
rb->kbd_input(state->filename,MAX_PATH, NULL);
if (save_sudoku(state)) {
state->editmode=0;
} else {

View file

@ -689,7 +689,7 @@ static int save_game(void)
char savepath[MAX_PATH];
rb->snprintf(savepath, sizeof(savepath), "/Savegame.ssg");
if(rb->kbd_input(savepath, MAX_PATH))
if(rb->kbd_input(savepath, MAX_PATH, NULL))
{
DEBUGF("Keyboard input failed\n");
return -1;

View file

@ -173,7 +173,7 @@ static bool save_changes(int overwrite)
if (newfile || !overwrite)
{
if(rb->kbd_input(filename,MAX_PATH) < 0)
if(rb->kbd_input(filename,MAX_PATH, NULL) < 0)
{
newfile = true;
return false;
@ -247,7 +247,7 @@ static int do_item_menu(int cur_sel)
ret = MENU_RET_NO_UPDATE;
break;
case 2: /* insert above */
if (!rb->kbd_input(copy_buffer,MAX_LINE_LEN))
if (!rb->kbd_input(copy_buffer,MAX_LINE_LEN, NULL))
{
do_action(ACTION_INSERT,copy_buffer,cur_sel);
copy_buffer[0]='\0';
@ -255,7 +255,7 @@ static int do_item_menu(int cur_sel)
}
break;
case 3: /* insert below */
if (!rb->kbd_input(copy_buffer,MAX_LINE_LEN))
if (!rb->kbd_input(copy_buffer,MAX_LINE_LEN, NULL))
{
do_action(ACTION_INSERT,copy_buffer,cur_sel+1);
copy_buffer[0]='\0';
@ -425,7 +425,7 @@ enum plugin_status plugin_start(const void* parameter)
switch (rb->do_menu(&menu, NULL, NULL, false))
{
case 0:
temp_changed = !rb->kbd_input(extension, sizeof(extension));
temp_changed = !rb->kbd_input(extension, sizeof(extension), NULL);
break;
case 1:
old_color = color;
@ -446,7 +446,7 @@ enum plugin_status plugin_start(const void* parameter)
}
else
#endif
if (!rb->kbd_input(temp_line,MAX_LINE_LEN))
if (!rb->kbd_input(temp_line,MAX_LINE_LEN, NULL))
{
if (line_count)
do_action(ACTION_UPDATE,temp_line,cur_sel);

View file

@ -628,7 +628,7 @@ void save_snapshot(void)
name[0]='/';
name[1]='\0';
put_msg("Enter name of snapshot file to save:");
if (!rb->kbd_input((char*)&name, sizeof name))
if (!rb->kbd_input((char*)&name, sizeof(name), NULL))
save_snapshot_file(&name[0]);
}