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.54k stars 901 forks source link

Different wallpaper per workspace #103

Closed ThatOneCalculator closed 2 years ago

ThatOneCalculator commented 2 years ago

Describe in detail your idea.

The ability to designate different wallpapers to different workspaces would be great :)

japrogramer commented 2 years ago

im setting the wallpaper with exec-once and then swaybg. If there was a hook that could run after an action it would be trivial to run a wallpaper switcher.

vaxerski commented 2 years ago

idk how to do hooks other than sockets, can you like listen to a socket with a bash script?

vaxerski commented 2 years ago

Added a UNIX sockets-based event system. See the IPC wiki page for events.

To see them live, do something like for example:

socat - UNIX-CONNECT:/tmp/hypr/.socket2.sock   

However you want to handle that, you can now.

Lmk how to execute a script with a param on each event, I want to know myself too, but I suck at bash :P

japrogramer commented 2 years ago

@vaxerski

Here is how to execute a command on each workspace event

#!/bin/zsh

function handle {
    if [[${1:0:9} == "workspace" ]]; then
        echo $line
    fi
}

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

I set my background with

swaybg --image $(find $HOME/Pictures/Wallpaper -type f | shuf -n 1) -m fill

but that doesn't seem to like running inside of the function because it doesn't exit and needs to stay running to keep the background

vaxerski commented 2 years ago

okay, thanks.

But that seems like a script issue, no? you can always killall swaybg and run swaybg each time in the bg.

At any rate, I'd consider this issue closed. It is now possible.

ThatOneCalculator commented 2 years ago

@japrogramer please lmk when you make a working script :pray:

japrogramer commented 2 years ago

@ThatOneCalculator

#!/bin/zsh
swaybg --image $(find $HOME/Pictures/Wallpaper -type f | shuf -n 1) -m fill&
function handle {
    if [[ ${1:0:9} == "workspace" ]]; then
        echo $line
        killall swaybg
        swaybg --image $(find $HOME/Pictures/Wallpaper -type f | shuf -n 1) -m fill&
    fi
}

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

this works when I run it from the shell but im having trouble calling it from hyprland.conf in an exec-once. so if you figure that out let me know

ThatOneCalculator commented 2 years ago

When I run it from shell, I get

./wall.sh:12: closing brace expected
vaxerski commented 2 years ago

typo in all swaybg it's ${ and should be $(

ThatOneCalculator commented 2 years ago

thanks oomfie ur the bestest

japrogramer commented 2 years ago

fixed in the comment

ThatOneCalculator commented 2 years ago

Works fine from shell, but briefly shows the Hyprland logo when switching workspaces

ThatOneCalculator commented 2 years ago

Also works fine when adding exec=/home/me/wall.sh to hyprland.conf

japrogramer commented 2 years ago

I don't get that hyprland logo issue, I have a black background for my hyprland instance. thanks, I see I had a typo on my call.

now using

exec-once=sh -c \$HOME/.config/hypr/wallpaper_switch.sh
ThatOneCalculator commented 2 years ago

ah. How can I set the bg to be black instead of the hyprland logo?

japrogramer commented 2 years ago

I don't know It happened after the latest build I made from main.

ThatOneCalculator commented 2 years ago

weird...

vaxerski commented 2 years ago

The hyprland logo is due to the delay. You kill swaybg, and then before the new swaybg can initialize and load the image there is a gap.

japrogramer commented 2 years ago

so maybe store the current swaybg task pid in a variable and kill it after the new swaybg starts

vaxerski commented 2 years ago

yep, wait a couple sec and then kill

on the side note: this method SUCKS for multimon users. I'll tweak the events a bit.

ThatOneCalculator commented 2 years ago

Despite some initially odd behavior, the results from this are really pretty.

https://user-images.githubusercontent.com/44733677/170124661-dc161cb9-968b-470e-9338-32b4599645e1.mp4

japrogramer commented 2 years ago

Oh Nice! ill move the kill to after the new swaybg spawns

vaxerski commented 2 years ago

r/unixporn would be proud.

Fixed them events. Also added activemon and activewindow.

vaxerski commented 2 years ago

Oh Nice! ill move the kill to after the new swaybg spawns

You can just wait 1s or something before killing old swaybg. The new one will open on top, anyway.

japrogramer commented 2 years ago

This is the new script with the delay kill

#!/bin/zsh
swaybg --image $(find $HOME/Pictures/Wallpaper -type f | shuf -n 1) -m fill&
function handle {
    if [[ ${1:0:9} == "workspace" ]]; then
        echo $line
        swpid=`ps axf | grep swaybg | grep -v grep | awk '{printf $1}'`
        swaybg --image $(find $HOME/Pictures/Wallpaper -type f | shuf -n 1) -m fill&
        sleep .3
        kill $swpid
    fi
}

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

Note: that if you switch to the same workspace you are in, it also changes the wallpaper

vaxerski commented 2 years ago

Note: that if you switch to the same workspace you are in, it also changes the wallpaper

i fixed that already, recompile

On the side note: the fact that it's even possible to do something like this, this quickly and easily is what I love about loonux

japrogramer commented 2 years ago

thanks, will recompile.

ThatOneCalculator commented 2 years ago

Pushed a new version to the AUR so that those who aren't on devel will be prompted to recompile from source :heart:

japrogramer commented 2 years ago

@ThatOneCalculator Here is a new version of the script which works with the new socket file location, and the script tries to avoid repeating the wallpaper between workspace changes.

#!/bin/zsh
background=$(find $HOME/Pictures/Wallpaper -type f | shuf -n 1)
swaybg --image $background -m fill&

function handle {
    if [[ ${1:0:9} == "workspace" ]]; then
        echo $line
    newbackground=$(find $HOME/Pictures/Wallpaper -type f | shuf -n 1)
    echo $newbackground
    until [[ ("${background}" != "${newbackground}") && (-r $newbackground) ]]; do
        newbackground=$(find $HOME/Pictures/Wallpaper -type f | shuf -n 1)
        echo $newbackground
        sleep .3
        done
    echo $newbackground
    background=newbackground
    swpid=`ps axf | grep swaybg | grep -v grep | awk '{printf $1}'`
    swaybg --image $newbackground -m fill&
    sleep .3
    kill $swpid
    fi
}

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