Alternative mouse binding with preserved aspect ratio while resizing

How to make windows resizable with aspect ratio in version 0.55.

In previous version it was

bindm = $mainMod SHIFT, mouse:273, resizewindow 1

Now it should be configured as

local focused_keep_aspect = hl.window_rule({
    match = { focus = true },
    keep_aspect_ratio = true,
})

hl.bind(mainMod .. " + SHIFT + mouse:273",function()
        focused_keep_aspect:set_enabled(true)
        hl.dispatch(hl.dsp.window.resize())
end, { mouse = true })

hl.bind(mainMod .. " + mouse:273",function()
        focused_keep_aspect:set_enabled(false)
        hl.dispatch(hl.dsp.window.resize())
end, { mouse = true })

Is there any easier way to configure this.

I think you can delete the local variable:

hl.bind(MainMod .. " + SHIFT + mouse:273", function()
    hl.window_rule({ match = { focus = true }, keep_aspect_ratio = true })
    hl.dispatch(hl.dsp.window.resize())
end, { mouse = true })

hl.bind(MainMod .. " + mouse:273", hl.dsp.window.resize(), { mouse = true })

No it is not working, it does seem working until once you resize with mainMod + SHIFT + mouse:273 the aspect ratio rule is permanently set, and normal resizing stops working and all focused windows start behaving like that.

I don’t know much about lua implementation done, but my current config works fine with no problems.

I did find out instead of resetting every time using a release bind should simply work. This is annoying but, I have no other choice

local focused_keep_aspect = hl.window_rule({
    match = { focus = true },
    keep_aspect_ratio = true,
})

hl.bind(mainMod .. " + SHIFT + mouse:273",function()
	focused_keep_aspect:set_enabled(true)
	hl.dispatch(hl.dsp.window.resize())
end, { mouse = true })

hl.bind(mainMod .. " + SHIFT + mouse:273",function()
	focused_keep_aspect:set_enabled(false)
end, { mouse = true, release = true })

hl.bind(mainMod .. " + mouse:273",function()
	hl.dispatch(hl.dsp.window.resize())
end, { mouse = true })