This idea is absed on the following snippet for wezterm: https://gitlab.com/-/snippets/4798512
This should work with most terminals, as long as they allow for custom titles or if you don't mind using them only in dropdown mode.
The idea is to create a down rule that forces the window to stay in the position you want, and to create a script using kdotool to execute the terminal if it's not running, and minimize/show it if it's running.
This should also work in x11 with minimal changes. I personally like for the terminal to stay on top always, and for the keybind to hide/show it, regardless of my current focus since I work with two monitors and the first press gaining focus when I want to hide it is annoying. In any case, here is the script excerpt in case the snippet link is deleted and that interaction is preferred, this should also work with xdotool:
toggle() {
WINDOW_ID=$(kdotool search --name "${NAME_WINDOW_SEARCH}")
ACTIVE_ID=$(kdotool getactivewindow)
case "${WINDOW_ID}" in
"")
dbus-launch ${TERMINAL_BIN} ${ADDITIONAL_ARGS}
;;
"${ACTIVE_ID}")
echo "Focused->Hidden"
kdotool windowminimize "${WINDOW_ID}"
;;
*)
echo "Hidden/Unfocused->Focused"
kdotool windowactivate "${WINDOW_ID}"
;;
esac
}We will create several window rules to enforce the positioning of the terminal, ths can be changed to the preference of the
user. The only important part is where we define the window title, it must be the same as the one defined in the script.

Now we only need a keybind that launches the script and it will work. Remember making the script executable too.

Thanks! This was really useful. Though, I ended up writing something different based on your idea.
This supports returning focus if already open and doesn't need the flag file.