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

@ -82,8 +82,9 @@ static void kdb_init(void)
sleep(HZ/10); sleep(HZ/10);
} }
int kbd_input(char* text, int buflen) int kbd_input(char* text, int buflen, unsigned short *kbd)
{ {
(void)kbd;
JNIEnv e = *env_ptr; JNIEnv e = *env_ptr;
jstring str = e->NewStringUTF(env_ptr, text); jstring str = e->NewStringUTF(env_ptr, text);
jstring ok_text = e->NewStringUTF(env_ptr, str(LANG_KBD_OK)); jstring ok_text = e->NewStringUTF(env_ptr, str(LANG_KBD_OK));

View file

@ -21,7 +21,9 @@
#ifndef _KEYBOARD_H #ifndef _KEYBOARD_H
#define _KEYBOARD_H #define _KEYBOARD_H
int kbd_input(char* buffer, int buflen); /* '*kbd', same format as https://www.rockbox.org/wiki/LoadableKeyboardLayouts */
int kbd_input(char* buffer, int buflen, unsigned short *kbd);
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
int load_kbd(unsigned char* filename); int load_kbd(unsigned char* filename);

View file

@ -58,7 +58,7 @@ int save_playlist_screen(struct playlist_info* playlist)
if (dot) /* remove extension */ if (dot) /* remove extension */
*dot = '\0'; *dot = '\0';
if (!kbd_input(temp, sizeof(temp))) if (!kbd_input(temp, sizeof(temp), NULL))
{ {
len = strlen(temp); len = strlen(temp);
if(len > 4 && !strcasecmp(&temp[len-4], ".m3u")) if(len > 4 && !strcasecmp(&temp[len-4], ".m3u"))

View file

@ -1009,7 +1009,7 @@ static int rename_file(void)
if (strlcpy(newname, selection, sizeof (newname)) >= sizeof (newname)) { if (strlcpy(newname, selection, sizeof (newname)) >= sizeof (newname)) {
/* Too long */ /* Too long */
} else if (kbd_input(newbase, sizeof (newname) - pathlen) < 0) { } else if (kbd_input(newbase, sizeof (newname) - pathlen, NULL) < 0) {
rc = OPRC_CANCELLED; rc = OPRC_CANCELLED;
} else if (!strcmp(oldbase, newbase)) { } else if (!strcmp(oldbase, newbase)) {
rc = OPRC_NOOP; /* No change at all */ rc = OPRC_NOOP; /* No change at all */
@ -1051,7 +1051,7 @@ static int create_dir(void)
if (pathlen >= sizeof (dirname)) { if (pathlen >= sizeof (dirname)) {
/* Too long */ /* Too long */
} else if (kbd_input(basename, sizeof (dirname) - pathlen) < 0) { } else if (kbd_input(basename, sizeof (dirname) - pathlen, NULL) < 0) {
rc = OPRC_CANCELLED; rc = OPRC_CANCELLED;
} else if (check_new_name(basename)) { } else if (check_new_name(basename)) {
rc = mkdir(dirname); rc = mkdir(dirname);

View file

@ -97,8 +97,9 @@ static void say_edit(void)
talk_id(VOICE_EDIT, false); talk_id(VOICE_EDIT, false);
} }
int kbd_input(char* text, int buflen) int kbd_input(char* text, int buflen, unsigned short *kbd)
{ {
(void) kbd;
bool done = false; bool done = false;
bool redraw = true; bool redraw = true;
bool line_edit = false; bool line_edit = false;

View file

@ -356,7 +356,7 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr,
else else
strlcpy(playlist, m3u8name, MAX_PATH); strlcpy(playlist, m3u8name, MAX_PATH);
if (kbd_input(playlist, MAX_PATH)) if (kbd_input(playlist, MAX_PATH, NULL))
return false; return false;
len = strlen(playlist); len = strlen(playlist);

View file

@ -910,7 +910,7 @@ bool search_playlist(void)
if (!playlist_viewer_init(&viewer, 0, false)) if (!playlist_viewer_init(&viewer, 0, false))
return ret; return ret;
if (kbd_input(search_str, sizeof(search_str)) < 0) if (kbd_input(search_str, sizeof(search_str), NULL) < 0)
return ret; return ret;
lcd_clear_display(); lcd_clear_display();
playlist_count = playlist_amount_ex(viewer.playlist); playlist_count = playlist_amount_ex(viewer.playlist);

View file

@ -927,7 +927,7 @@ struct plugin_api {
int (*rand)(void); int (*rand)(void);
void (*qsort)(void *base, size_t nmemb, size_t size, void (*qsort)(void *base, size_t nmemb, size_t size,
int(*compar)(const void *, const void *)); int(*compar)(const void *, const void *));
int (*kbd_input)(char* buffer, int buflen); int (*kbd_input)(char* buffer, int buflen, unsigned short *kbd);
struct tm* (*get_time)(void); struct tm* (*get_time)(void);
int (*set_time)(const struct tm *tm); int (*set_time)(const struct tm *tm);
struct tm * (*gmtime_r)(const time_t *timep, struct tm *tm); struct tm * (*gmtime_r)(const time_t *timep, struct tm *tm);

View file

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

View file

@ -92,7 +92,7 @@ enum plugin_status plugin_start(const void* parameter)
searchword[0] = '\0'; searchword[0] = '\0';
/* get the word to search */ /* 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 */ return PLUGIN_OK; /* input cancelled */
fIndex = rb->open(DICT_INDEX, O_RDONLY); /* index file */ 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; return zkey;
inputbuf[0] = '\0'; inputbuf[0] = '\0';
r = rb->kbd_input(inputbuf, 5); r = rb->kbd_input(inputbuf, 5, NULL);
rb->lcd_setfont(FONT_SYSFIXED); rb->lcd_setfont(FONT_SYSFIXED);
dumb_dump_screen(); dumb_dump_screen();
if (!r) if (!r)
@ -226,7 +226,7 @@ zchar os_read_line(int max, zchar *buf, int timeout, int width, int continued)
if (max > width) if (max > width)
max = width; max = width;
strcpy(inputbuf, buf); strcpy(inputbuf, buf);
r = rb->kbd_input(inputbuf, 256); r = rb->kbd_input(inputbuf, 256, NULL);
rb->lcd_setfont(FONT_SYSFIXED); rb->lcd_setfont(FONT_SYSFIXED);
dumb_dump_screen(); dumb_dump_screen();
if (!r) if (!r)

View file

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

View file

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

View file

@ -69,6 +69,8 @@ bmp_smooth_scale.c
pluginlib_albumart.c pluginlib_albumart.c
#endif #endif
kbd_helper.c
#endif /* HAVE_LCD_BITMAP */ #endif /* HAVE_LCD_BITMAP */
#ifdef HAVE_TOUCHSCREEN #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 #endif
case LRC_MENU_LRC_DIR: case LRC_MENU_LRC_DIR:
rb->strcpy(temp_buf, prefs.lrc_directory); 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); rb->strcpy(prefs.lrc_directory, temp_buf);
break; break;
case MENU_ATTACHED_USB: case MENU_ATTACHED_USB:

View file

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

View file

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

View file

@ -623,7 +623,7 @@ static void led_resistance_calc(void)
rb->splash(HZ*2, "(First) Input the supply voltage:"); rb->splash(HZ*2, "(First) Input the supply voltage:");
memset(kbd_buffer,0,sizeof(kbd_buffer)); 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); input_voltage = rb->atoi(kbd_buffer);
if(input_voltage == 0) break; if(input_voltage == 0) break;
@ -660,7 +660,7 @@ static void led_resistance_calc(void)
rb->lcd_clear_display(); rb->lcd_clear_display();
rb->splash(HZ*2, "Input the foreward current, in mA"); rb->splash(HZ*2, "Input the foreward current, in mA");
memset(fwd_kbd_buffer,0,sizeof(fwd_kbd_buffer)); 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); foreward_current = ((rb->atoi(fwd_kbd_buffer))/10);
break; break;
} }
@ -817,7 +817,7 @@ static void resistance_to_color(void)
NULL, false); NULL, false);
if(ret<0) break; 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 /* As stated above somewhere, we (I) need to make a calculator-like
keypad, that keyboard isn't all that fun to use. */ keypad, that keyboard isn't all that fun to use. */
ret = rb->do_menu(&r_to_c_menu_tol, &menu_selection_tol, 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) if (!is_load)
{ {
slot_info(desc_buf, sizeof(desc_buf), slot_id, false); 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; return false;
if ( !strlen(desc_buf) ) if ( !strlen(desc_buf) )
strlcpy(desc_buf, "Untitled", sizeof(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: case TEXT_MENU_TEXT:
rb->lcd_set_foreground(COLOR_BLACK); rb->lcd_set_foreground(COLOR_BLACK);
rb->kbd_input( buffer->text.text, MAX_TEXT ); rb->kbd_input( buffer->text.text, MAX_TEXT, NULL );
break; break;
case TEXT_MENU_FONT: case TEXT_MENU_FONT:
@ -2790,7 +2790,7 @@ static void goto_menu(void)
rb->lcd_set_foreground(COLOR_BLACK); rb->lcd_set_foreground(COLOR_BLACK);
if (!filename[0]) if (!filename[0])
rb->strcpy(filename,"/"); rb->strcpy(filename,"/");
if( !rb->kbd_input( filename, MAX_PATH ) ) if( !rb->kbd_input( filename, MAX_PATH, NULL ) )
{ {
if( !check_extention( filename, ".bmp" ) ) if( !check_extention( filename, ".bmp" ) )
rb->strcat(filename, ".bmp"); rb->strcat(filename, ".bmp");

View file

@ -224,7 +224,7 @@ void CONSOLE_HandleInput()
//If console_buffer[0] strlen() != 0 //If console_buffer[0] strlen() != 0
//1. Push the dirty_buffer unto the console_buffer //1. Push the dirty_buffer unto the console_buffer
//2. parse the text //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_Printf("%s", dirty_buffer);
console_cursor_pos = 0; console_cursor_pos = 0;

View file

@ -151,7 +151,7 @@ keyname_t keynames[] =
/* Rockbox hack */ /* Rockbox hack */
void rb_console(void) 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){ static bool search_init(const char* file){
rb->memset(search_string, 0, sizeof(search_string)); 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(); clear_display();
rb->splash(0, "Searching..."); rb->splash(0, "Searching...");
fd = rb->open_utf8(file, O_RDONLY); fd = rb->open_utf8(file, O_RDONLY);

View file

@ -1963,7 +1963,7 @@ static bool sokoban_loop(void)
*loc = '.'; *loc = '.';
} }
if (!rb->kbd_input(buf, MAX_PATH)) if (!rb->kbd_input(buf, MAX_PATH, NULL))
save(buf, true); save(buf, true);
} else } else
rb->splash(HZ*2, "Solution too long to save"); 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; break;
case SE_PART1_NAME: case SE_PART1_NAME:
rb->kbd_input(part1_name, MAX_PATH); rb->kbd_input(part1_name, MAX_PATH, NULL);
break; break;
case SE_PART2_SAVE: case SE_PART2_SAVE:
@ -882,7 +882,7 @@ static void save_editor(struct mp3entry *mp3, int splittime)
break; break;
case SE_PART2_NAME: case SE_PART2_NAME:
rb->kbd_input(part2_name, MAX_PATH); rb->kbd_input(part2_name, MAX_PATH, NULL);
break; break;
case SE_SAVE: case SE_SAVE:

View file

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

View file

@ -689,7 +689,7 @@ static int save_game(void)
char savepath[MAX_PATH]; char savepath[MAX_PATH];
rb->snprintf(savepath, sizeof(savepath), "/Savegame.ssg"); 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"); DEBUGF("Keyboard input failed\n");
return -1; return -1;

View file

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

View file

@ -628,7 +628,7 @@ void save_snapshot(void)
name[0]='/'; name[0]='/';
name[1]='\0'; name[1]='\0';
put_msg("Enter name of snapshot file to save:"); 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]); save_snapshot_file(&name[0]);
} }

View file

@ -277,7 +277,7 @@ int handle_radio_add_preset(void)
{ {
buf[0] = '\0'; buf[0] = '\0';
if (!kbd_input(buf, MAX_FMPRESET_LEN + 1)) if (!kbd_input(buf, MAX_FMPRESET_LEN + 1, NULL))
{ {
struct fmstation * const fms = &presets[num_presets]; struct fmstation * const fms = &presets[num_presets];
strcpy(fms->name, buf); strcpy(fms->name, buf);
@ -307,7 +307,7 @@ static int radio_edit_preset(void)
strcpy(buf, fms->name); strcpy(buf, fms->name);
if (!kbd_input(buf, MAX_FMPRESET_LEN + 1)) if (!kbd_input(buf, MAX_FMPRESET_LEN + 1, NULL))
{ {
strcpy(fms->name, buf); strcpy(fms->name, buf);
presets_changed = true; presets_changed = true;
@ -372,7 +372,7 @@ int preset_list_save(void)
while(bad_file_name) while(bad_file_name)
{ {
if(!kbd_input(filepreset, sizeof(filepreset))) if(!kbd_input(filepreset, sizeof(filepreset), NULL))
{ {
/* check the name: max MAX_FILENAME (20) chars */ /* check the name: max MAX_FILENAME (20) chars */
char* p2; char* p2;

View file

@ -82,6 +82,7 @@
struct keyboard_parameters struct keyboard_parameters
{ {
unsigned short kbd_buf[KBD_BUF_SIZE]; unsigned short kbd_buf[KBD_BUF_SIZE];
unsigned short *kbd_buf_ptr;
unsigned short max_line_len; unsigned short max_line_len;
int default_lines; int default_lines;
int last_k; int last_k;
@ -295,7 +296,7 @@ static unsigned short get_kbd_ch(struct keyboard_parameters *pm, int x, int y)
i = pm->last_i; i = pm->last_i;
k -= pm->last_k; k -= pm->last_k;
} }
for (pbuf = &pm->kbd_buf[i]; (i = *pbuf) != 0xFEFF; pbuf += i + 1) for (pbuf = &pm->kbd_buf_ptr[i]; (i = *pbuf) != 0xFEFF; pbuf += i + 1)
{ {
n = i ? (i + pm->max_chars - 1) / pm->max_chars : 1; n = i ? (i + pm->max_chars - 1) / pm->max_chars : 1;
if (k < n) break; if (k < n) break;
@ -304,7 +305,7 @@ static unsigned short get_kbd_ch(struct keyboard_parameters *pm, int x, int y)
if (y == 0 && i != 0xFEFF) if (y == 0 && i != 0xFEFF)
{ {
pm->last_k = pm->page*pm->lines - k; pm->last_k = pm->page*pm->lines - k;
pm->last_i = pbuf - pm->kbd_buf; pm->last_i = pbuf - pm->kbd_buf_ptr;
} }
k = k * pm->max_chars + x; k = k * pm->max_chars + x;
return (*pbuf != 0xFEFF && k < *pbuf)? pbuf[k+1]: ' '; return (*pbuf != 0xFEFF && k < *pbuf)? pbuf[k+1]: ' ';
@ -330,7 +331,7 @@ static void kbd_move_picker_horizontal(struct keyboard_parameters *pm,
static void kbd_move_picker_vertical(struct keyboard_parameters *pm, static void kbd_move_picker_vertical(struct keyboard_parameters *pm,
struct edit_state *state, int dir); struct edit_state *state, int dir);
int kbd_input(char* text, int buflen) int kbd_input(char* text, int buflen, unsigned short *kbd)
{ {
bool done = false; bool done = false;
struct keyboard_parameters * const param = kbd_param; struct keyboard_parameters * const param = kbd_param;
@ -438,6 +439,12 @@ int kbd_input(char* text, int buflen)
FOR_NB_SCREENS(l) FOR_NB_SCREENS(l)
{ {
struct keyboard_parameters *pm = &param[l]; struct keyboard_parameters *pm = &param[l];
if(kbd) /* user supplied custom layout */
pm->kbd_buf_ptr = kbd;
else
pm->kbd_buf_ptr = pm->kbd_buf; /* internal layout buffer */
struct screen *sc = &screens[l]; struct screen *sc = &screens[l];
kbd_calc_params(pm, sc, &state); kbd_calc_params(pm, sc, &state);
} }
@ -743,7 +750,7 @@ static void kbd_calc_params(struct keyboard_parameters *pm,
* since we're going to be adding spaces, * since we're going to be adding spaces,
* max width is at least their width */ * max width is at least their width */
pm->font_w = font_get_width(font, ' '); pm->font_w = font_get_width(font, ' ');
for (pbuf = pm->kbd_buf; *pbuf != 0xFEFF; pbuf += i) for (pbuf = pm->kbd_buf_ptr; *pbuf != 0xFEFF; pbuf += i)
{ {
for (i = 0; ++i <= *pbuf; ) for (i = 0; ++i <= *pbuf; )
{ {
@ -807,7 +814,7 @@ recalc_param:
pm->keyboard_margin = DEFAULT_MARGIN; pm->keyboard_margin = DEFAULT_MARGIN;
total_lines = 0; total_lines = 0;
for (pbuf = pm->kbd_buf; (i = *pbuf) != 0xFEFF; pbuf += i + 1) for (pbuf = pm->kbd_buf_ptr; (i = *pbuf) != 0xFEFF; pbuf += i + 1)
total_lines += (i ? (i + pm->max_chars - 1) / pm->max_chars : 1); total_lines += (i ? (i + pm->max_chars - 1) / pm->max_chars : 1);
pm->pages = (total_lines + pm->lines - 1) / pm->lines; pm->pages = (total_lines + pm->lines - 1) / pm->lines;

View file

@ -698,7 +698,7 @@ bool settings_save_config(int options)
/* allow user to modify filename */ /* allow user to modify filename */
while (true) { while (true) {
if (!kbd_input(filename, sizeof filename)) { if (!kbd_input(filename, sizeof(filename), NULL)) {
break; break;
} }
else { else {

View file

@ -1905,7 +1905,7 @@ int tagtree_enter(struct tree_context* c)
} }
else else
{ {
rc = kbd_input(searchstring, SEARCHSTR_SIZE); rc = kbd_input(searchstring, SEARCHSTR_SIZE, NULL);
if (rc < 0 || !searchstring[0]) if (rc < 0 || !searchstring[0])
{ {
tagtree_exit(c); tagtree_exit(c);

View file

@ -950,7 +950,7 @@ int create_playlist(void)
else else
snprintf(filename, sizeof filename, "%s/all.m3u8", playlist_dir); snprintf(filename, sizeof filename, "%s/all.m3u8", playlist_dir);
if (kbd_input(filename, MAX_PATH)) if (kbd_input(filename, MAX_PATH, NULL))
return 0; return 0;
splashf(0, "%s %s", str(LANG_CREATING), filename); splashf(0, "%s %s", str(LANG_CREATING), filename);
#endif #endif