aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/scripts/Dropterminal.sh
blob: a160c3e9b65cb91604ad16de02c5e52a0726a8b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */  ##
# Dropdown Terminal Usage: ./dropdown.sh [foot|kitty]

TERMINAL="$1"
SPECIAL_WS="special:scratchpad"

# Validate input and set CLASS and CMD
case "$TERMINAL" in
    foot)
        CLASS="foot-dropterminal"
        TERMINAL_CMD="foot --app-id $CLASS"
        ;;
    kitty)
        CLASS="kitty-dropterminal"
        TERMINAL_CMD="kitty --class $CLASS"
        ;;
    *)
        echo "Invalid or missing terminal argument. Usage: $0 [foot|kitty]"
        exit 1
        ;;
esac

# Get the current workspace
CURRENT_WS=$(hyprctl activeworkspace -j | jq -r '.id')

# Function to check if terminal exists
terminal_exists() {
    hyprctl clients -j | jq -e --arg CLASS "$CLASS" 'any(.[]; .class == $CLASS)' >/dev/null 2>&1
}

# Function to check if terminal is in special workspace
terminal_in_special() {
    hyprctl clients -j | jq -e --arg CLASS "$CLASS" 'any(.[]; .class == $CLASS and .workspace.name == "special:scratchpad")' >/dev/null 2>&1
}

# Function to get terminal address
get_terminal_address() {
    hyprctl clients -j | jq -r --arg CLASS "$CLASS" '.[] | select(.class == $CLASS) | .address'
}

if terminal_exists; then
    TERMINAL_ADDR=$(get_terminal_address)

    if terminal_in_special; then
        echo "Bringing terminal to workspace $CURRENT_WS and pinning"
        hyprctl dispatch movetoworkspace "$CURRENT_WS,address:$TERMINAL_ADDR"
        hyprctl dispatch pin "address:$TERMINAL_ADDR"
        hyprctl dispatch focuswindow "address:$TERMINAL_ADDR"
    else
        echo "Unpinning and hiding terminal to special workspace"
        hyprctl dispatch pin "address:$TERMINAL_ADDR"  # Unpin (toggle)
        sleep 0.1
        hyprctl dispatch movetoworkspacesilent "$SPECIAL_WS,address:$TERMINAL_ADDR"
    fi
else
    echo "Creating new dropdown terminal with command: $TERMINAL_CMD"
    hyprctl dispatch exec "[float; move 25% 5%; size 50% 50%] $TERMINAL_CMD"
    sleep 0.5
    if terminal_exists; then
        TERMINAL_ADDR=$(get_terminal_address)
        hyprctl dispatch pin "address:$TERMINAL_ADDR"
        hyprctl dispatch focuswindow "address:$TERMINAL_ADDR"
    fi
fi
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage