hyprwm / contrib

Community scripts and utilities for Hypr projects
MIT License
280 stars 39 forks source link

For `event_closewindow`, how do I get the target window's `WINDOWADDRESS`? #109

Open kohane27 opened 2 months ago

kohane27 commented 2 months ago

Program

shellevents

Maintainers of the program

trippwill

Bug or Regression?

Bug

Description

Hello! Hope you're doing well.

It's not exactly a bug. I'm trying to use event_closewindow but run into issues: how do I get the target window's WINDOWADDRESS?

event_openwindow provides WINDOWCLASS so it's easy to do so:

event_openwindow() {
    # WINDOWADDRESS WORKSPACENAME WINDOWCLASS WINDOWTITLE
    case "$WINDOWCLASS" in "firefox")
        bash "$HOME"/.config/zsh/scripts/enable-audio.sh
        ;;
    esac
}

But I can't do the same for event_closewindow because it only provides WINDOWADDRESS:

event_closewindow() {
    # WINDOWADDRESS
}

I tried the following:

event_closewindow() {
    # WINDOWADDRESS
    target_address=$(hyprctl --batch clients -j | jq -r '.[] | select(.class == "firefox") | .address')
    if [[ "$WINDOWADDRESS" == "$target_address" ]]; then
        bash "$HOME"/.config/zsh/scripts/disable-audio.sh
    fi
}

But the window is already closed so target_address is always null.

Any input is much appreciated. Thank you.

vaxerski commented 2 months ago

image it's right here.

kohane27 commented 2 months ago

Hello it's the creator of Hyprland!

Apologies of my unclear question. I know that I can get the WINDOWADDRESS. I meant how do I get the WINDOWCLASS or WINDOWTITLE from the WINDOWADDRESS.

The WINDOWADDRESS changes on reboot so the following doesn't work:

event_closewindow() {
    # WINDOWADDRESS
    case "$WINDOWADDRESS" in "5a6b54d80ba0")
        bash "$HOME"/.config/zsh/scripts/disable-audio.sh
        ;;
    esac
}

Basically I want the following:

    case "$WINDOWCLASS" in "firefox")
        bash "$HOME"/.config/zsh/scripts/disable-audio.sh
        ;;
    esac

but in event_closewindow instead of event_openwindow. Thanks again!

vaxerski commented 2 months ago

you can't from the IPC as the window is already gone. You'll need to cache those states (probably launch hyprctl clients once and then just cache window open events)