diff --git a/src/core/layout.rs b/src/core/layout.rs index 347e639..ff6a354 100644 --- a/src/core/layout.rs +++ b/src/core/layout.rs @@ -519,6 +519,7 @@ const KEYSYMS: [(&str, Keysym, &str); 21] = [ struct LayoutFile { rows: Vec>, + has_bottom_row: bool, width: f64, height: f64, row_width: f64, @@ -581,12 +582,21 @@ impl LayoutFile { self.row_width = 0.0; } + fn start_keyboard(&mut self, attrs: &HashMap<&str, &str>) + { + if *attrs.get("bottom_row").unwrap_or(&"") == "false" { + self.has_bottom_row = false; + } + } + fn start_elem(&mut self, name: &str, attrs: &HashMap<&str, &str>) { if name == "key" { self.start_key(attrs); } else if name == "row" { self.start_row(); + } else if name == "keyboard" { + self.start_keyboard(attrs); } } @@ -612,6 +622,7 @@ impl LayoutFile { { let mut layout = LayoutFile { rows: Vec::new(), + has_bottom_row: true, width: 0.0, height: 0.0, row_width: 0.0, @@ -707,27 +718,29 @@ impl Layout { text_supp: false, }; - let path = dir.join("bottom_row.xml"); - let bottom_row = LayoutFile::load(path)?; + if main_layout.has_bottom_row { + let path = dir.join("bottom_row.xml"); + let bottom_row = LayoutFile::load(path)?; - let old_height = layout.height; - layout.height += bottom_row.height; + let old_height = layout.height; + layout.height += bottom_row.height; - layout.rows.reserve(bottom_row.rows.len()); - for row in bottom_row.rows { - let mut new_row = Vec::with_capacity(row.len()); + layout.rows.reserve(bottom_row.rows.len()); + for row in bottom_row.rows { + let mut new_row = Vec::with_capacity(row.len()); - for key in row { - new_row.push(Key { - parts: key.parts, - x1: key.x1 * layout.width / bottom_row.width, - y1: old_height + key.y1, - x2: key.x2 * layout.width / bottom_row.width, - y2: old_height + key.y2, - }); + for key in row { + new_row.push(Key { + parts: key.parts, + x1: key.x1 * layout.width / bottom_row.width, + y1: old_height + key.y1, + x2: key.x2 * layout.width / bottom_row.width, + y2: old_height + key.y2, + }); + } + + layout.rows.push(new_row); } - - layout.rows.push(new_row); } Ok(layout)