mirror of
https://gitlab.freedesktop.org/wayland/weston.git
synced 2026-05-07 21:18:15 +02:00
clients: keyboard: changed numpad layout
Changed the numeric keys layout to create an easier to use numpad. Adds Numpad floating point number input with checks that such a number always has at max one decimal point. Signed-off-by: Joscha.Wloch <Joscha.Wloch@bruker.com>
This commit is contained in:
parent
d728ee0c1d
commit
90e54338d7
1 changed files with 36 additions and 18 deletions
|
|
@ -151,25 +151,19 @@ static const struct key normal_keys[] = {
|
|||
};
|
||||
|
||||
static const struct key numeric_keys[] = {
|
||||
{ keytype_default, "1", "1", "1", 2},
|
||||
{ keytype_default, "2", "2", "2", 2},
|
||||
{ keytype_default, "3", "3", "3", 2},
|
||||
{ keytype_default, "4", "4", "4", 2},
|
||||
{ keytype_default, "5", "5", "5", 2},
|
||||
{ keytype_default, "6", "6", "6", 2},
|
||||
{ keytype_default, "7", "7", "7", 2},
|
||||
{ keytype_default, "8", "8", "8", 2},
|
||||
{ keytype_default, "9", "9", "9", 2},
|
||||
{ keytype_default, "0", "0", "0", 2},
|
||||
{ keytype_backspace, "<--", "<--", "<--", 4},
|
||||
|
||||
{ keytype_space, "", "", "", 8},
|
||||
{ keytype_enter, "Enter", "Enter", "Enter", 4},
|
||||
{ keytype_arrow_up, "/\\", "/\\", "/\\", 2},
|
||||
{ keytype_arrow_left, "<", "<", "<", 2},
|
||||
{ keytype_arrow_right, ">", ">", ">", 2},
|
||||
{ keytype_arrow_down, "\\/", "\\/", "\\/", 2},
|
||||
{ keytype_style, "", "", "", 4}
|
||||
{ keytype_default, "4", "4", "4", 2},
|
||||
{ keytype_default, "5", "5", "5", 2},
|
||||
{ keytype_default, "6", "6", "6", 2},
|
||||
{ keytype_default, "1", "1", "1", 2},
|
||||
{ keytype_default, "2", "2", "2", 2},
|
||||
{ keytype_default, "3", "3", "3", 2},
|
||||
{ keytype_default, "0", "0", "0", 4},
|
||||
{ keytype_default,".", ".", ".", 2},
|
||||
{ keytype_enter, "Enter", "Enter", "Enter", 3},
|
||||
{ keytype_backspace, "<--", "<--", "<--", 3},
|
||||
};
|
||||
|
||||
static const struct key arabic_keys[] = {
|
||||
|
|
@ -233,8 +227,8 @@ static const struct layout normal_layout = {
|
|||
static const struct layout numeric_layout = {
|
||||
numeric_keys,
|
||||
sizeof(numeric_keys) / sizeof(*numeric_keys),
|
||||
24,
|
||||
2,
|
||||
6,
|
||||
5,
|
||||
"en",
|
||||
ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_LTR
|
||||
};
|
||||
|
|
@ -316,6 +310,19 @@ set_hex_color(cairo_t *cr, uint32_t color)
|
|||
((color >> 24) & 0xff) / 255.0);
|
||||
}
|
||||
|
||||
static bool
|
||||
contains_decimal_point(const char* str)
|
||||
{
|
||||
for (size_t i = 0; i < strlen(str); ++i)
|
||||
{
|
||||
if (str[i] == '.')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static const char *
|
||||
label_from_key(struct keyboard *keyboard,
|
||||
const struct key *key)
|
||||
|
|
@ -633,6 +640,17 @@ keyboard_handle_key(struct keyboard *keyboard, uint32_t time, const struct key *
|
|||
if (state != WL_POINTER_BUTTON_STATE_PRESSED)
|
||||
break;
|
||||
|
||||
// Check if content purpose is number
|
||||
if ((((keyboard->keyboard->content_purpose == ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_DIGITS) ||
|
||||
(keyboard->keyboard->content_purpose == ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NUMBER)) &&
|
||||
contains_decimal_point(label)) &&
|
||||
(contains_decimal_point(keyboard->keyboard->surrounding_text) ||
|
||||
contains_decimal_point(keyboard->keyboard->preedit_string)))
|
||||
{
|
||||
// Do not enter a second decimal point.
|
||||
return;
|
||||
}
|
||||
|
||||
keyboard->keyboard->preedit_string =
|
||||
append(keyboard->keyboard->preedit_string,
|
||||
label);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue