Skip to content

Commit

Permalink
Add locale_extra_keys keyboard attribute
Browse files Browse the repository at this point in the history
This attribute can be used to disable adding the extra keys from
method.xml.
  • Loading branch information
Julow committed Jul 6, 2024
1 parent 99367a9 commit 3164215
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/Custom-layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The `<keyboard>`...`</keyboard>` pair follows the declaration tag and encloses t
* `script`: The (main) writing system that the keyboard supports. The possible values are `arabic`, `armenian`, `bengali`, `cyrillic`, `devanagari`, `gujarati`, `hangul`, `hebrew`, `latin`, `persian`, `shavian`, and `urdu`. It defaults to `latin`.
* `numpad_script`: The script to use for the numpad. This is useful for scripts where a different, non-ASCII set of numerals is used, like Devanagari and Arabic. It defaults to the same as `script`.
* `bottom_row`: Whether or not to show the common bottom row. It accepts `true` or `false`, and defaults to `true`. If your custom layout defines the bottom row, then specify `bottom_row=false` to disable the built-in bottom row.
* `locale_extra_keys`: Whether language-dependent extra keys from [method.xml](../res/xml/method.xml) should be added to this layout. It accepts `true` or `false`, and defaults to `true`.

## Row
The `<row>`...`</row>` pair encloses one row on the keyboard. It has only one optional property:
Expand Down
2 changes: 1 addition & 1 deletion srcs/juloo.keyboard2/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public KeyboardData modify_layout(KeyboardData kw)
extra_keys.put(KeyValue.getKeyByName("config"), KeyboardData.PreferredPos.ANYWHERE);
extra_keys.putAll(extra_keys_param);
extra_keys.putAll(extra_keys_custom);
if (extra_keys_subtype != null)
if (extra_keys_subtype != null && kw.locale_extra_keys)
{
Set<KeyValue> present = new HashSet<KeyValue>();
present.addAll(kw.getKeys().keySet());
Expand Down
12 changes: 8 additions & 4 deletions srcs/juloo.keyboard2/KeyboardData.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public final class KeyboardData
public final String name;
/** Whether the bottom row should be added. */
public final boolean bottom_row;
/** Whether extra keys from [method.xml] should be added to this layout. */
public final boolean locale_extra_keys;
/** Position of every keys on the layout, see [getKeys()]. */
private Map<KeyValue, KeyPos> _key_pos = null;

Expand Down Expand Up @@ -234,6 +236,7 @@ private static KeyboardData parse_keyboard(XmlPullParser parser) throws Exceptio
if (!expect_tag(parser, "keyboard"))
throw error(parser, "Expected tag <keyboard>");
boolean bottom_row = attribute_bool(parser, "bottom_row", true);
boolean locale_extra_keys = attribute_bool(parser, "locale_extra_keys", true);
float specified_kw = attribute_float(parser, "width", 0f);
String script = parser.getAttributeValue(null, "script");
if (script != null && script.equals(""))
Expand Down Expand Up @@ -263,7 +266,7 @@ else if (numpad_script.equals(""))
}
}
float kw = (specified_kw != 0f) ? specified_kw : compute_max_width(rows);
return new KeyboardData(rows, kw, modmap, script, numpad_script, name, bottom_row);
return new KeyboardData(rows, kw, modmap, script, numpad_script, name, bottom_row, locale_extra_keys);
}

private static float compute_max_width(List<Row> rows)
Expand All @@ -282,7 +285,7 @@ private static Row parse_row(XmlPullParser parser) throws Exception
}

protected KeyboardData(List<Row> rows_, float kw, Modmap mm, String sc,
String npsc, String name_, boolean bottom_row_)
String npsc, String name_, boolean bottom_row_, boolean locale_extra_keys_)
{
float kh = 0.f;
for (Row r : rows_)
Expand All @@ -295,13 +298,14 @@ protected KeyboardData(List<Row> rows_, float kw, Modmap mm, String sc,
keysWidth = Math.max(kw, 1f);
keysHeight = kh;
bottom_row = bottom_row_;
locale_extra_keys = locale_extra_keys_;
}

/** Copies the fields of an other keyboard, with rows changed. */
/** Copies the fields of a keyboard, with rows changed. */
protected KeyboardData(KeyboardData src, List<Row> rows)
{
this(rows, compute_max_width(rows), src.modmap, src.script,
src.numpad_script, src.name, src.bottom_row);
src.numpad_script, src.name, src.bottom_row, src.locale_extra_keys);
}

public static class Row
Expand Down

0 comments on commit 3164215

Please sign in to comment.