lf icon indicating copy to clipboard operation
lf copied to clipboard

Keep leftmost columns at constant width/execute script on window resize?

Open mbpowers opened this issue 3 years ago • 3 comments

I don't like it when the leftmost columns resize when I resize the window, and want the rest of the space to go to the rightmost/preview. Is there any way to do this? I wrote a simple command that does this but have to execute the command manually on resize. Is there any way to get the command to execute automatically on screen resize? Here is the script.

cmd recol %{{
    w=$(tput cols)
    c1=18
    c2=18
    c3=$(( $w-$c1-$c2 ))
    lf -remote "send $id set ratios $c1:$c2:$c3"
}}

Maybe it would be useful to add functionality of set column widths as an alternative to ratios, for example set colwidths 20:20:0 where the numbers are number of columns like tput outputs and the zero argument implies use whatever space is leftover.

I also don't completely understand the remote command functionality yet and thought maybe there would be a way to use that?

I couldn't find anyone else with this issue and understand if it isn't worth any sort of refactor/enhancement (or if its even necessary). Thanks for the cool program btw!

mbpowers avatar Nov 04 '21 08:11 mbpowers

Figured out a partial hacky solution, added these lines to DWM config:

    { MODKEY,           XK_r,                      spawn,            SHCMD("lf -remote 'send recol'") },
    { MODKEY,           XK_h,                      spawn,            SHCMD("lf -remote 'send recol'") },
    { MODKEY,           XK_l,                      spawn,            SHCMD("lf -remote 'send recol'") },

mod+h and mod+l are assigned to change the master width so it will change the window width then call this command remotely, and mod+r is set to spawn lf so it will call the command after launch. If you copy me make sure to place after the original commands to make sure they run in the right order.

This solution has some slight visual flickering as lf tries to resize the columns based on ratios before my recol command gets sent.

Another issue is if I spawn any window besides lf the recol command is not triggered. Same goes for moving the windows order in the stack. I could add a similar line of code for every hotkey I have that spawns a new window or changes stack order, but that seems like overkill and would clutter my DWM config, will look for a better approach.

mbpowers avatar Nov 22 '21 09:11 mbpowers

I agree that this would be a useful feature. I think the easiest and most straight forward way would be allowing to define a on-resize command that gets run on resize. It could then also be used to adjust the number of columns. Currently, unless you can hook into resize events for specifig windows in your window manager, I don't think a cleaner solution than yours is possible.

kmarius avatar Nov 22 '21 22:11 kmarius

@mbpowers @kmarius I think on-resize hook sounds reasonable. My guess is that it may not be too difficult to implement either if anyone is interested in working on this. One might need to trace how tcell.EventResize propagates in the code.

gokcehan avatar Dec 02 '21 16:12 gokcehan