#!/bin/bash
# Pocket DS — toggle the Onboard on-screen keyboard.
#
# Onboard runs under XWayland (reliable XInput touch) with the uinput
# injection backend (global). Under XWayland it only renders at full
# DSI-2 size on a FRESH map, so we SHOW by starting a fresh instance and
# HIDE by killing it.
#
# Show goes through Onboard's D-Bus service, whose Exec is overridden to
# /usr/bin/pocketds-onboard (see org.onboard.Onboard.service) — so a not-
# running Onboard is activated with the correct XWayland+uinput env, and
# a running one just gets Show. No launch/registration race.
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"

if pgrep -x onboard >/dev/null 2>&1; then
    pkill -x onboard
else
    dbus-send --type=method_call --dest=org.onboard.Onboard \
        /org/onboard/Onboard/Keyboard org.onboard.Onboard.Keyboard.Show 2>/dev/null
fi
