[Librem-5-dev] [PATCH v2] Add more opinionated keyboard layout

Dorota Czaplejewicz dorota.czaplejewicz at puri.sm
Tue Feb 19 04:23:37 PST 2019


On Sat, 16 Feb 2019 11:45:47 -0500
Drew DeVault <sir at cmpwn.com> wrote:

> More useful for use on sway
> ---
Thanks, this is much better. More feedback inline:

>  clients/keyboard.c | 56 ++++++++++++++++++++++++++++------------------
>  1 file changed, 34 insertions(+), 22 deletions(-)
> 
> diff --git a/clients/keyboard.c b/clients/keyboard.c
> index 7f368bc7..ee2cd7cd 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,8 @@ enum key_type {
>      keytype_arrow_right,
>      keytype_arrow_down,
>      keytype_ctrl,
> +    keytype_logo,
> +    keytype_esc,
>  };
>  
>  struct key {
> @@ -165,7 +168,7 @@ static const struct key normal_keys[] = {
>      { keytype_default, "j", "J", "(", NULL, KEY_J, 1},
>      { keytype_default, "k", "K", ")", NULL, KEY_K, 1},
>      { keytype_default, "l", "L", "~", NULL, KEY_L, 1},
> -    { keytype_enter, "↵", "↵", "↵", NULL, 0, 2},
> +    { keytype_enter, "↵", "↵", "↵", NULL, KEY_ENTER, 2},
>  
>      { keytype_caps, "ABC", "abc", "ABC", NULL, 0, 2},
>      { keytype_default, "z", "Z", "/", NULL, KEY_Z, 1},
> @@ -177,15 +180,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_esc, "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[] = {
> @@ -211,7 +215,7 @@ static const struct key polish_keys[] = {
>      { keytype_default, "j", "J", ")", "}", KEY_J, 1},
>      { keytype_default, "k", "K", "ó", "Ó", KEY_K, 1},
>      { keytype_default, "l", "L", "ł", "Ł", KEY_L, 1},
> -    { keytype_enter, "↵", "↵", "↵", NULL, 0, 2},
> +    { keytype_enter, "↵", "↵", "↵", NULL, KEY_ENTER, 2},
>  
>      { keytype_caps, "ABC", "abc", "abc", NULL, 0, 2},
>      { keytype_default, "z", "Z", "ż", "Ż", KEY_Z, 1},
> @@ -248,7 +252,7 @@ static const struct key numeric_keys[] = {
>      { keytype_backspace, "<--", "<--", "<--", NULL, 0, 2},
>  
>      { keytype_space, "", "", "", NULL, 0, 4},
> -    { keytype_enter, "Enter", "Enter", "Enter", NULL, 0, 2},
> +    { keytype_enter, "Enter", "Enter", "Enter", NULL, KEY_ENTER, 2},
>      { keytype_arrow_up, "/\\", "/\\", "/\\", NULL, 0, 1},
>      { keytype_arrow_left, "<", "<", "<", NULL, 0, 1},
>      { keytype_arrow_right, ">", ">", ">", NULL, 0, 1},
> @@ -280,7 +284,7 @@ static const struct key arabic_keys[] = {
>      { keytype_default, "م", "/", "*", NULL, 0,  1},
>      { keytype_default, "ك", ":", "_", NULL, 0,  1},
>      { keytype_default, "د", "\"", "+", NULL, 0,  1},
> -    { keytype_enter, "Enter", "Enter", "Enter", NULL, 0, 2},
> +    { keytype_enter, "Enter", "Enter", "Enter", NULL, KEY_ENTER, 2},
>  
>      { keytype_caps, "Shift", "Base", "Shift", NULL, 0, 2},
>      { keytype_default, "ئ", "~", ")", NULL, 0,  1},
> @@ -369,6 +373,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 +445,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 +683,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 +724,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 +743,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);
> @@ -751,16 +761,20 @@ keyboard_handle_key(struct keyboard *keyboard, const struct layout *layout,
>              virtual_keyboard_send_preedit(keyboard->keyboard, -1);
>          }
>          break;
> +    case keytype_tab:
> +    case keytype_esc:
>      case keytype_enter:
> -        if (state == WL_POINTER_BUTTON_STATE_PRESSED
> +        if (state != WL_POINTER_BUTTON_STATE_PRESSED

Nice find - enter and tab behaviour was different here. Is there a reason you chose "!=" instead of "=="? I made the commit happen before the key press in order to ensure that the "accept" action based on the key press receives the full copy of the entered text, including the not yet finished preedit. In this light, the above line should stay.

I'm also not sure whether esc should commit draft preedit text (as opposed to discarding it), but I will accept either way.

Thanks!
--Dorota
>                  && keyboard->keyboard->current.active) {
>              virtual_keyboard_commit_preedit(keyboard->keyboard);
>          }
>          zwp_virtual_keyboard_v1_key(keyboard->keyboard->virtual_keyboard,
> -                                    time, KEY_ENTER, key_state);
> +                                    time, key->keycode, 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;
> @@ -818,14 +832,6 @@ keyboard_handle_key(struct keyboard *keyboard, const struct layout *layout,
>          }
>          keyboard_update_mods(keyboard);
>          break;
> -    case keytype_tab:
> -        if (state != WL_POINTER_BUTTON_STATE_PRESSED
> -                && keyboard->keyboard->current.active) {
> -            virtual_keyboard_commit_preedit(keyboard->keyboard);
> -        }
> -        zwp_virtual_keyboard_v1_key(keyboard->keyboard->virtual_keyboard,
> -                                    time, KEY_TAB, key_state);
> -        break;
>      case keytype_arrow_up:
>          if (state != WL_POINTER_BUTTON_STATE_PRESSED
>                  && keyboard->keyboard->current.active) {
> @@ -865,6 +871,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/20190219/1741960a/attachment.sig>


More information about the Librem-5-dev mailing list