#!/bin/bash

## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

set -o errexit
set -o nounset
set -o errtrace
set -o pipefail

true "$0: START"

print_usage() {
  printf '%s\n' "$0: Set keyboard layout for labwc" >&2
  printf '%s\n' "Usage: $0 [--help|-h] [--no-persist] [--no-reload] [--config=<path>] [--no-live-changes] [--interactive] -- [layout [variant [option]]]" >&2
  printf '%s\n' 'Options:' >&2
  printf '%s\n' '--help, -h         Print this help message.' >&2
  printf '%s\n' '--no-persist       Make layout change non-persistent.' >&2
  printf '%s\n' '--no-reload        Skip reloading labwc config. Only useful with --no-persist.' >&2
  printf '%s\n' '--config=<path>    Specify an alternative config file path.' >&2
  printf '%s\n' '--no-live-changes  Do not change the keyboard layout in the active running session.' >&2
  printf '%s\n' '--interactive      Show an interactive user interface.' >&2
  printf '\n' >&2
  printf '%s\n' 'Examples:' >&2
  printf '%s\n' '  set-labwc-keymap de' >&2
  printf '%s\n' '  set-labwc-keymap --no-persist us colemak' >&2
  printf '%s\n' '  set-labwc-keymap us,cz,de "" grp:alt_shift_toggle' >&2
}

if [ "$(id -u)" = "0" ]; then
  printf '%s\n' "$0: ERROR: This must NOT be run as root (sudo)!" >&2
  exit 1
fi

scriptname=$(basename -- "$0")
function_name="$(printf '%s\n' "$scriptname" | str_replace "-" "_")"

source /usr/libexec/helper-scripts/set-keyboard-layout.sh

true "$0: END"
