Merge branch 'text' into 'master'

Text property

Closes #153

See merge request Librem5/squeekboard!257
This commit is contained in:
Dorota Czaplejewicz
2019-11-28 09:19:30 +00:00
12 changed files with 306 additions and 334 deletions

View File

@ -25,22 +25,22 @@ views:
- "Q W E R T Z U I O P"
- "A S D F G H J K L"
- "Shift_L Y X C V B N M BackSpace"
- "show_numbers show_eschars preferences space ! ? Return"
- "show_numbers show_dechars preferences space ! ? Return"
numbers:
- "1 2 3 4 5 6 7 8 9 0"
- "@ # € % & - _ + ( )"
- "show_symbols , \" ' : = < > BackSpace"
- "show_letters show_eschars preferences space , . Return"
- "show_letters show_dechars preferences space , . Return"
symbols:
- "~ ` ´ | · √ µ ÷ × ¶"
- "© ® £ $ ¥ ^ ° * { }"
- "show_numbers \\ / § π τ [ ] BackSpace"
- "show_letters show_eschars preferences space , . Return"
eschars:
- "show_letters show_dechars preferences space , . Return"
dechars:
- "ä è é ö ü Ä È É Ö Ü"
- "à â ê î ô À Â È Î Ô"
- "show_numbers « » ç Ç æ œ ß BackSpace"
- "show_letters show_eschars preferences space „ “ Return"
- "show_letters show_dechars preferences space „ “ Return"
buttons:
Shift_L:
@ -73,17 +73,16 @@ buttons:
set_view: "symbols"
outline: "altline"
label: "*/="
show_eschars:
show_dechars:
action:
locking:
lock_view: "eschars"
lock_view: "dechars"
unlock_view: "base"
outline: "altline"
label: "äÄ"
space:
outline: "spaceline"
label: " "
keysym: "space"
text: " "
Return:
outline: "altline"
icon: "key-enter"

View File

@ -53,6 +53,7 @@ buttons:
BackSpace:
outline: "altline"
icon: "edit-clear-symbolic"
keysym: "BackSpace"
preferences:
action: "show_prefs"
outline: "altline"
@ -86,111 +87,112 @@ buttons:
label: "αι"
period:
outline: "altline"
label: "."
text: "."
space:
outline: spaceline
label: " "
text: " "
Return:
outline: "wide"
icon: "key-enter"
keysym: "Return"
aring:
label: "å"
text: "å"
Aring:
label: "Å"
text: "Å"
oslash:
label: "ø"
text: "ø"
Oslash:
label: "Ø"
text: "Ø"
ae:
label: "æ"
text: "æ"
AE:
label: "Æ"
text: "Æ"
asterisk:
label: "*"
text: "*"
asciitilde:
label: "~"
text: "~"
quoteleft:
label: "`"
text: "`"
bar:
label: "|"
text: "|"
U00B7:
label: "·"
text: "·"
squareroot:
label: "√"
text: "√"
Greek_pi:
label: "π"
text: "π"
division:
label: "÷"
text: "÷"
multiply:
label: "×"
text: "×"
paragraph:
label: "¶"
text: "¶"
Greek_tau:
label: "τ"
text: "τ"
copyright:
label: "©"
text: "©"
numbersign:
label: "#"
text: "#"
U00AE:
label: "®"
text: "®"
at:
label: "@"
text: "@"
dollar:
label: "$"
text: "$"
U00A3:
label: "£"
text: "£"
percent:
label: "%"
text: "%"
EuroSign:
label: "€"
text: "€"
ampersand:
label: "&"
text: "&"
U00A5:
label: "¥"
text: "¥"
minus:
label: "-"
text: "-"
asciicircum:
label: "^"
text: "^"
underscore:
label: "_"
text: "_"
degree:
label: "°"
text: "°"
plus:
label: "+"
text: "+"
equal:
label: "="
text: "="
parenleft:
label: "("
text: "("
parenright:
label: ")"
text: ")"
braceleft:
label: "{"
text: "{"
braceright:
label: "}"
text: "}"
comma:
label: ","
text: ","
backslash:
label: "\\"
text: "\\"
slash:
label: "/"
text: "/"
quotedbl:
label: "\""
text: "\""
quoteright:
label: "'"
text: "'"
less:
label: "<"
text: "<"
greater:
label: ">"
text: ">"
colon:
label: ":"
text: ":"
semicolon:
label: ";"
text: ";"
exclam:
label: "!"
text: "!"
question:
label: "?"
text: "?"
bracketleft:
label: "["
text: "["
bracketright:
label: "]"
text: "]"

View File

@ -51,6 +51,7 @@ buttons:
BackSpace:
outline: "altline"
icon: "edit-clear-symbolic"
keysym: "BackSpace"
preferences:
action: "show_prefs"
outline: "default"
@ -80,14 +81,14 @@ buttons:
period:
outline: "default"
label: "."
text: "."
space:
outline: "spaceline"
label: " "
text: " "
Return:
outline: "altline"
icon: "key-enter"
keysym: "Return"
colon:
label: ":"
"\"":
keysym: "quotedbl"
text: ":"

View File

@ -46,6 +46,7 @@ buttons:
BackSpace:
outline: "altline"
icon: "edit-clear-symbolic"
keysym: "BackSpace"
preferences:
action: "show_prefs"
outline: "altline"
@ -69,108 +70,109 @@ buttons:
outline: altline
space:
outline: spaceline
label: " "
text: " "
Return:
outline: "wide"
icon: "key-enter"
keysym: "Return"
aring:
label: "å"
text: "å"
Aring:
label: "Å"
text: "Å"
ouml:
label: "ö"
text: "ö"
Ouml:
label: "Ö"
text: "Ö"
auml:
label: "ä"
text: "ä"
Auml:
label: "Ä"
text: "Ä"
asterisk:
label: "*"
text: "*"
asciitilde:
label: "~"
text: "~"
quoteleft:
label: "`"
text: "`"
bar:
label: "|"
text: "|"
U00B7:
label: "·"
text: "·"
squareroot:
label: "√"
text: "√"
Greek_pi:
label: "π"
text: "π"
division:
label: "÷"
text: "÷"
multiply:
label: "×"
text: "×"
paragraph:
label: "¶"
text: "¶"
Greek_tau:
label: "τ"
text: "τ"
copyright:
label: "©"
text: "©"
numbersign:
label: "#"
text: "#"
U00AE:
label: "®"
text: "®"
at:
label: "@"
text: "@"
dollar:
label: "$"
text: "$"
U00A3:
label: "£"
text: "£"
percent:
label: "%"
text: "%"
EuroSign:
label: "€"
text: "€"
ampersand:
label: "&"
text: "&"
U00A5:
label: "¥"
text: "¥"
minus:
label: "-"
text: "-"
asciicircum:
label: "^"
text: "^"
underscore:
label: "_"
text: "_"
degree:
label: "°"
text: "°"
plus:
label: "+"
text: "+"
equal:
label: "="
text: "="
parenleft:
label: "("
text: "("
parenright:
label: ")"
text: ")"
braceleft:
label: "{"
text: "{"
braceright:
label: "}"
text: "}"
comma:
label: ","
text: ","
backslash:
label: "\\"
text: "\\"
slash:
label: "/"
text: "/"
quotedbl:
label: "\""
text: "\""
quoteright:
label: "'"
text: "'"
less:
label: "<"
text: "<"
greater:
label: ">"
text: ">"
colon:
label: ":"
text: ":"
semicolon:
label: ";"
text: ";"
exclam:
label: "!"
text: "!"
question:
label: "?"
text: "?"
bracketleft:
label: "["
text: "["
bracketright:
label: "]"
text: "]"

View File

@ -53,6 +53,7 @@ buttons:
BackSpace:
outline: "altline"
icon: "edit-clear-symbolic"
keysym: "BackSpace"
preferences:
action: "show_prefs"
outline: "default"
@ -91,6 +92,7 @@ buttons:
Return:
outline: "altline"
icon: "key-enter"
keysym: "Return"
colon:
label: ":"
"\"":

View File

@ -225,7 +225,7 @@ buttons:
space:
outline: "default-wide"
label: "␣"
keysym: "U3000"
text: " "
# switch to number view
numbers:
action:

View File

@ -26,13 +26,13 @@ views:
- "show_numbers preferences space . Return"
numbers:
- "1 2 3 4 5 6 7 8 9 0"
- "at numbersign dollar percent ampersand minus underscore plus parenleft parenright"
- "show_symbols comma quotedbl quoteright colon semicolon exclam question BackSpace"
- "@ # $ % & - _ + ( )"
- "show_symbols , \" ' : ; ! ? BackSpace"
- "show_letters preferences space . Return"
symbols:
- "asciitilde quoteleft bar U00B7 squareroot Greek_pi Greek_tau division multiply paragraph"
- "copyright U00AE U00A3 EuroSign U00A5 asciicircum degree asterisk braceleft braceright"
- "show_numbers backslash slash less greater equal bracketleft bracketright BackSpace"
- "~ ` | U00B7 squareroot Greek_pi Greek_tau division multiply paragraph"
- "copyright U00AE U00A3 EuroSign U00A5 asciicircum degree * { }"
- "show_numbers \\ / < > = [ ] BackSpace"
- "show_letters preferences space . Return"
buttons:
@ -46,6 +46,7 @@ buttons:
BackSpace:
outline: "altline"
icon: "edit-clear-symbolic"
keysym: "BackSpace"
preferences:
action: "show_prefs"
outline: "altline"
@ -69,108 +70,37 @@ buttons:
outline: altline
space:
outline: spaceline
label: " "
text: " "
Return:
outline: "wide"
icon: "key-enter"
aring:
label: "å"
Aring:
label: "Å"
oslash:
label: "ø"
Oslash:
label: "Ø"
ae:
label: "æ"
AE:
label: "Æ"
asterisk:
label: "*"
asciitilde:
label: "~"
quoteleft:
label: "`"
bar:
label: "|"
keysym: "Return"
U00B7:
label: "·"
text: "·"
squareroot:
label: "√"
text: "√"
Greek_pi:
label: "π"
text: "π"
division:
label: "÷"
text: "÷"
multiply:
label: "×"
text: "×"
paragraph:
label: "¶"
text: "¶"
Greek_tau:
label: "τ"
text: "τ"
copyright:
label: "©"
numbersign:
label: "#"
text: "©"
U00AE:
label: "®"
at:
label: "@"
dollar:
label: "$"
text: "®"
U00A3:
label: "£"
percent:
label: "%"
text: "£"
EuroSign:
label: "€"
ampersand:
label: "&"
text: "€"
U00A5:
label: "¥"
minus:
label: "-"
text: "¥"
asciicircum:
label: "^"
underscore:
label: "_"
text: "^"
degree:
label: "°"
plus:
label: "+"
equal:
label: "="
parenleft:
label: "("
parenright:
label: ")"
braceleft:
label: "{"
braceright:
label: "}"
comma:
label: ","
backslash:
label: "\\"
slash:
label: "/"
quotedbl:
label: "\""
quoteright:
label: "'"
less:
label: "<"
greater:
label: ">"
colon:
label: ":"
semicolon:
label: ";"
exclam:
label: "!"
question:
label: "?"
bracketleft:
label: "["
bracketright:
label: "]"
text: "°"

View File

@ -22,22 +22,24 @@ buttons:
BackSpace:
outline: "altline"
icon: "edit-clear-symbolic"
keysym: "BackSpace"
space:
outline: spaceline
label: " "
text: " "
Return:
outline: outline7
icon: "key-enter"
keysym: "BackSpace"
asterisk:
label: "*"
text: "*"
numbersign:
label: "#"
text: "#"
minus:
label: "-"
text: "-"
plus:
label: "+"
text: "+"
parenleft:
label: "("
text: "("
parenright:
label: ")"
text: ")"

View File

@ -46,6 +46,7 @@ buttons:
BackSpace:
outline: "altline"
icon: "edit-clear-symbolic"
keysym: "BackSpace"
preferences:
action: "show_prefs"
outline: "altline"
@ -69,96 +70,97 @@ buttons:
outline: altline
space:
outline: spaceline
label: " "
text: " "
Return:
outline: "wide"
icon: "key-enter"
keysym: "Return"
asterisk:
label: "*"
text: "*"
asciitilde:
label: "~"
text: "~"
quoteleft:
label: "`"
text: "`"
bar:
label: "|"
text: "|"
U00B7:
label: "·"
text: "·"
squareroot:
label: "√"
text: "√"
Greek_pi:
label: "π"
text: "π"
division:
label: "÷"
text: "÷"
multiply:
label: "×"
text: "×"
paragraph:
label: "¶"
text: "¶"
Greek_tau:
label: "τ"
text: "τ"
copyright:
label: "©"
text: "©"
numbersign:
label: "#"
text: "#"
U00AE:
label: "®"
text: "®"
at:
label: "@"
text: "@"
dollar:
label: "$"
text: "$"
U00A3:
label: "£"
text: "£"
percent:
label: "%"
text: "%"
EuroSign:
label: "€"
text: "€"
ampersand:
label: "&"
text: "&"
U00A5:
label: "¥"
text: "¥"
minus:
label: "-"
text: "-"
asciicircum:
label: "^"
text: "^"
underscore:
label: "_"
text: "_"
degree:
label: "°"
text: "°"
plus:
label: "+"
text: "+"
equal:
label: "="
text: "="
parenleft:
label: "("
text: "("
parenright:
label: ")"
text: ")"
braceleft:
label: "{"
text: "{"
braceright:
label: "}"
text: "}"
comma:
label: ","
text: ","
backslash:
label: "\\"
text: "\\"
slash:
label: "/"
text: "/"
quotedbl:
label: "\""
text: "\""
quoteright:
label: "'"
text: "'"
less:
label: "<"
text: "<"
greater:
label: ">"
text: ">"
colon:
label: ":"
text: ":"
semicolon:
label: ";"
text: ";"
exclam:
label: "!"
text: "!"
question:
label: "?"
text: "?"
bracketleft:
label: "["
text: "["
bracketright:
label: "]"
text: "]"

View File

@ -46,6 +46,7 @@ buttons:
BackSpace:
outline: "altline"
icon: "edit-clear-symbolic"
keysym: "BackSpace"
preferences:
action: "show_prefs"
outline: "special"
@ -72,14 +73,13 @@ buttons:
label: "*/="
period:
outline: "special"
label: "."
text: "."
space:
outline: "spaceline"
label: " "
text: " "
Return:
outline: "wide"
icon: "key-enter"
keysym: "Return"
colon:
label: ":"
"\"":
keysym: "quotedbl"
text: ":"

View File

@ -18,22 +18,22 @@ views:
- "q w e r t y u i o p"
- "a s d f g h j k l"
- "Shift_L z x c v b n m BackSpace"
- "show_numbers preferences space period Return"
- "show_numbers preferences space . Return"
upper:
- "Q W E R T Y U I O P"
- "A S D F G H J K L"
- "Shift_L Z X C V B N M BackSpace"
- "show_numbers preferences space period Return"
- "show_numbers preferences space . Return"
numbers:
- "1 2 3 4 5 6 7 8 9 0"
- "@ # $ % & - _ + ( )"
- "show_symbols , \" ' colon ; ! ? BackSpace"
- "show_letters preferences space period Return"
- "show_letters preferences space . Return"
symbols:
- "~ ` | · √ π τ ÷ × ¶"
- "© ® £ € ¥ ^ ° * { }"
- "show_numbers_from_symbols \\ / < > = [ ] BackSpace"
- "show_letters preferences space period Return"
- "show_letters preferences space . Return"
buttons:
Shift_L:
@ -46,6 +46,7 @@ buttons:
BackSpace:
outline: "altline"
icon: "edit-clear-symbolic"
keysym: "BackSpace"
preferences:
action: "show_prefs"
outline: "special"
@ -70,16 +71,15 @@ buttons:
set_view: "symbols"
outline: "altline"
label: "*/="
period:
".":
outline: "special"
label: "."
text: "."
space:
outline: "spaceline"
label: " "
text: " "
Return:
outline: "wide"
icon: "key-enter"
keysym: "Return"
colon:
label: ":"
"\"":
keysym: "quotedbl"
text: ":"

View File

@ -234,22 +234,28 @@ struct Bounds {
/// Buttons are embedded in a single string
type ButtonIds = String;
/// All info about a single button
/// Buttons can have multiple instances though.
#[derive(Debug, Default, Deserialize, PartialEq)]
#[serde(deny_unknown_fields)]
struct ButtonMeta {
/// Action other than keysym (conflicts with keysym)
/// Special action to perform on activation. Conflicts with keysym, text.
action: Option<Action>,
/// The name of the outline. If not present, will be "default"
outline: Option<String>,
/// FIXME: start using it
/// The name of the XKB keysym to emit on activation.
/// Conflicts with action, text
keysym: Option<String>,
/// If not present, will be derived from the button ID
/// The text to submit on activation. Will be derived from ID if not present
/// Conflicts with action, keysym
text: Option<String>,
/// If not present, will be derived from text or the button ID
label: Option<String>,
/// Conflicts with label
icon: Option<String>,
/// The name of the outline. If not present, will be "default"
outline: Option<String>,
}
#[derive(Debug, Deserialize, PartialEq)]
#[derive(Debug, Deserialize, PartialEq, Clone)]
#[serde(deny_unknown_fields)]
enum Action {
#[serde(rename="locking")]
@ -454,50 +460,27 @@ fn create_action<H: WarningHandler>(
xkb::keysym_from_name(name, xkb::KEYSYM_NO_FLAGS) != xkb::KEY_NoSymbol
}
let keysyms = match &symbol_meta.action {
// Non-submit action
Some(_) => Vec::new(),
// Submit action
None => match &symbol_meta.keysym {
// Keysym given explicitly
Some(keysym) => vec!(match keysym_valid(keysym.as_str()) {
true => keysym.clone(),
false => {
warning_handler.handle(&format!(
"Keysym name invalid: {}",
keysym,
));
"space".into() // placeholder
},
}),
// Keysyms left open to derive
// TODO: when button name is meant diretly as xkb keysym name,
// mark it so, e.g. with a "#"
None => match keysym_valid(name) {
// Button name is actually a valid xkb name
true => vec!(String::from(name)),
// Button name is not a valid xkb name,
// so assume it's a literal string to be submitted
false => {
if name.chars().count() == 0 {
// A name read from yaml with no valid Unicode.
// Highly improbable, but let's be safe.
warning_handler.handle(&format!(
"Key {} doesn't have any characters",
name,
));
vec!("space".into()) // placeholder
} else {
name.chars().map(|codepoint| {
let codepoint_string = codepoint.to_string();
match keysym_valid(codepoint_string.as_str()) {
true => codepoint_string,
false => format!("U{:04X}", codepoint as u32),
}
}).collect()
}
},
},
enum SubmitData {
Action(Action),
Text(String),
Keysym(String),
};
let submission = match (
&symbol_meta.action,
&symbol_meta.keysym,
&symbol_meta.text
) {
(Some(action), None, None) => SubmitData::Action(action.clone()),
(None, Some(keysym), None) => SubmitData::Keysym(keysym.clone()),
(None, None, Some(text)) => SubmitData::Text(text.clone()),
(None, None, None) => SubmitData::Text(name.into()),
_ => {
warning_handler.handle(&format!(
"Button {} has more than one of (action, keysym, text)",
name
));
SubmitData::Text("".into())
},
};
@ -518,14 +501,16 @@ fn create_action<H: WarningHandler>(
}
}
match &symbol_meta.action {
Some(Action::SetView(view_name)) => ::action::Action::SetLevel(
match submission {
SubmitData::Action(
Action::SetView(view_name)
) => ::action::Action::SetLevel(
filter_view_name(
name, view_name.clone(), &view_names,
warning_handler,
)
),
Some(Action::Locking {
SubmitData::Action(Action::Locking {
lock_view, unlock_view
}) => ::action::Action::LockLevel {
lock: filter_view_name(
@ -541,11 +526,44 @@ fn create_action<H: WarningHandler>(
warning_handler,
),
},
Some(Action::ShowPrefs) => ::action::Action::ShowPreferences,
None => ::action::Action::Submit {
SubmitData::Action(
Action::ShowPrefs
) => ::action::Action::ShowPreferences,
SubmitData::Keysym(keysym) => ::action::Action::Submit {
text: None,
keys: keysyms.into_iter().map(::action::KeySym).collect(),
keys: vec!(::action::KeySym(
match keysym_valid(keysym.as_str()) {
true => keysym.clone(),
false => {
warning_handler.handle(&format!(
"Keysym name invalid: {}",
keysym,
));
"space".into() // placeholder
},
}
)),
},
SubmitData::Text(text) => ::action::Action::Submit {
text: {
CString::new(text.clone())
.map_err(|e| {
warning_handler.handle(&format!(
"Text {} contains problems: {:?}",
text,
e
));
e
}).ok()
},
keys: text.chars().map(|codepoint| {
let codepoint_string = codepoint.to_string();
::action::KeySym(match keysym_valid(codepoint_string.as_str()) {
true => codepoint_string,
false => format!("U{:04X}", codepoint as u32),
})
}).collect(),
}
}
}
@ -572,6 +590,18 @@ fn create_button<H: WarningHandler>(
} else if let Some(icon) = &button_meta.icon {
::layout::Label::IconName(CString::new(icon.as_str())
.expect("Bad icon"))
} else if let Some(text) = &button_meta.text {
::layout::Label::Text(
CString::new(text.as_str())
.unwrap_or_else(|e| {
warning_handler.handle(&format!(
"Text {} is invalid: {}",
text,
e,
));
CString::new("").unwrap()
})
)
} else {
::layout::Label::Text(cname.clone())
};
@ -642,6 +672,7 @@ mod tests {
icon: None,
keysym: None,
action: None,
text: None,
label: Some("test".into()),
outline: None,
}
@ -785,6 +816,7 @@ mod tests {
".".into() => ButtonMeta {
icon: None,
keysym: None,
text: None,
action: None,
label: Some("test".into()),
outline: None,
@ -795,7 +827,7 @@ mod tests {
&mut PanicWarn,
),
::action::Action::Submit {
text: None,
text: Some(CString::new(".").unwrap()),
keys: vec!(::action::KeySym("U002E".into())),
},
);