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

Dorota Czaplejewicz dorota.czaplejewicz at puri.sm
Sun Mar 3 08:10:05 PST 2019


On Fri, 22 Feb 2019 10:55:35 -0500
Drew DeVault <sir at cmpwn.com> wrote:

> More useful for use on sway

Thank you, the change is just in. Sorry for the delay.

--Dorota

> ---
>  clients/keyboard.c | 54 ++++++++++++++++++++++++++++------------------
>  1 file changed, 33 insertions(+), 21 deletions(-)
> 
> diff --git a/clients/keyboard.c b/clients/keyboard.c
> index 076c0322..8bce8964 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
>                  && 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/20190303/b87d8b7a/attachment.sig>


More information about the Librem-5-dev mailing list