I've recently started using this library to get at structured RandR information. It's been really easy to jump in and start working with but couldn't find a way to get at the screen refresh rate information.
After a bit of searching around and reading up on XRandR I noticed that the xrandr_get_screen_info() function is what I was interested in but it looks like the refresh rates list is currently tagged with a FIXME.
I did a bit of debugging/reading and figured out that:
The refresh rate list was added in version 1.2 (?) (requires call to xrandr_query_version())
The sub-lists are not 32-bit aligned (requires removing padding to unpack correctly)
I was able to get it working with the below changes (admittedly I have not tested the code extensively but simply setting the pad argument to 0 appears to extract the list without breaking backwards compatibility).
diff --git a/Xlib/ext/randr.py b/Xlib/ext/randr.py
index 0a1dfb9..c15ec95 100644
--- a/Xlib/ext/randr.py+++ b/Xlib/ext/randr.py@@ -151,7 +151,7 @@ RandR_ModeInfo = rq.Struct(
RandR_Rates = rq.Struct(
rq.LengthOf('rates', 2),
- rq.List('rates', rq.Card16Obj)+ rq.List('rates', rq.Card16Obj, pad = 0)
)
# TODO: This struct is part of the RENDER extension and should be moved there
@@ -323,7 +323,7 @@ class GetScreenInfo(rq.ReplyRequest):
rq.Card16('n_rate_ents'), # XCB's protocol description disagrees with the X headers on this; ignoring.
rq.Pad(2),
rq.List('sizes', RandR_ScreenSizes),
- #rq.List('rates', RandR_Rates) #FIXME: Why does uncommenting this cause an error?+ rq.List('rates', RandR_Rates)
)
def get_screen_info(self):
I am still very new to this code base, Xrandr and the X Server Protocol in general so I'm not sure if this could cause issues elsewhere. This method doesn't get the size of the refresh rate list ahead of time and I toyed with the idea of using either the length of the size list or n_rate_ents to compute the length but this feels cleaner and safer.
Hoping to get a second opinion or see if this fix might be considered.
Quick example of getting the rates from root screen (both with "initial" and latest version of Xrandr):
I've recently started using this library to get at structured RandR information. It's been really easy to jump in and start working with but couldn't find a way to get at the screen refresh rate information.
After a bit of searching around and reading up on XRandR I noticed that the
xrandr_get_screen_info()function is what I was interested in but it looks like the refresh rates list is currently tagged with a FIXME.I did a bit of debugging/reading and figured out that:
xrandr_query_version())I was able to get it working with the below changes (admittedly I have not tested the code extensively but simply setting the pad argument to 0 appears to extract the list without breaking backwards compatibility).
I am still very new to this code base, Xrandr and the X Server Protocol in general so I'm not sure if this could cause issues elsewhere. This method doesn't get the size of the refresh rate list ahead of time and I toyed with the idea of using either the length of the size list or
n_rate_entsto compute the length but this feels cleaner and safer.Hoping to get a second opinion or see if this fix might be considered.
Quick example of getting the rates from root screen (both with "initial" and latest version of Xrandr):
The text was updated successfully, but these errors were encountered: