@@ -235,8 +235,8 @@ def _set_cfunctions(self):
235
235
See https://tronche.com/gui/x/xlib/function-index.html for details.
236
236
"""
237
237
238
- def cfactory (attr = self . xlib , func = None , argtypes = None , restype = None ):
239
- # type: (Any, str, List[Any], Any) -> None
238
+ def cfactory (func , argtypes , restype , attr = self . xlib ):
239
+ # type: (str, List[Any], Any , Any) -> None
240
240
""" Factorize ctypes creations. """
241
241
self ._cfactory (
242
242
attr = attr ,
@@ -254,30 +254,18 @@ def cfactory(attr=self.xlib, func=None, argtypes=None, restype=None):
254
254
char_p = ctypes .c_char_p
255
255
pointer = ctypes .POINTER
256
256
257
- cfactory (func = "XSetErrorHandler" , argtypes = [void ], restype = c_int )
257
+ cfactory ("XSetErrorHandler" , [void ], c_int )
258
+ cfactory ("XGetErrorText" , [pointer (Display ), c_int , char_p , c_int ], void )
259
+ cfactory ("XOpenDisplay" , [char_p ], pointer (Display ))
260
+ cfactory ("XDefaultRootWindow" , [pointer (Display )], pointer (XWindowAttributes ))
258
261
cfactory (
259
- func = "XGetErrorText " ,
260
- argtypes = [pointer (Display ), c_int , char_p , c_int ],
261
- restype = void ,
262
+ "XGetWindowAttributes " ,
263
+ [pointer (Display ), pointer ( XWindowAttributes ), pointer ( XWindowAttributes ) ],
264
+ c_int ,
262
265
)
263
- cfactory (func = "XOpenDisplay" , argtypes = [char_p ], restype = pointer (Display ))
264
266
cfactory (
265
- func = "XDefaultRootWindow" ,
266
- argtypes = [pointer (Display )],
267
- restype = pointer (XWindowAttributes ),
268
- )
269
- cfactory (
270
- func = "XGetWindowAttributes" ,
271
- argtypes = [
272
- pointer (Display ),
273
- pointer (XWindowAttributes ),
274
- pointer (XWindowAttributes ),
275
- ],
276
- restype = c_int ,
277
- )
278
- cfactory (
279
- func = "XGetImage" ,
280
- argtypes = [
267
+ "XGetImage" ,
268
+ [
281
269
pointer (Display ),
282
270
pointer (Display ),
283
271
c_int ,
@@ -287,48 +275,43 @@ def cfactory(attr=self.xlib, func=None, argtypes=None, restype=None):
287
275
ulong ,
288
276
c_int ,
289
277
],
290
- restype = pointer (XImage ),
278
+ pointer (XImage ),
291
279
)
292
- cfactory (func = "XDestroyImage" , argtypes = [pointer (XImage )], restype = void )
280
+ cfactory ("XDestroyImage" , [pointer (XImage )], void )
293
281
294
282
# A simple benchmark calling 10 times those 2 functions:
295
283
# XRRGetScreenResources(): 0.1755971429956844 s
296
284
# XRRGetScreenResourcesCurrent(): 0.0039125580078689 s
297
285
# The second is faster by a factor of 44! So try to use it first.
298
286
try :
299
287
cfactory (
288
+ "XRRGetScreenResourcesCurrent" ,
289
+ [pointer (Display ), pointer (Display )],
290
+ pointer (XRRScreenResources ),
300
291
attr = self .xrandr ,
301
- func = "XRRGetScreenResourcesCurrent" ,
302
- argtypes = [pointer (Display ), pointer (Display )],
303
- restype = pointer (XRRScreenResources ),
304
292
)
305
293
except AttributeError :
306
294
cfactory (
295
+ "XRRGetScreenResources" ,
296
+ [pointer (Display ), pointer (Display )],
297
+ pointer (XRRScreenResources ),
307
298
attr = self .xrandr ,
308
- func = "XRRGetScreenResources" ,
309
- argtypes = [pointer (Display ), pointer (Display )],
310
- restype = pointer (XRRScreenResources ),
311
299
)
312
300
self .xrandr .XRRGetScreenResourcesCurrent = self .xrandr .XRRGetScreenResources
313
301
314
302
cfactory (
303
+ "XRRGetCrtcInfo" ,
304
+ [pointer (Display ), pointer (XRRScreenResources ), c_long ],
305
+ pointer (XRRCrtcInfo ),
315
306
attr = self .xrandr ,
316
- func = "XRRGetCrtcInfo" ,
317
- argtypes = [pointer (Display ), pointer (XRRScreenResources ), c_long ],
318
- restype = pointer (XRRCrtcInfo ),
319
- )
320
- cfactory (
321
- attr = self .xrandr ,
322
- func = "XRRFreeScreenResources" ,
323
- argtypes = [pointer (XRRScreenResources )],
324
- restype = void ,
325
307
)
326
308
cfactory (
309
+ "XRRFreeScreenResources" ,
310
+ [pointer (XRRScreenResources )],
311
+ void ,
327
312
attr = self .xrandr ,
328
- func = "XRRFreeCrtcInfo" ,
329
- argtypes = [pointer (XRRCrtcInfo )],
330
- restype = void ,
331
313
)
314
+ cfactory ("XRRFreeCrtcInfo" , [pointer (XRRCrtcInfo )], void , attr = self .xrandr )
332
315
333
316
def get_error_details (self ):
334
317
# type: () -> Optional[Dict[str, Any]]
0 commit comments