On Sun, Apr 18, 2021 at 04:26:05PM +0200, Max Schillinger wrote:
> svkbd allows you to create keys for symbols of the second (=shift) layer by 
> defining them with a modifier included, like:
> 
>     { "|", "|", XK_backslash, 1, XK_Shift_L },
> 
> This key creates a pipe symbol by sending shift + backslash. But 
> unfortunately, this way you can't emit get the original symbol (backslash) 
> anymore. So you still need a separate key for typing a backslash, wasting 
> precious space on the screen.
> 
> The appended patch fixes this by allowing to neutralize the shift by tapping 
> this key with shift. It works both by tapping first shift, then the pipe key 
> on the on-screen keyboard, or by clicking the pipe key with the middle mouse 
> button (assuming XK_Shift_L is set as the button 2 mod).
> 
> This way you can create a "flipped" backslash/pipe key:
> 
>     { "|", "\\", XK_backslash, 1, XK_Shift_L },
> 
> This patch works equally for AltGr symbols in a `de`-based layout. For 
> example:
> 
>     { "~", "+", XK_plus, 1, XK_ISO_Level3_Shift },
> 
> (In the German QWERTZ layout, you enter "~" with AltGr-"+".)
> 
> Best regards,
> Max
> 
> ---
>  svkbd.c | 36 +++++++++++++++++++++++-------------
>  1 file changed, 23 insertions(+), 13 deletions(-)
> 
> diff --git a/svkbd.c b/svkbd.c
> index f9b951d..61778c6 100644
> --- a/svkbd.c
> +++ b/svkbd.c
> @@ -198,16 +198,19 @@ buttonpress(XEvent *e)
>       if (!(k = findkey(ev->x, ev->y)))
>               return;
> 
> -     if (k->modifier) {
> -             mod = k->modifier;
> -     } else {
> -             for (i = 0; i < LENGTH(buttonmods); i++) {
> -                     if (ev->button == buttonmods[i].button) {
> -                             mod = buttonmods[i].mod;
> -                             break;
> -                     }
> +     for (i = 0; i < LENGTH(buttonmods); i++) {
> +             if (ev->button == buttonmods[i].button) {
> +                     mod = buttonmods[i].mod;
> +                     break;
>               }
>       }
> +
> +     if (k->modifier) {
> +             if (mod == k->modifier)
> +                     mod = 0;
> +             else
> +                     mod = k->modifier;
> +     }
>       press(k, mod);
>  }
> 
> @@ -231,7 +234,9 @@ buttonrelease(XEvent *e)
>       if (ev->x < 0 || ev->y < 0) {
>               unpress(NULL, mod);
>       } else if ((k = findkey(ev->x, ev->y))) {
> -             if (k->modifier)
> +             if (k->modifier == mod)
> +                     unpress(k, 0);
> +             else if (k->modifier)
>                       unpress(k, k->modifier);
>               else
>                       unpress(k, mod);
> @@ -564,6 +569,7 @@ void
>  unpress(Key *k, KeySym buttonmod)
>  {
>       int i;
> +     Bool neutralizebuttonmod = False;
> 
>       if (k != NULL) {
>               switch(k->keysym) {
> @@ -589,10 +595,13 @@ unpress(Key *k, KeySym buttonmod)
>               /* simulate the press event, as we postponed it earlier in 
> press() */
>               for (i = 0; i < numkeys; i++) {
>                       if (keys[i].pressed && IsModifierKey(keys[i].keysym)) {
> -                             simulate_keypress(keys[i].keysym);
> +                             if (keys[i].keysym == buttonmod)
> +                                     neutralizebuttonmod = True;
> +                             else
> +                                     simulate_keypress(keys[i].keysym);
>                       }
>               }
> -             if (buttonmod) {
> +             if (buttonmod && !neutralizebuttonmod) {
>                       simulate_keypress(buttonmod);
>               }
>               simulate_keypress(k->keysym);
> @@ -615,14 +624,15 @@ unpress(Key *k, KeySym buttonmod)
>               }
>       }
> 
> -     if (buttonmod) {
> +     if (buttonmod && !neutralizebuttonmod) {
>               simulate_keyrelease(buttonmod);
>       }
> 
>       if ((k == NULL) || (!IsModifierKey(k->keysym))) {
>               for (i = 0; i < numkeys; i++) {
>                       if (keys[i].pressed && IsModifierKey(keys[i].keysym)) {
> -                             simulate_keyrelease(keys[i].keysym);
> +                             if (!(keys[i].keysym == buttonmod && 
> neutralizebuttonmod))
> +                                     simulate_keyrelease(keys[i].keysym);
>                               keys[i].pressed = 0;
>                               drawkey(&keys[i]);
>                       }
> --
> 2.25.1
> 
> 

Hi,

>From the description it sounds useful to me.

Any users of svkbd have opinions or objections about this patch?  I don't use
svkbd at the moment.

-- 
Kind regards,
Hiltjo

Reply via email to