buttons: Accept "text" and drop xkb keysym derivation

This commit is contained in:
Dorota Czaplejewicz
2019-11-19 18:56:18 +00:00
parent 3aec821f92
commit af6ad1fce6
12 changed files with 300 additions and 334 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -234,22 +234,28 @@ struct Bounds {
/// Buttons are embedded in a single string /// Buttons are embedded in a single string
type ButtonIds = String; type ButtonIds = String;
/// All info about a single button
/// Buttons can have multiple instances though.
#[derive(Debug, Default, Deserialize, PartialEq)] #[derive(Debug, Default, Deserialize, PartialEq)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
struct ButtonMeta { struct ButtonMeta {
/// Action other than keysym (conflicts with keysym) /// Special action to perform on activation. Conflicts with keysym, text.
action: Option<Action>, action: Option<Action>,
/// The name of the outline. If not present, will be "default" /// The name of the XKB keysym to emit on activation.
outline: Option<String>, /// Conflicts with action, text
/// FIXME: start using it
keysym: Option<String>, 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>, label: Option<String>,
/// Conflicts with label /// Conflicts with label
icon: Option<String>, 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)] #[serde(deny_unknown_fields)]
enum Action { enum Action {
#[serde(rename="locking")] #[serde(rename="locking")]
@ -454,50 +460,23 @@ fn create_action<H: WarningHandler>(
xkb::keysym_from_name(name, xkb::KEYSYM_NO_FLAGS) != xkb::KEY_NoSymbol xkb::keysym_from_name(name, xkb::KEYSYM_NO_FLAGS) != xkb::KEY_NoSymbol
} }
let keysyms = match &symbol_meta.action { enum SubmitData {
// Non-submit action Action(Action),
Some(_) => Vec::new(), Text(String),
// Submit action Keysym(String),
None => match &symbol_meta.keysym { };
// Keysym given explicitly
Some(keysym) => vec!(match keysym_valid(keysym.as_str()) { let submission = match (&symbol_meta.action, &symbol_meta.keysym, &symbol_meta.text) {
true => keysym.clone(), (Some(action), None, None) => SubmitData::Action(action.clone()),
false => { (None, Some(keysym), None) => SubmitData::Keysym(keysym.clone()),
warning_handler.handle(&format!( (None, None, Some(text)) => SubmitData::Text(text.clone()),
"Keysym name invalid: {}", (None, None, None) => SubmitData::Text(name.into()),
keysym, _ => {
)); warning_handler.handle(&format!(
"space".into() // placeholder "Button {} has more than one of (action, keysym, text)",
}, name
}), ));
// Keysyms left open to derive SubmitData::Text("".into())
// 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()
}
},
},
}, },
}; };
@ -518,14 +497,16 @@ fn create_action<H: WarningHandler>(
} }
} }
match &symbol_meta.action { type SD = SubmitData;
Some(Action::SetView(view_name)) => ::action::Action::SetLevel(
match submission {
SD::Action(Action::SetView(view_name)) => ::action::Action::SetLevel(
filter_view_name( filter_view_name(
name, view_name.clone(), &view_names, name, view_name.clone(), &view_names,
warning_handler, warning_handler,
) )
), ),
Some(Action::Locking { SD::Action(Action::Locking {
lock_view, unlock_view lock_view, unlock_view
}) => ::action::Action::LockLevel { }) => ::action::Action::LockLevel {
lock: filter_view_name( lock: filter_view_name(
@ -541,11 +522,42 @@ fn create_action<H: WarningHandler>(
warning_handler, warning_handler,
), ),
}, },
Some(Action::ShowPrefs) => ::action::Action::ShowPreferences, SD::Action(Action::ShowPrefs) => ::action::Action::ShowPreferences,
None => ::action::Action::Submit { SD::Keysym(keysym) => ::action::Action::Submit {
text: None, 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
},
}
)),
}, },
SD::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 +584,18 @@ fn create_button<H: WarningHandler>(
} else if let Some(icon) = &button_meta.icon { } else if let Some(icon) = &button_meta.icon {
::layout::Label::IconName(CString::new(icon.as_str()) ::layout::Label::IconName(CString::new(icon.as_str())
.expect("Bad icon")) .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 { } else {
::layout::Label::Text(cname.clone()) ::layout::Label::Text(cname.clone())
}; };
@ -642,6 +666,7 @@ mod tests {
icon: None, icon: None,
keysym: None, keysym: None,
action: None, action: None,
text: None,
label: Some("test".into()), label: Some("test".into()),
outline: None, outline: None,
} }
@ -785,6 +810,7 @@ mod tests {
".".into() => ButtonMeta { ".".into() => ButtonMeta {
icon: None, icon: None,
keysym: None, keysym: None,
text: None,
action: None, action: None,
label: Some("test".into()), label: Some("test".into()),
outline: None, outline: None,
@ -795,7 +821,7 @@ mod tests {
&mut PanicWarn, &mut PanicWarn,
), ),
::action::Action::Submit { ::action::Action::Submit {
text: None, text: Some(CString::new(".").unwrap()),
keys: vec!(::action::KeySym("U002E".into())), keys: vec!(::action::KeySym("U002E".into())),
}, },
); );