X Tutup
The Wayback Machine - https://web.archive.org/web/20210106130913/https://github.com/python-xlib/python-xlib/issues/145
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RandR: get_screen_info() missing refresh rates [possible fix] #145

Open
elysid opened this issue Jun 4, 2019 · 0 comments
Open

RandR: get_screen_info() missing refresh rates [possible fix] #145

elysid opened this issue Jun 4, 2019 · 0 comments

Comments

@elysid
Copy link

@elysid elysid commented Jun 4, 2019

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):

Python 3.7.3 (default, Mar 26 2019, 21:43:19) 
[GCC 8.2.1 20181127] on linux
Type "help", "copyright", "credits" or "license" for more information.
+>>> from Xlib import display
+>>> from Xlib.ext import randr
+>>> import pprint
+>>> d = display.Display()
+>>> d.screen().root.xrandr_get_screen_info().rates
[]
+>>> d.xrandr_query_version()
<<class 'Xlib.ext.randr.QueryVersion'> serial = 15, data = {'sequence_number': 15, 'major_version': 1, 'minor_version': 3}, error = None>
+>>> pprint.pprint([ r._data for r in d.screen().root.xrandr_get_screen_info().rates ])
[{'rates': [60]},
 {'rates': [60]},
 {'rates': [60]},
 {'rates': [60]},
 {'rates': [60]},
 {'rates': [60]},
 {'rates': [60]},
 {'rates': [60]},
 {'rates': [60, 56]},
 {'rates': [60]},
 {'rates': [60]},
 {'rates': [60]},
 {'rates': [60, 59]},
 {'rates': [60, 59]},
 {'rates': []}]
+>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.
X Tutup