Search code examples
x11subscriptionpollingxrandr

Get informed about display changes


I know about the libxrandr library but reading out newly attached monitor/display information, like available resolutions, requires polling.

Is there a way, in a CPP program, to get informed about changes on attached displays without asking RandR every x seconds?


Solution

  • At least if you are using Gnome and Mutter you can listen to the dbus signals of Mutter.

    Example of a dbus method in the same namespace:

    dbus-send --session --print-reply --dest=org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig.GetCurrentState
    

    Use a DBus viewer to find the signal you are looking for.

    I don't know a solution for any other window manager