diff --git a/data/keyboards/de.yaml b/data/keyboards/de.yaml index f71ea5283d0ba2d1aec8196f42c673d3e5d73142..4693e95e452d84c9cb9c041c643e8601c0770caa 100644 --- a/data/keyboards/de.yaml +++ b/data/keyboards/de.yaml @@ -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" diff --git a/data/keyboards/el.yaml b/data/keyboards/el.yaml index 437c6bb06ba160abf4e64ddcab19c34d66e0141d..70ec7be51c550a722814a37c091aa6ae4764d1b7 100644 --- a/data/keyboards/el.yaml +++ b/data/keyboards/el.yaml @@ -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: "]" diff --git a/data/keyboards/es.yaml b/data/keyboards/es.yaml index 7628e982c11346d92b3d5595d5cdf09ea2239229..2d0212020c17a6228cb5a87c0d86ce66c3553ec5 100644 --- a/data/keyboards/es.yaml +++ b/data/keyboards/es.yaml @@ -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: ":" + diff --git a/data/keyboards/fi.yaml b/data/keyboards/fi.yaml index e894902db05369d6e0e2ab5dfdb187660e792338..ce38007d5aad2a4a2cf577fe9c6877f8f9ecce76 100644 --- a/data/keyboards/fi.yaml +++ b/data/keyboards/fi.yaml @@ -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: "]" diff --git a/data/keyboards/it.yaml b/data/keyboards/it.yaml index ca68c78a8af9a8d01cc1ed43a9aff030b9eef465..54b6f19f67c18135952049ed6cc001ad18b46343 100644 --- a/data/keyboards/it.yaml +++ b/data/keyboards/it.yaml @@ -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: ":" "\"": diff --git a/data/keyboards/jp+kana.yaml b/data/keyboards/jp+kana.yaml index b606d6d0be348c79bd11825165819a992063deb9..e0f35cbdd5365adc451c33de9f3c4b66378599dc 100644 --- a/data/keyboards/jp+kana.yaml +++ b/data/keyboards/jp+kana.yaml @@ -225,7 +225,7 @@ buttons: space: outline: "default-wide" label: "␣" - keysym: "U3000" + text: " " # switch to number view numbers: action: diff --git a/data/keyboards/no.yaml b/data/keyboards/no.yaml index 3326bc0c224ddb6e9aee1d0c475dde0e53f28af4..7a502501be9ffbbeda4fd3421561990ba641f9a5 100644 --- a/data/keyboards/no.yaml +++ b/data/keyboards/no.yaml @@ -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: "°" diff --git a/data/keyboards/number.yaml b/data/keyboards/number.yaml index 07cc2531dec0e4b108b945eae4836570969ae07b..2f145aeb246137a877dc07b4bd7fc4786f621d93 100644 --- a/data/keyboards/number.yaml +++ b/data/keyboards/number.yaml @@ -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: ")" diff --git a/data/keyboards/se.yaml b/data/keyboards/se.yaml index 28a476bb6f7e9c4d631ca517afda72df4dbbd179..dae7663fb9c35169150653ad62c572adee2904bb 100644 --- a/data/keyboards/se.yaml +++ b/data/keyboards/se.yaml @@ -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: "]" diff --git a/data/keyboards/us.yaml b/data/keyboards/us.yaml index 60c9dfb6ff5fe18d74cad4de5677bc0fa7d14fe7..4d195ba156a4bf8d8fa1da2f14bec60ff0aae26d 100644 --- a/data/keyboards/us.yaml +++ b/data/keyboards/us.yaml @@ -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: ":" diff --git a/data/keyboards/us_wide.yaml b/data/keyboards/us_wide.yaml index 9942182d1bc402102647a04d099ffa04e9efd69f..1c1cc54ee3218ed708c63df57aad5833f2385a63 100644 --- a/data/keyboards/us_wide.yaml +++ b/data/keyboards/us_wide.yaml @@ -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: ":" diff --git a/src/data.rs b/src/data.rs index f7ca6865675b3f8d59e473328617f87404491714..503716caa52dcd1b90e4c80922a781d66e9d89d6 100644 --- a/src/data.rs +++ b/src/data.rs @@ -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, - /// The name of the outline. If not present, will be "default" - outline: Option, - /// FIXME: start using it + /// The name of the XKB keysym to emit on activation. + /// Conflicts with action, text keysym: Option, - /// 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, + /// If not present, will be derived from text or the button ID label: Option, /// Conflicts with label icon: Option, + /// The name of the outline. If not present, will be "default" + outline: Option, } -#[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( 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( } } - 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( 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( } 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())), }, );