Commit acac00bc authored by Dorota Czaplejewicz's avatar Dorota Czaplejewicz
Browse files

Merge branch 'terminal' into 'master'

Fix emoji and number layouts

See merge request Librem5/squeekboard!444
parents d2891294 608be930
Pipeline #66277 passed with stages
in 59 minutes
---
outlines:
default: { width: 35.33, height: 46 }
action: { width: 59, height: 46 }
altline: { width: 52.67, height: 46 }
wide: { width: 59, height: 46 }
spaceline: { width: 140, height: 46 }
special: { width: 44, height: 46 }
small: { width: 59, height: 22 }
views:
base:
- "Ctrl Alt →"
- "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 show_actions Return"
upper:
- "Ctrl Alt PgUp PgDn Home End"
- "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 show_actions Return"
numbers:
- "Ctrl Alt →"
- "1 2 3 4 5 6 7 8 9 0"
- "* # $ / & - _ + ( )"
- "show_symbols , \" ' colon ; ! ? BackSpace"
- "show_letters preferences space period Return"
symbols:
- "Ctrl Alt →"
- "~ ` | · π τ ÷ × ¶"
- "© ® £ ¥ ^ ° @ { }"
- "show_numbers_from_symbols \\ % < > = [ ] BackSpace"
- "show_letters preferences space period Return"
actions:
- "Ctrl Alt PgUp PgDn Home End"
- "F1 F2 F3 F4 F5 F6"
- "F7 F8 F9 F10 F11 F12"
- "Esc Tab Pause Insert Up Del"
- "show_letters Menu Break Left Down Right"
buttons:
Shift_L:
action:
locking:
lock_view: "upper"
unlock_view: "base"
outline: "altline"
icon: "key-shift"
BackSpace:
outline: "altline"
icon: "edit-clear-symbolic"
action: erase
preferences:
action: "show_prefs"
outline: "special"
icon: "keyboard-mode-symbolic"
show_numbers:
action:
set_view: "numbers"
outline: "wide"
label: "123"
show_numbers_from_symbols:
action:
set_view: "numbers"
outline: "altline"
label: "123"
show_letters:
action:
set_view: "base"
outline: "wide"
label: "ABC"
show_symbols:
action:
set_view: "symbols"
outline: "altline"
label: "τ=\\"
show_actions:
action:
set_view: "actions"
outline: "altline"
label: ">_"
period:
outline: "altline"
text: "."
space:
outline: "spaceline"
text: " "
Return:
outline: "wide"
icon: "key-enter"
keysym: "Return"
colon:
text: ":"
F1:
outline: "action"
keysym: "F1"
F2:
outline: "action"
keysym: "F2"
F3:
outline: "action"
keysym: "F3"
F4:
outline: "action"
keysym: "F4"
F5:
outline: "action"
keysym: "F5"
F6:
outline: "action"
keysym: "F6"
F7:
outline: "action"
keysym: "F7"
F8:
outline: "action"
keysym: "F8"
F9:
outline: "action"
keysym: "F9"
F10:
outline: "action"
keysym: "F10"
F11:
outline: "action"
keysym: "F11"
F12:
outline: "action"
keysym: "F12"
Esc:
outline: "action"
keysym: "Escape"
Tab:
outline: "action"
keysym: "Tab"
Del:
outline: "action"
keysym: "Delete"
Insert:
outline: "action"
keysym: "Insert"
Menu:
outline: "action"
keysym: "Menu"
Pause:
outline: "action"
keysym: "Pause"
Break:
outline: "action"
keysym: "Break"
Home:
outline: "small"
keysym: "Home"
End:
outline: "small"
keysym: "End"
PgUp:
outline: "small"
keysym: "Page_Up"
PgDn:
outline: "small"
keysym: "Page_Down"
"↑":
outline: "small"
keysym: "Up"
"↓":
outline: "small"
keysym: "Down"
"←":
outline: "small"
keysym: "Left"
"→":
outline: "small"
keysym: "Right"
Up:
label: "↑"
outline: "action"
keysym: "Up"
Left:
label: "←"
outline: "action"
keysym: "Left"
Down:
label: "↓"
outline: "action"
keysym: "Down"
Right:
label: "→"
outline: "action"
keysym: "Right"
Ctrl:
modifier: "Control"
outline: "small"
label: "Ctrl"
Alt:
modifier: "Alt"
outline: "small"
label: "Alt"
---
outlines:
default: { width: 54, height: 37 }
action: { width: 90, height: 37 }
altline: { width: 81, height: 37 }
wide: { width: 90, height: 37 }
spaceline: { width: 225, height: 37 }
special: { width: 54, height: 37 }
small: { width: 67.4, height: 22 }
views:
base:
- "EscSmall TabSmall Ctrl Alt →"
- "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 show_actions Return"
upper:
- "EscSmall TabSmall Ctrl Alt PgUp PgDn Home End"
- "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 show_actions Return"
numbers:
- "EscSmall TabSmall Ctrl Alt →"
- "1 2 3 4 5 6 7 8 9 0"
- "* # $ / & - _ + ( )"
- "show_symbols , \" ' colon ; ! ? BackSpace"
- "show_letters preferences space period Return"
symbols:
- "EscSmall TabSmall Ctrl Alt →"
- "~ ` | · π τ ÷ × ¶"
- "© ® £ ¥ ^ ° @ { }"
- "show_numbers_from_symbols \\ % < > = [ ] BackSpace"
- "show_letters preferences space period Return"
actions:
- "EscSmall TabSmall Ctrl Alt PgUp PgDn Home End"
- "F1 F2 F3 F4 F5 F6"
- "F7 F8 F9 F10 F11 F12"
- "Esc Tab Pause Insert Up Del"
- "show_letters Menu Break Left Down Right"
buttons:
Shift_L:
action:
locking:
lock_view: "upper"
unlock_view: "base"
outline: "altline"
icon: "key-shift"
BackSpace:
outline: "altline"
icon: "edit-clear-symbolic"
action: erase
preferences:
action: "show_prefs"
outline: "special"
icon: "keyboard-mode-symbolic"
show_numbers:
action:
set_view: "numbers"
outline: "wide"
label: "123"
show_numbers_from_symbols:
action:
set_view: "numbers"
outline: "altline"
label: "123"
show_letters:
action:
set_view: "base"
outline: "wide"
label: "ABC"
show_symbols:
action:
set_view: "symbols"
outline: "altline"
label: "τ=\\"
show_actions:
action:
set_view: "actions"
outline: "altline"
label: ">_"
period:
outline: "altline"
text: "."
space:
outline: "spaceline"
text: " "
Return:
outline: "wide"
icon: "key-enter"
keysym: "Return"
colon:
text: ":"
F1:
outline: "action"
keysym: "F1"
F2:
outline: "action"
keysym: "F2"
F3:
outline: "action"
keysym: "F3"
F4:
outline: "action"
keysym: "F4"
F5:
outline: "action"
keysym: "F5"
F6:
outline: "action"
keysym: "F6"
F7:
outline: "action"
keysym: "F7"
F8:
outline: "action"
keysym: "F8"
F9:
outline: "action"
keysym: "F9"
F10:
outline: "action"
keysym: "F10"
F11:
outline: "action"
keysym: "F11"
F12:
outline: "action"
keysym: "F12"
Esc:
outline: "action"
keysym: "Escape"
EscSmall:
outline: "small"
keysym: "Escape"
label: "Esc"
Tab:
outline: "action"
keysym: "Tab"
TabSmall:
outline: "small"
keysym: "Tab"
label: "Tab"
Del:
outline: "action"
keysym: "Delete"
Insert:
outline: "action"
keysym: "Insert"
Menu:
outline: "action"
keysym: "Menu"
Pause:
outline: "action"
keysym: "Pause"
Break:
outline: "action"
keysym: "Break"
Home:
outline: "small"
keysym: "Home"
End:
outline: "small"
keysym: "End"
PgUp:
outline: "small"
keysym: "Page_Up"
PgDn:
outline: "small"
keysym: "Page_Down"
"↑":
outline: "small"
keysym: "Up"
"↓":
outline: "small"
keysym: "Down"
"←":
outline: "small"
keysym: "Left"
"→":
outline: "small"
keysym: "Right"
Up:
label: "↑"
outline: "action"
keysym: "Up"
Left:
label: "←"
outline: "action"
keysym: "Left"
Down:
label: "↓"
outline: "action"
keysym: "Down"
Right:
label: "→"
outline: "action"
keysym: "Right"
Ctrl:
modifier: "Control"
outline: "small"
label: "Ctrl"
Alt:
modifier: "Alt"
outline: "small"
label: "Alt"
......@@ -139,7 +139,7 @@ eekboard_context_service_use_layout(EekboardContextService *context, struct sque
// overlay is "Normal" for most layouts, we will only look for "terminal" in rust code.
// for now just avoid passing a null pointer
if (overlay_name == NULL) {
overlay_name = "Normal"; // fallback to Normal
overlay_name = ""; // fallback to Normal
}
// generic part follows
......
......@@ -77,7 +77,6 @@ pub mod c {
}
const FALLBACK_LAYOUT_NAME: &str = "us";
const FALLBACK_GENERIC_LAYOUT_NAME: &str = "terminal";
#[derive(Debug)]
pub enum LoadError {
......@@ -119,49 +118,60 @@ type LayoutSource = (ArrangementKind, DataSource);
/// Lists possible sources, with 0 as the most preferred one
/// Trying order: native lang of the right kind, native base,
/// fallback lang of the right kind, fallback base
/// The `purpose` argument is not ContentPurpose,
/// but rather ContentPurpose and overlay in one.
fn list_layout_sources(
name: &str,
kind: ArrangementKind,
overlay: &str,
purpose: &str,
keyboards_path: Option<PathBuf>,
) -> Vec<LayoutSource> {
// Just a simplification of often called code.
let add_by_name = |
mut ret: Vec<LayoutSource>,
purpose: &str,
name: &str,
kind: &ArrangementKind,
| -> Vec<LayoutSource> {
let name = if purpose == "" { name.into() }
else { format!("{}/{}", purpose, name) };
if let Some(path) = keyboards_path.clone() {
ret.push((
kind.clone(),
DataSource::File(
path.join(name.to_owned()).with_extension("yaml")
path.join(name.clone())
.with_extension("yaml")
)
))
}
ret.push((
kind.clone(),
DataSource::Resource(name.into())
DataSource::Resource(name)
));
ret
};
// Another grouping.
let add_by_kind = |ret, name: &str, kind| {
let add_by_kind = |ret, purpose: &str, name: &str, kind| {
let ret = match kind {
&ArrangementKind::Base => ret,
kind => add_by_name(
ret,
purpose,
&name_with_arrangement(name.into(), kind),
kind,
),
};
add_by_name(ret, name, &ArrangementKind::Base)
add_by_name(ret, purpose, name, &ArrangementKind::Base)
};
fn name_with_arrangement(name: String, kind: &ArrangementKind) -> String {
fn name_with_arrangement(
name: String,
kind: &ArrangementKind,
) -> String {
match kind {
ArrangementKind::Base => name,
ArrangementKind::Wide => name + "_wide",
......@@ -171,7 +181,7 @@ fn list_layout_sources(
let ret = Vec::new();
// Name as given takes priority.
let ret = add_by_kind(ret, name, &kind);
let ret = add_by_kind(ret, purpose, name, &kind);
// Then try non-alternative name if applicable (`us` for `us+colemak`).
let ret = {
......@@ -181,7 +191,7 @@ fn list_layout_sources(
// The name is already equal to base, so it was already added.
if base == name { ret }
else {
add_by_kind(ret, base, &kind)
add_by_kind(ret, purpose, base, &kind)
}
},
// The layout's base name starts with a "+". Weird but OK.
......@@ -192,14 +202,7 @@ fn list_layout_sources(
}
};
// No other choices left, so give anything.
let mut fallback=FALLBACK_LAYOUT_NAME;
match overlay {
"terminal" => fallback = FALLBACK_GENERIC_LAYOUT_NAME,
_ => fallback = FALLBACK_LAYOUT_NAME,
};
add_by_kind(ret, fallback.into(), &kind)
add_by_kind(ret, purpose, FALLBACK_LAYOUT_NAME.into(), &kind)
}
......@@ -235,20 +238,14 @@ fn load_layout_data_with_fallback(
let path = env::var_os("SQUEEKBOARD_KEYBOARDSDIR")
.map(PathBuf::from)
.or_else(|| xdg::data_path("squeekboard/keyboards"));
// prefix the layout name if we are showing a terminal specific layout
let layout_name = match overlay {
"Normal" => format!("{}", name), // normal keyboard layouts
other => format!("{}-{}", other, name), // terminal and catch-all
};
log_print!(
logging::Level::Debug,
"load_layout_data_with_fallback() -> name:{}, purpose:{:?}, overlay:{}, layout_name:{}",
name, purpose, overlay, &layout_name
name, purpose, overlay, &name
);
for (kind, source) in list_layout_sources(&layout_name, kind, overlay, path) {
for (kind, source) in list_layout_sources(&name, kind, overlay, path) {
let layout = load_layout_data(source.clone());
match layout {
Err(e) => match (e, source) {
......@@ -981,7 +978,7 @@ mod tests {
/// First fallback should be to builtin, not to FALLBACK_LAYOUT_NAME
#[test]
fn fallbacks_order() {
let sources = list_layout_sources("nb", ArrangementKind::Base, "Normal", None);
let sources = list_layout_sources("nb", ArrangementKind::Base, "", None);
assert_eq!(
sources,
......@@ -998,7 +995,7 @@ mod tests {
/// If layout contains a "+", it should reach for what's in front of it too.
#[test]
fn fallbacks_order_base() {
let sources = list_layout_sources("nb+aliens", ArrangementKind::Base, "Normal", None);
let sources = list_layout_sources("nb+aliens", ArrangementKind::Base, "", None);
assert_eq!(
sources,
......@@ -1015,16 +1012,16 @@ mod tests {
#[test]
fn fallbacks_terminal_order_base() {
let sources = list_layout_sources("terminal-nb+aliens", ArrangementKind::Base, "terminal", None);
let sources = list_layout_sources("nb+aliens", ArrangementKind::Base, "terminal", None);
assert_eq!(
sources,
vec!(
(ArrangementKind::Base, DataSource::Resource("terminal-nb+aliens".into())),
(ArrangementKind::Base, DataSource::Resource("terminal-nb".into())),
(ArrangementKind::Base, DataSource::Resource("terminal/nb+aliens".into())),
(ArrangementKind::Base, DataSource::Resource("terminal/nb".into())),
(
ArrangementKind::Base,
DataSource::Resource(FALLBACK_GENERIC_LAYOUT_NAME.into())
DataSource::Resource(format!("terminal/{}", FALLBACK_LAYOUT_NAME))
),
)
);
......
......@@ -80,19 +80,16 @@ const KEYBOARDS: &[(*const str, *const str)] = &[
("us+dvorak_wide", include_str!("../data/keyboards/us+dvorak_wide.yaml")),
// Others
("number", include_str!("../data/keyboards/number.yaml")),
("number/us", include_str!("../data/keyboards/number/us.yaml")),
// Terminal
("terminal-generic", include_str!("../data/keyboards/terminal/generic.yaml")),
("terminal-generic_wide", include_str!("../data/keyboards/terminal/generic_wide.yaml")),
("terminal/fr", include_str!("../data/keyboards/terminal/fr.yaml")),
("terminal-fr", include_str!("../data/keyboards/terminal/fr.yaml")),
("terminal-us", include_str!("../data/keyboards/terminal/us.yaml")),