#!/bin/sh

if [ -n "$INPUT_METHOD" ]; then
    # Note:
    # systemd-inputmethod-generator rewrite $INPUT_METHOD from fcitx5 to fcitx
    # This works because fcitx and fcitx5 cannot be installed together.
    case $INPUT_METHOD in
	fcitx | fcitx5)
	    ;;
	*)
	    exit 0;;
    esac
elif [ -f $XDG_RUNTIME_DIR/input_method ]; then
    exit 0
fi

/usr/bin/fcitx5 -D && \
    echo -n fcitx5 > $XDG_RUNTIME_DIR/input_method

exit 0
