wmutils / contrib

Useful bits and pieces
Other
94 stars 16 forks source link

feature request: get map of used window space/map of available space #20

Closed falafflepotatoe closed 7 years ago

falafflepotatoe commented 8 years ago

theres no other tools that do this (if you know of one plz link me)

would love to be able to get a map of available window rects so i can create windows in

z3bra commented 8 years ago

Could you elaborate on this? I'd love to implement something that doesn't exist yet!

Ferdi265 commented 8 years ago

I think he means a list of screen areas where there are no windows, i.e. where the root window is visible

falafflepotatoe commented 8 years ago

@ferdi265 correct. the most common app for printing win data doesnt even list geometries in tree mode (tree mode lists all windows).

Ferdi265 commented 8 years ago

The what-is-covered case seems like it would be possible with a loop around lsw and wattr; only problem would be duplicated geometries in some cases.

I don't know yet wether this should be done in shell or in C.

falafflepotatoe commented 8 years ago

@Ferdi265 thanks Ill have a look

ideally something like (pseudo code)

listvisiblegeometry()  => [
   { name: Sublime Text 2.0, handle: 0x12341234, geometry: [0,0,800,600] },
   { name: XMMS, handle: 0x12341234, geometry: [900,0,300,200] }
]

and unusedgemetry() => [[0,0,700,200], [500,700,200,800]]

my end goal is do something like for unusedgeometry() ( if (height>200) mplayer somerockvideofromyoutube.mp4 -rect $x,$y,$h,$w ) to play 4-10 copies of the same music video in sync from youtube :)

it should be a cool effect

z3bra commented 8 years ago

The first part is easy to handle:

lsw | while read WID; do
    printf '{ name: %s, handle: %s, geometry: [%d,%d,%d,%d] },\n' "$(wname $WID)" $(wattr ixywh $WID)
done

For the second one... you'd have to draw a map of your screen, then calculate all the possible rectangles that could fit in the screen. This sounds possible even if a bit tricky.
But shell is definitely not the best way to do it, as it's not efficient at all.

One could write a project that reads geometries from stdin, one per line with the first one being the root windows, then perform the calculation, and output all geometry to stdout in the form 'x y w h', so you can use it with wtp directly.

I'll try to give it a shot.

z3bra commented 8 years ago

@dcat wrote tplot which can be used for this. He also wrote a script to create a map of drawn windows in your terminal. Never saw the code, but the result was nice!

Ferdi265 commented 8 years ago

The problem with unusedspace() here is that in some cases, the possible windows are ambiguous. (i.e. there are multiple ways to split the empty space into rectangles)

Best would be to just say "don't rely on the order and/or location/size of the individual rectangles in unusedspace()". Best would probably be to just write some geometry arithmetic library that can compute union, difference and intersection of geometries, for use in tools like wmutils and similar

z3bra commented 7 years ago

Seeing your original intention, I doubt a single script could solve this efficiently. It might be best to write a new tool from scratch using libwm, to compute the map and spawn instances of mplayer (or whatever).