wmutils / contrib

Useful bits and pieces
Other
93 stars 16 forks source link

Add window gridding script: gridder.sh #49

Closed mtreca closed 5 years ago

mtreca commented 5 years ago

Add a script to place the current window on a virtual grid. Adapted from an unmerged PR I opened here.

z3bra commented 5 years ago

Thanks for your submission, I have a few comments on the code before we can merge it to the repo:

Remove unneeded xprop(1) dependency Text files can store the "grid" information the same way. Also the goal of this repository is to showcase what can be done with wmutils alone. Using X11 tools external to the repo goes against that idea.

You can pass argument to functions, and they'll show up as "$1" "$2" "$N". It will look cleaner in your final arg loop, or your "compute" calls:

init) init ;;
move) move "$2" "$3" ;;
resize) resize "$2" "$3" ;;

You could even factorize that:

init|move|resize) $1 $2 $3 ;;

But that's a bit more "obscure", I must say.

Please remove bashisms... Especially if you use /bin/sh as a shebang. As an example, your script will not run on debian, ubuntu, crux, openbsd. Probably even more.

Cheers!

mtreca commented 5 years ago

Hi, z3bra, thank you for your feedback.

I made the request changes, the script is much cleaner that way.

z3bra commented 5 years ago

I just gave it a try today, and I must admit I'm a bit confused about what it's supposed to do.

It seems like gridder.sh init always move the current window to the middle of the screen, and move/resize are just moving/resizing this window by a fixed amount of pixel. If that's all you wanted to do, then your script might be a little over complicated:

sw=$(wattr w $(lsw -r))
sh=$(wattr h $(lsw -r))
wb=$(wattr b $(pfw))

x=$(( $2 * $sw / 9 - $wb ))
y=$(( $3 * $sh / 9 - $wb ))

case $1 in
    move) wmv $x $y $(pfw) ;;
    resize) wrs $x $y $(pfw) ;;
esac

Seems to do the same. But I probably misunderstood something?

edit: freaking github doesn't support markdown for email replies. LOOK AT THE F*CKING HISTORY FOR CORRECT MARKDOWN SUPPORT #!!@

mtreca commented 5 years ago

It seems that you are absolutely right. This is what happens when you try to port features of other wms without taking time to think first. Thanks for your time!