hyprwm / Hyprland

Hyprland is an independent, highly customizable, dynamic tiling Wayland compositor that doesn't sacrifice on its looks.
https://hyprland.org
BSD 3-Clause "New" or "Revised" License
21.09k stars 882 forks source link

script works in terminal not as startup #1089

Closed euglevi closed 1 year ago

euglevi commented 1 year ago

I made a very simple script to open firefox as soon as I create a workspace.

#!/bin/bash

function handle {
 if [[ ${1:0:20}  == "createworkspace>>web" ]]; then 
     firefox
 fi
}

socat - UNIX-CONNECT:/tmp/hypr/$(echo $HYPRLAND_INSTANCE_SIGNATURE)/.socket2.sock | while read  line; do handle $line; done

When I run it in the terminal, everything works fine. When I attach it to my config file in an exec command (exec=/home/eugenio/.config/hypr/hyprland_firefox.sh), it does not work. When I look if the pid that Hyprland set is active, I cannot seem to find it. Any ideas? Could it be something related to environment variables or to path? But what?

Thank you!

vaxerski commented 1 year ago

exec-once=sleep 2 && /home/eugenio/.config/hypr/hyprland_firefox.sh

euglevi commented 1 year ago

Alas, it is not working. Not even if I put a delay of 20 seconds rather than 2.

vaxerski commented 1 year ago

oh wait, iirc, the HIS is not passed to execs. That might be an issue. Check if echo $HYPRLAND_INSTANCE_SIGNATURE returns the sig.

euglevi commented 1 year ago

Mmmm not sure how I should check. If I check in a shell, then I get the value. The log does not say anything about it.

vaxerski commented 1 year ago

exec-once=echo $HYPRLAND_INSTANCE_SIGNATURE > ~/myfile.txt

?

euglevi commented 1 year ago

Sorry, it has been a long week...

Anyway, the file has the proper value of HIS. So this rules out the script not working because of the environmental variable, right?

vaxerski commented 1 year ago

yeah. Huh, odd. Can you try to pipe the script itself into a file? See if it outputs any errors

euglevi commented 1 year ago

That I had already tried with no luck. An empty file.

Now I tried a slightly modified script:

#!/bin/bash

function handle {
 if [[ ${1:0:20}  == "createworkspace>>web" ]]; then 
     echo "2"
     firefox
 else
     echo "1"
 fi
}

socat - UNIX-CONNECT:/tmp/hypr/$(echo $HYPRLAND_INSTANCE_SIGNATURE)/.socket2.sock | while read  line;do handle $line; done

What I got - and I tried several times - was a log file with 22 1s. Always the same number.

vaxerski commented 1 year ago

What I got - and I tried several times - was a log file with 22 1s. Always the same number.

maybe try logging the actual provided value instead of a useless 1? You're actively doing things that do not help, lol

euglevi commented 1 year ago

You are right, I thought 1s were more fun :)

This is what I get:

activelayout>>Video
activelayout>>Video
activelayout>>Power
activelayout>>Power
activelayout>>Sleep
activelayout>>Sleep
activelayout>>Integr
activelayout>>Integr
activelayout>>Integr
activelayout>>Integr
activelayout>>DELL09
activelayout>>DELL09
activelayout>>Intel
activelayout>>Intel
activelayout>>Intel
activelayout>>Intel
activelayout>>Dell
activelayout>>Dell
activelayout>>AT
activelayout>>AT
openlayer>>hyprpaper
openlayer>>waybar

Sorry and thank you (also for your patience...)

vaxerski commented 1 year ago

what in the name of fuck

Seems like the events.... stop? Can you try to trigger some distinct event and verify it doesnt log? e.g. opening a window

euglevi commented 1 year ago

I tried with opening a window. Again, if I start the script from the terminal everything works fine, if I set it as a startup script then it interrupts after opening hyprpaper and waybar (now I have 26 lines rather than 22 in the log file because I have two monitors).

euglevi commented 1 year ago

I solved the issue. Socat was stopping because, apparently, it has a timeout of 0.5 seconds. So it was sufficient to add the option "-t 1000" to the socat command in the script to keep it working.