Skip to content

Commit 849e1fe

Browse files
committed
Linux: improve monitors finding
A simple benchmark calling 10 times those 2 functions: XRRGetScreenResources(): 0.1755971429956844 s XRRGetScreenResourcesCurrent(): 0.0039125580078689 s The second is faster by a factor of 44! So try to use it first.
1 parent e3460c9 commit 849e1fe

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ History:
44

55
4.0.1 2019/0x/xx
66
- Linux: fix several XLib functions signature (fixes #92)
7+
- Linux: improve monitors finding by a factor of 44
78

89
4.0.0 2019/01/11
910
- MSS: remove use of setup.py for setup.cfg

mss/linux.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,26 @@ def cfactory(
252252
cfactory(func="XDestroyImage", argtypes=[pointer(XImage)], restype=void)
253253
cfactory(func="XCloseDisplay", argtypes=[pointer(Display)], restype=void)
254254

255-
cfactory(
256-
attr=self.xrandr,
257-
func="XRRGetScreenResources",
258-
argtypes=[pointer(Display), pointer(Display)],
259-
restype=pointer(XRRScreenResources),
260-
)
255+
# A simple benchmark calling 10 times those 2 functions:
256+
# XRRGetScreenResources(): 0.1755971429956844 s
257+
# XRRGetScreenResourcesCurrent(): 0.0039125580078689 s
258+
# The second is faster by a factor of 44! So try to use it first.
259+
try:
260+
cfactory(
261+
attr=self.xrandr,
262+
func="XRRGetScreenResourcesCurrent",
263+
argtypes=[pointer(Display), pointer(Display)],
264+
restype=pointer(XRRScreenResources),
265+
)
266+
except AttributeError:
267+
cfactory(
268+
attr=self.xrandr,
269+
func="XRRGetScreenResources",
270+
argtypes=[pointer(Display), pointer(Display)],
271+
restype=pointer(XRRScreenResources),
272+
)
273+
self.xrandr.XRRGetScreenResourcesCurrent = self.xrandr.XRRGetScreenResources
274+
261275
cfactory(
262276
attr=self.xrandr,
263277
func="XRRGetCrtcInfo",
@@ -338,7 +352,7 @@ def monitors(self):
338352
)
339353

340354
# Each monitors
341-
mon = self.xrandr.XRRGetScreenResources(self.display, self.drawable)
355+
mon = self.xrandr.XRRGetScreenResourcesCurrent(self.display, self.drawable)
342356
for idx in range(mon.contents.ncrtc):
343357
crtc = self.xrandr.XRRGetCrtcInfo(
344358
self.display, mon, mon.contents.crtcs[idx]

0 commit comments

Comments
 (0)