How to disable a window rule after a while?

Hi everyone.

Up to 0.54, I used the config below to sequentially start applications when Hyprland starts.

Example for starting VSCodium on workspace 9 then having the ability to start it anywhere else :

windowrule {
    name = start-VSCodium
    match:class = codium
    workspace = 9 silent
}

exec-once = sleep 30 && vscodium

exec = sleep 60 && hyprctl keyword 'windowrule[start-vscodium]:enable false'

With 0.55 and Lua, I realized that I could simplify this logic with the ability of “Executing with rules“. So I tried the following :

hl.on(
    "hyprland.start",
    function ()
        hl.exec_cmd(
            "sleep 30 && vscodium",
            { workspace = "9 silent" }
        )
    end
)

It worked like a charm for all my app that I start at launch except for VSCodium (maybe a process fork as mentioned in the Wiki). So I had to reuse the static rule I had before :

hl.on(
    "hyprland.start",
    function ()

        local VSCodiumRule = hl.window_rule({
            name = "start-VSCodium",
            match = { class = "codium" },
            workspace = "9 silent"
        })

        hl.exec_cmd("sleep 30 && vscodium")

        hl.exec_cmd("sleep 60 && ???????") -- What has to be here ?
    end
)

VSCodium now starts perfectly and silently on workspace 9 but I can’t figure out how I can disable this rule after 60 seconds. I tried various combinations of hyprctl dispatch ..., hyprctl eval ..., all with VSCodiumRule:set_enabled(false) but I didn’t find any solution for disabling it.

Thanks in advance if you can help me achieving this.

You were close.

The local keyword (as the name implies) makes a variable local, as opposed to global. This means that as soon as the current scope ends (in this case, the callback in hyprland.start), you can no longer use it.

Also, you probably shouldn’t be registering window rules inside of hyprland.start unless you have a good reason for doing so. (correct me if I’m wrong)

The simplest fix is to remove the local keyword, and then hyprctl eval 'VSCodiumRule:set_enabled(false)' will work as expected.

That being said, we now have Timers and window.open Events. You probably should use them instead of a shell timeout. You can, for example, listen to window open events, check if it’s the window you want, and then disable the rule from Lua, this will work regardless of how long or short it takes for it to start. Or you can even use window.open_early and skip window rules altogether for ultimate freedom.

Hello

I answer myself… I used a timer and everything worked ! Complete code below :

hl.on(
    "hyprland.start",
    function ()

        local VSCodiumRule = hl.window_rule({
            name = "start-VSCodium",
            match = { class = "codium" },
            workspace = "9 silent"
        })

        local resetStartWindowRules = hl.timer(
            function ()
                VSCodiumRule:set_enabled(false)
            end,
            {
                timeout = 60000,
                type = "oneshot"
            }
        )

        hl.exec_cmd("sleep 30 && vscodium")

        resetStartWindowRules:set_enabled(true)
    end
)

Oh, you answered while I was writing… I figured out by myself but I will check events as you suggested it.

Thank you.