GdkMonitor ListModel Tracking is Broken
Hello there.
I'm writing an application which tracks monitor add/remove events via the GdkMonitor GListModel returned from "gdk_display_get_monitors".
Here is a bit of debug info, I'm reacting to a monitor getting plugged in and removed.
Let's show what happens in this cycle (keep in mind, there's only two monitors involved here, my laptop screen and an external one).
On initial load of the app, I do a manual iteration of the list (one which did not occur from an event).
** (way-shell:1112061): DEBUG: 09:45:27.811: panel.c:panel_on_monitor_change(): monitor pointer: 0x15a88f0
** (way-shell:1112061): DEBUG: 09:45:27.862: panel.c:panel_on_monitor_change(): initialized bar for monitor: [California Institute of Technology 0x1404 (eDP-1)] [0x1404] [eDP-1]
** (way-shell:1112061): DEBUG: 09:45:27.862: panel.c:panel_on_monitor_change(): monitor pointer: 0x15a9cd0
** (way-shell:1112061): DEBUG: 09:45:27.863: panel.c:panel_on_monitor_change(): initialized bar for monitor: [LG Electronics LG HDR 4K 0x0000F5CA (HDMI-A-1)] [LG HDR 4K] [HDMI-A-1]
When I unplug and plug the monitor back in we get:
** (way-shell:1112061): DEBUG: 09:47:00.835: panel.c:panel_on_monitor_change(): monitor pointer: 0x15a88f0
** (way-shell:1112061): DEBUG: 09:47:00.835: panel.c:panel_on_monitor_change(): bar already exists for monitor [California Institute of Technology 0x1404 (eDP-1)] [0x1404] [eDP-1]
** (way-shell:1112061): DEBUG: 09:47:00.835: panel.c:panel_on_monitor_change(): monitor pointer: 0x3a3ec30
** (way-shell:1112061): DEBUG: 09:47:00.858: panel.c:panel_on_monitor_change(): initialized bar for monitor: [(null)] [(null)] [(null)]
The issue here is that we seem to get all NULL's for the monitor in the next event. Either, the event is occurring before the monitor's data is available or the monitor's data is simply unavailable for some reason.
My code was trying to track monitors by their pointers, which now I see won't work because a new pointer is allocated when the monitor is disconnected and reconnected (completely legit, and something I just overlooked). However, because all fields seem to be NULL that I'm outputting for debug anyway, this leaves me with nothing to reliably track a monitor's identity with.
Is this a known issue.
I'm on Sway v1.8, Fedora 39.