Watch for `monitors change event` on wayland with Glib mainloop in gtk4?

I’m writing a wayland layershell project with gtk4-layershell.
And i want to watch for monitor change events, then reload some of my window and do something else.

i can’t seem to find how to do that in gtk4

Hi,

Have you tried connecting to the GtkWindow’s notify::display signal?

1 Like

The display property is for the windowing system display connection; it has nothing to do with monitors.

Use the list model of GdkMonitor instances returned by gdk_display_get_monitors(). You also need to listen to the GdkMonitor::invalidate signal of each GdkMonitor.

2 Likes

Thanks for the reply, but that only applies when monitor disconnected, not when new one connected.
I can do it with wayland client api though, but it will be much more convenient if gdk supports it.

The “invalidate” signal will tell you when a GdkMonitor instance is going to be invalidated; the GListModel::items-changed signal will be used when a new monitor is added or a monitor is removed from the list of monitors.

1 Like

Sorry, i thought the listmodel returned is just a normal list of monitors created temporarily.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.