User:Fdelamotte/Lateral Keyboard In Sxmo

From postmarketOS

Here are some notes about an experiment I made to get a keyboard split in two lateral panes when in landscape.

Beware this is only a really awfull hack ...

Wvkbd-lateral.png

Modifying wvkbd

First let's get a keyboard that displays on a lateral edge instead of the bottom and give it a custom layout. Then we can launch two of them.

The keyboard used in sxmo is wvkbd[1] by Proycon.

To make a modified version suitable for our needs, you should first retreive the source code from Sourcehut with :

$ git clone https://git.sr.ht/~proycon/wvkbd

Make a vertical keyboard

There are only three modifications to be made in main.c to make the keyboard display vertically. We need to change the anchor (to left or right side of the screen) and swap the dimensions (width and height) to make the keyboard vertical. Here is a diff (KBD_ANCHOR will be defined in the layout include) :

68,70c68
< static uint32_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM |
<                          ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
<                          ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
---
> static uint32_t anchor = KBD_ANCHOR;
549c547
<         zwlr_layer_surface_v1_set_size(layer_surface, 0, height);
---
>         zwlr_layer_surface_v1_set_size(layer_surface, height, 0);
726c724
<     zwlr_layer_surface_v1_set_size(layer_surface, 0, height);
---
>     zwlr_layer_surface_v1_set_size(layer_surface, height, 0);

Add new layouts

Then we add two new layouts, left and write. First copy the keymaps :

$ cp keymap.{mobintl,left}.h
$ cp keymap.{mobintl,right}.h

Then you can add the modified layouts left [2] and right [3] where keys_full have been redefined to get the desired layout. The head of the files also contains the anchor definition and a modified height (beware I use a desktop scale of 1 so you probably have to redefine that according to your setup).

/* constants */
/* how tall the keyboard should be by default (can be overriden) */
#define KBD_PIXEL_HEIGHT 250
     
/* how tall the keyboard should be by default (can be overriden) */
#define KBD_PIXEL_LANDSCAPE_HEIGHT 350
     
/* spacing around each key */
#define KBD_KEY_BORDER 2
     
#define KBD_ANCHOR ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |\
                   ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |\
                   ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM 

Compile the layouts

Each layout can then be compiled.

$ make LAYOUT=left clean all
$ make LAYOUT=right clean all

And you can copy the executables in your ~/bin.

You'll probably note that the modifiers are not shared between layout (notably shift), this limits their usability a lot, but I think a big refactor would be needed to have the two surfaces in one executable ...

Integrate into sxmo

First a script to launch the keyboards depending on the orientation of the screen (launchkbd.sh[4]) :

#!/bin/sh                                                                                                                                                                                      
 
cleanup_exit() {
  swaymsg -t get_outputs | grep -q "transform.*90" && swaymsg gaps left all set 80
  pkill "wvkbd-*"
}
 
trap 'cleanup_exit' SIGINT SIGKILL SIGTERM EXIT
 
if swaymsg -t get_outputs | grep -q "transform.*90" ; then
    swaymsg gaps left all set 0
    wvkbd-right --fg 661111 --fg-sp 441111&
    wvkbd-left --fg 1c6d90 --fg-sp 103d51&
else
    wvkbd-fr -H 600 -L 300 --fn 'Monospace 30' -l full,special --landscape-layers landscape,special &
fi
 
wait
 
swaymsg -t get_outputs | grep -q "transform.*90" && swaymsg gaps left all set 80

You can kill the keyboards by issuing pkill -f "wvkbd-*" or pkill -f "launchkbd.sh" (there is a trap in the script so that the keyboards are killed when the script si terminated).

Note that when opening and closing the keyboard, I set the gaps according to my own config, this might need tweaking.

A modification to sxmo_keyboard.sh [5] is needed because isopen won't detect the script with pidof. It should work both with normal wvkbd and using launchkbd.sh.

To make sxmo open your keyboard automatically, you have to define the KEYBOARD variable in profile (~/bin is in my path so the script is correctly found) :

export KEYBOARD=launchkbd.sh