[Librem-5-dev] [PATCH] Add more opinionated keyboard layout
Dorota Czaplejewicz
dorota.czaplejewicz at puri.sm
Sat Feb 16 08:31:13 PST 2019
Hi Drew,
I like this patch in general, even though it exposes a problem we haven't solved yet: how to switch between topical layouts.
Regardless if that problem gets solved here or in the rewrite, I'm fine with the new layout. There's one issue though, with the usage of the input_method protocol.
When input_method is available, the text sequences to send when pressing a button are obtained from the button label when the type is `keytype_default`. Because of that, pressing the esc button results in emitting the `esc` string, which is rather jarring. In addition, the esc keycode never gets sent.
Something more appropriate would be not to emit any text, following the example of `keytype_tab`.
Sorry for not documenting this all in the code.
Cheers,
Dorota
On Fri, 15 Feb 2019 21:30:41 -0500
Drew DeVault <sir at cmpwn.com> wrote:
> More useful for use on sway
> ---
> I understand if you aren't interested in this patch.
>
> clients/keyboard.c | 33 +++++++++++++++++++++++++--------
> 1 file changed, 25 insertions(+), 8 deletions(-)
>
> diff --git a/clients/keyboard.c b/clients/keyboard.c
> index 7f368bc7..d5543586 100644
> --- a/clients/keyboard.c
> +++ b/clients/keyboard.c
> @@ -98,6 +98,7 @@ enum key_modifier_type {
> modifier_shift = 1,
> modifier_capslock = 2,
> modifier_ctrl = 4,
> + modifier_logo = 64,
> modifier_altgr = 128,
> };
>
> @@ -114,6 +115,7 @@ enum key_type {
> keytype_arrow_right,
> keytype_arrow_down,
> keytype_ctrl,
> + keytype_logo,
> };
>
> struct key {
> @@ -177,15 +179,16 @@ static const struct key normal_keys[] = {
> { keytype_default, "m", "M", "!", NULL, KEY_M, 1},
> { keytype_default, ",", ",", "\\", NULL, KEY_COMMA, 1},
> { keytype_default, ".", ".", "|", NULL, KEY_DOT, 1},
> - { keytype_caps, "ABC", "abc", "ABC", NULL, 0, 1},
> + { keytype_default, "esc", "esc", "esc", NULL, KEY_ESC, 1},
>
> - { keytype_altgr, "123", "123", "abc", NULL, 0, 1},
> - { keytype_space, "", "", "", NULL, 0, 5},
> + { keytype_ctrl, "Ctrl", "Ctrl", "Ctrl", NULL, 0, 2},
> + { keytype_logo, "Logo", "Logo", "Logo", NULL, 0, 2},
> + { keytype_space, "", "", "", NULL, 0, 3},
> { keytype_arrow_up, "↑", "↑", "↑", NULL, 0, 1},
> { keytype_arrow_left, "←", "←", "←", NULL, 0, 1},
> { keytype_arrow_right, "→", "→", "→", NULL, 0, 1},
> { keytype_arrow_down, "↓", "↓", "↓", NULL, 0, 1},
> - { keytype_ctrl, "Ctrl", "Ctrl", "Ctrl", NULL, 0, 2}
> + { keytype_altgr, "123", "123", "abc", NULL, 0, 1},
> };
>
> static const struct key polish_keys[] = {
> @@ -369,6 +372,7 @@ struct keyboard {
>
> enum keyboard_state state;
> bool ctrl_on;
> + bool logo_on;
>
> uint32_t scale; // output scale
> double width; // width in output units
> @@ -440,7 +444,8 @@ draw_key(struct keyboard *keyboard, const struct key *key, cairo_t *cr,
> key->width * key_width, key_height);
> cairo_clip(cr);
>
> - if (key->key_type == keytype_ctrl && keyboard->ctrl_on) {
> + if ((key->key_type == keytype_ctrl && keyboard->ctrl_on) ||
> + (key->key_type == keytype_logo && keyboard->logo_on)) {
> cairo_rectangle(cr,
> col * key_width, row * key_height,
> key->width * key_width, key_height);
> @@ -677,6 +682,7 @@ append(char *s1, const char *s2)
>
> static void keyboard_update_mods(struct keyboard *keyboard) {
> unsigned mods = keyboard->ctrl_on ? modifier_ctrl : modifier_none;
> + mods |= keyboard->logo_on ? modifier_logo : modifier_none;
> unsigned locked = 0;
> switch(keyboard->state) {
> case KEYBOARD_STATE_DEFAULT:
> @@ -717,7 +723,9 @@ keyboard_handle_key(struct keyboard *keyboard, const struct layout *layout,
>
> switch (key->key_type) {
> case keytype_default:
> - if (!keyboard->keyboard->current.active || keyboard->ctrl_on) {
> + if (!keyboard->keyboard->current.active
> + || keyboard->ctrl_on
> + || keyboard->logo_on) {
> zwp_virtual_keyboard_v1_key(keyboard->keyboard->virtual_keyboard,
> time, key->keycode, key_state);
> break;
> @@ -734,7 +742,8 @@ keyboard_handle_key(struct keyboard *keyboard, const struct layout *layout,
> if (!keyboard->keyboard->current.active
> || (strlen(keyboard->keyboard->preedit_string) == 0
> && strlen(keyboard->keyboard->current.surrounding_text) == 0)
> - || keyboard->ctrl_on) {
> + || keyboard->ctrl_on
> + || keyboard->logo_on) {
> zwp_virtual_keyboard_v1_key(keyboard->keyboard->virtual_keyboard,
> time,
> KEY_BACKSPACE, key_state);
> @@ -760,7 +769,9 @@ keyboard_handle_key(struct keyboard *keyboard, const struct layout *layout,
> time, KEY_ENTER, key_state);
> break;
> case keytype_space:
> - if (!keyboard->keyboard->current.active || keyboard->ctrl_on) {
> + if (!keyboard->keyboard->current.active
> + || keyboard->ctrl_on
> + || keyboard->logo_on) {
> zwp_virtual_keyboard_v1_key(keyboard->keyboard->virtual_keyboard,
> time, KEY_SPACE, key_state);
> break;
> @@ -865,6 +876,12 @@ keyboard_handle_key(struct keyboard *keyboard, const struct layout *layout,
> keyboard->ctrl_on ^= true;
> keyboard_update_mods(keyboard);
> break;
> + case keytype_logo:
> + if (state != WL_POINTER_BUTTON_STATE_PRESSED)
> + break;
> + keyboard->logo_on ^= true;
> + keyboard_update_mods(keyboard);
> + break;
> default:
> dbg("Keytype invalid\n");
> }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.community.puri.sm/pipermail/librem-5-dev/attachments/20190216/62aec1c3/attachment.sig>
More information about the Librem-5-dev
mailing list