#!/bin/sh

if ! [ -z "$(swaymsg -t get_tree | grep 'ddterminal')" ]; then
    if [ -z "$(swaymsg -t get_tree | grep -A 46 'ddterminal' | tail -n 1 | grep 'true')" ]; then
        swaymsg '[title="ddterminal"] scratchpad show'
    else
        swaymsg '[title="ddterminal"] move scratchpad'
    fi
else
    $TERMINAL -T "ddterminal" tmuxatt &
    sleep 0.2s
    curwiny=$(swaygetcurrentwindow | cut -d ' ' -f1 | cut -d ',' -f2 )
    curdisy=$(swaymsg -pt get_outputs | grep -A3 focused | grep Position | cut -d ',' -f2)
    moveup=$(($curwiny - $curdisy - 30))
    swaymsg move up "$moveup px"
fi