Chromium med skærmtastatur (onboard)

Source: Download script

Last Updated: 4. December 2024 by Agnete Moos (agms@sonderborg.dk)

Parameters:

Navn Type Standardværdi Påkrævet
Click to see the source code
#! /usr/bin/env sh

# DESCRIPTION:
# This script installs, sets up and enables a wm (bspwm)
# and an on-screen keyboard (onboard).
# Intended for OS2borgerPC Kiosk.
#
# ARGUMENTS:
# 1: Whether to install / uninstall the wm + onscreen keyboard
#
# PREREQUISITES:
# 1. OS2borgerPC Kiosk - Installer Chromium
# 2. OS2borgerPC Kiosk - Autostart Chromium
#
# Would like to skip installing sxhkd but it's not trivial to do as it's
# classified as a "required dependency" for bspwm
#
# AUTHOR: mfm@magenta.dk

set -ex

if ! get_os2borgerpc_config os2_product | grep --quiet kiosk; then
  echo "Dette script er ikke designet til at blive anvendt på en regulær OS2borgerPC-maskine."
  exit 1
fi

[ -z "$1" ] && exit 1

ACTIVATE=$1

CHROMIUM_SCRIPT='/usr/share/os2borgerpc/bin/start_chromium.sh'
USER=chrome
XINITRC="/home/$USER/.xinitrc"
# Note: Only the Compact keyboard layout is changed to not have Ctrl, Alt etc.
ONBOARD_OPTIONS="--theme=/usr/share/onboard/themes/HighContrast.theme --layout /usr/share/onboard/layouts/Compact.onboard"
# For apt installations/removals
export DEBIAN_FRONTEND=noninteractive

if [ "$ACTIVATE" = 'True' ]; then

  # Keyboard options: onboard (~100 mb incl. dependencies?), xvkbd (almost no
  # dependencies), florence (~500 mb incl. dependencies?!),
  # gnome onscreen keyboard, carabou
  # TODO: language-pack-da is now in install_dependencies.sh but older installs
  # ran a previous version of that, so keeping it here too
  apt-get update
  apt-get install -y language-pack-da bspwm onboard lemonbar- dmenu-

  cd /home/$USER || exit 1
  # Make the directory for the config
  # -p is also there to suppress errors in case someone re-runs this script,
  # and it already exists
  mkdir -p .config/bspwm

  # onboard: If we want a non-default keyboard theme this is apparently necessary
  # because it attempts to create a file in there
  mkdir -p .config/dconf
  chown $USER:$USER .config/dconf

  # Configure bspwm
cat << EOF > .config/bspwm/bspwmrc
#! /bin/sh

bspc monitor -d I

bspc config border_width         0
bspc config window_gap           0
bspc config borderless_monocle   true
bspc config gapless_monocle      true

# leave 20% space for the keyboard
bspc config split_ratio          0.80

# Always split downwards/vertically instead of whichever direction there is
# more space (typically horizontally to begin with)
bspc rule -a "*" split_dir=south

# Test if no difference?: Don't default to monocle?
# bspc desktop I --layout tiled

# layer=normal is needed at least, to ensure it doesn't cover the entire
# screen by default
bspc rule -a Onboard state=tiled layer=normal

# Onboard preferences shouldn't be shown at all. TODO: Not working, but it also
# doesn't matter right now because the button to show them is no longer there.
# bspc rule -a "Onboard Preferences" layer=below flag=hidden

# Launch chromium
$CHROMIUM_SCRIPT wm &

# we want æøå on the keyboard
setxkbmap dk

#sleep 5  # Go back to this solution if the below solution fails

# Wait until a window (the browser) exists because onboard needs to be below it
while ! bspc query -N -n .leaf > /dev/null; do
  sleep 0.5
done

# First time setup of onboard. Attempt at solving a bug where the keyboard
# doesn't appear, seemingly due to first time initialization
if [ ! -f /home/$USER/.config/dconf/user ]; then
  onboard $ONBOARD_OPTIONS &
  # Give it some time to start
  sleep 3
  killall onboard
  sleep 1
fi

# Not certain setting the options is outright necessary past first time setup
onboard $ONBOARD_OPTIONS &
EOF

  # Give it the same permissions as /usr/share/doc/bspwm/examples/bspwmrc
  chmod 755 .config/bspwm/bspwmrc

  # Don't auto-start chromium from xinitrc
  sed -i "s,\(.*$CHROMIUM_SCRIPT.*\),#\1," $XINITRC

  # Instead start autostarting bspwm - don't add it multiple times though
if ! grep -q -- 'exec bspwm' "$XINITRC"; then
cat << EOF >> "$XINITRC"
exec bspwm
EOF
fi

  # Backup the original Compact layout
  cp /usr/share/onboard/layouts/Compact.onboard /usr/share/onboard/layouts/Compact_orig.onboard

  # Use our own Onboard model without ctrl, alt, super etc.
  # This is simply the original file with several sections (keys) commented out.
cat << EOF > /usr/share/onboard/layouts/Compact.onboard







    

    

        
        
            
        

        
            
                
                
                    
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        

                        
                        
                        
                        

                        
                        
                        
                        
                        
                        
                        
                        
                        
                    
                    

                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                      

                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                    
                    
                

            

            
            

            
            
                
                    
                        
                        
                            
                              
                              
                            
                            
                            
                            
                        
                    
                    
                        
                          
                      
                    
                
            

        
    

EOF

  # Give it the same permission as the file it overwrites
  chmod 644 /usr/share/onboard/layouts/Compact.onboard

else # Go back to not using a wm or the onscreen keyboard

  apt-get remove -y bspwm onboard
  apt-get autoremove -y

  # Restore the original Compact layout in case it hasn't been deleted - ignore
  # errors if fx. the dir no longer exists.
  # true is here to prevent stopping if set -e is set
  cp /usr/share/onboard/layouts/Compact_orig.onboard /usr/share/onboard/layouts/Compact.onboard 2>/dev/null || true

  # Start chromium from xinitrc instead of bspwm
  sed -i "s,#\(.*$CHROMIUM_SCRIPT.*\),\1," $XINITRC
  sed -i "/\(exec bspwm\)/d" $XINITRC
fi

Beskrivelse

Sætter billedet op, så det er delt mellem browseren og et virtuelt tastatur.

Dette script forudsætter at følgendes scripts allerede er kørt:

  • Installer Chromium på kiosk
  • Autostart Chromium på Kiosk

Hvis du oplever, det ikke virker, så genkør scriptet “Autostart Chromium på Kiosk”, efterfulgt af dette script.

Dette script tager først effekt efter genstart.

Dette script er blevet testet og virker på Ubuntu 22.04.

Parametre

1: Tilføj skærmtastatur?:
Sæt hak: Installerer og slår skærmtastaturet til
Lad stå tom: Slår skærmtastatur fra (standard)