@@ -301,13 +301,7 @@ def __del__(self):
301301 pass
302302
303303 def __init__ (self ):
304- ''' GNU/Linux initialisations.
305-
306- Paths where the MSS library is loaded from:
307- - /usr/local/lib/pythonx.y/dist-packages/
308- - current working directory
309- if no one found, use of the _very_ slow method get_pixels_slow().
310- '''
304+ ''' GNU/Linux initialisations. '''
311305
312306 disp = None
313307 self .display = None
@@ -330,26 +324,12 @@ def __init__(self):
330324 raise ScreenshotError ('MSS: no Xrandr library found.' )
331325 self .xrandr = cdll .LoadLibrary (xrandr )
332326
333- v_maj , v_min , _ , _ , _ = sys .version_info
334- lib_dir = '/usr/local/lib/python{0}.{1}/dist-packages' .format (v_maj ,
335- v_min )
336- libmss = '{0}/libmss.so' .format (lib_dir )
337- try :
327+ libmss = find_library ('mss' )
328+ if libmss :
338329 self .mss = cdll .LoadLibrary (libmss )
339- except OSError :
340- try :
341- libmss = '{0}/libmss.cpython-{1}{2}m.so' .format (lib_dir , v_maj ,
342- v_min )
343- self .mss = cdll .LoadLibrary (libmss )
344- except OSError :
345- try :
346- libmss = find_library ('mss' )
347- self .mss = cdll .LoadLibrary (libmss )
348- except OSError :
349- msg = 'MSS: no MSS library found. ' + \
350- 'Using slow native function.'
351- print (msg )
352- self .mss = False
330+ else :
331+ print ('MSS: no MSS library found. Using slow native function.' )
332+ self .mss = False
353333
354334 self ._set_argtypes ()
355335 self ._set_restypes ()
@@ -416,7 +396,7 @@ def _set_restypes(self):
416396 self .xrandr .XRRFreeScreenResources .restype = c_void_p
417397 self .xrandr .XRRFreeCrtcInfo .restype = c_void_p
418398 if self .mss :
419- self .mss .GetXImagePixels .restype = c_void_p
399+ self .mss .GetXImagePixels .restype = c_int
420400
421401 def enum_display_monitors (self , screen = 0 ):
422402 ''' Get positions of one or more monitors.
@@ -474,10 +454,15 @@ def get_pixels(self, monitor):
474454 else :
475455 buffer_len = height * width * 3
476456 self .image = create_string_buffer (buffer_len )
477- self .mss .GetXImagePixels (ximage , width , height ,
478- ximage .contents .red_mask ,
479- ximage .contents .green_mask ,
480- ximage .contents .blue_mask , self .image )
457+ ret = self .mss .GetXImagePixels (ximage , width , height ,
458+ ximage .contents .red_mask ,
459+ ximage .contents .green_mask ,
460+ ximage .contents .blue_mask ,
461+ self .image )
462+ if not ret :
463+ self .xlib .XDestroyImage (ximage )
464+ err = 'MSS: libmss.GetXImagePixels() failed ({0}).' .format (ret )
465+ raise ScreenshotError (err )
481466 self .xlib .XDestroyImage (ximage )
482467 return self .image
483468
0 commit comments