# Taken from Glyph, Eevee on https://stackoverflow.com/questions/1225057/how-can-i-determine-the-monitor-refresh-rate
# Deconstruction, Commenting and Renaming by Cutieguwu.

from Xlib import display
from Xlib.ext import randr

displayGlobal = display.Display()                                                           # Get every display thing. Maybe a WM object?
default_screen = displayGlobal.get_default_screen()                                         # Find default display for some reason.
info = displayGlobal.screen(default_screen)                                                 # Use this as a point to get information about all screens.

displayConfigs = randr.get_screen_resources(info.root)                                      # Get every screen's possible configurations.
ConfigsActive = set()                                                                       # Create an empty set to add configurations to.

for config in displayConfigs.crtcs:                                                         # For every display configuration, determine if it's active and add its identifier to the configurations in use.
    crtc_info = randr.get_crtc_info(info.root, config, displayConfigs.config_timestamp)
    if crtc_info.mode:
        ConfigsActive.add(crtc_info.mode)

for config in displayConfigs.modes:
    if config.id in ConfigsActive:                                                          # For every active display mode, figure out its framerate.
        print(config.dot_clock / (config.h_total * config.v_total))