Aylur / astal

Building blocks for creating custom desktop shells
https://aylur.github.io/astal/
GNU Lesser General Public License v2.1
287 stars 37 forks source link

Relate GdkMonitor to River/Wayland Output #128

Closed cold-leopard closed 5 days ago

cold-leopard commented 5 days ago

Have you read through the documentation?

Describe what have you tried so far

What has worked so far is referring to monitors by number. Gtk seems to order the monitor in the opposite direction of River, so the below works, but I have no idea if that will be consistent

<window monitor=monitor>
    <box>
        <label label = {bind(river.get_outputs()[3 - monitor], "layout-name")}/>
    </box>
</window>    

Describe your question

I'd like to have each monitor have a status bar describing the River status for that monitor/output. I'd like to make use of the Gdk.Monitor object to do this, but I need to get info from the Gdk.Monitor object that can be used to describe the River output I want to get information about. Unfortunately, there doesn't seem to be any overlap between the Output information exposed by the River library and the information available from Gdk.Monitor in GTK 3

It looks as though the River library only exposes the Output name (seemingly relating to the monitor connection device e.g. DP-1) or wl_output ID.

GDK 3 Gdk.Monitor only exposes the work_area, model, and manufacturer. I have multiple monitors of the same model, so the latter two aren't an option. In theory, work_area might be able to work by comparing positions, but the River library does not make those available, and that doesn't seem an ideal solution.

In GDK 4, the monitor does expose description and connector information, connector information should match up to the River output's name (though not sure how stable that is as long-term solution), not sure if description is useful. However, I'm not sure if there's a good way to use GDK 4 just for this information without messing up other things.

In short, does anyone know a good way to relate River outputs to GDK monitors, or else how to use the GDK 4 monitor class without having everything on GTK 4?

kotontrion commented 5 days ago

Yeah, this is a known issue.

In theory, work_area might be able to work by comparing positions, but the River library does not make those available

I thought of implementing waylands output management protocol in river allowing to get the outputs position, size, description, etc, but didn't get to it yet. This wouldnt solve this anyway, but would give you more info.

In C you can get the wl_output from a gdk.monitor, but this api is not available in gjs, so it wouldn't be hard to match a gdk monitor to a river.output in c, but this would add gdk as a dependency and therefore the river lib wouldn't be usable in gdk3 and 4, so I would have to maintain two versions, which I would like to avoid. Now that I think of it, maybe I could write a small separate helper lib for that.

The next best thing is to match them using the name. In river the name is the same as the connector, as you said this can be easily done in gdk4.

In gdk3 this is more difficult. Here is a workaround to get the get the monitors name from the gdk.monitor in gtk3:

https://github.com/Aylur/ags/issues/363#issuecomment-2140092162

It uses a deprecated api, but it works fine.

cold-leopard commented 5 days ago

Perfect, thank you that did the trick!