@@ -253,6 +253,7 @@ def enum_display_monitors(self, screen=0):
253
253
254
254
if screen == - 1 :
255
255
rect = CGRectInfinite
256
+ self .debug ('enum_display_monitors' , 'rect' , rect )
256
257
yield ({
257
258
b'left' : int (rect .origin .x ),
258
259
b'top' : int (rect .origin .y ),
@@ -263,11 +264,14 @@ def enum_display_monitors(self, screen=0):
263
264
max_displays = 32 # Could be augmented, if needed ...
264
265
rotations = {0.0 : 'normal' , 90.0 : 'right' , - 90.0 : 'left' }
265
266
_ , ids , _ = CGGetActiveDisplayList (max_displays , None , None )
267
+ self .debug ('enum_display_monitors' , 'ids' , ids )
266
268
for display in ids :
267
269
rect = CGRectStandardize (CGDisplayBounds (display ))
270
+ self .debug ('enum_display_monitors' , 'rect' , rect )
268
271
left , top = rect .origin .x , rect .origin .y
269
272
width , height = rect .size .width , rect .size .height
270
273
rot = CGDisplayRotation (display )
274
+ self .debug ('enum_display_monitors' , 'rot' , rot )
271
275
if rotations [rot ] in ['left' , 'right' ]:
272
276
width , height = height , width
273
277
yield ({
@@ -290,6 +294,12 @@ def get_pixels(self, monitor):
290
294
winid = kCGNullWindowID
291
295
default = kCGWindowImageDefault
292
296
self .image = CGWindowListCreateImage (rect , options , winid , default )
297
+
298
+ self .debug ('get_pixels' , 'rect' , rect )
299
+ self .debug ('get_pixels' , 'options' , options )
300
+ self .debug ('get_pixels' , 'winid' , winid )
301
+ self .debug ('get_pixels' , 'default' , default )
302
+
293
303
if not self .image :
294
304
raise ScreenshotError ('MSS: CGWindowListCreateImage() failed.' )
295
305
return self .image
@@ -300,9 +310,13 @@ def save_img(self, data, width, height, output):
300
310
self .debug ('save_img' )
301
311
302
312
url = NSURL .fileURLWithPath_ (output )
303
- if not CGImageDestinationCreateWithURL (url , kUTTypePNG , 1 , None ):
313
+ dest = CGImageDestinationCreateWithURL (url , kUTTypePNG , 1 , None )
314
+ self .debug ('save_img' , 'url' , url )
315
+ self .debug ('save_img' , 'dest' , dest )
316
+ if not dest :
304
317
err = 'MSS : CGImageDestinationCreateWithURL() failed.'
305
318
raise ScreenshotError (err )
319
+
306
320
CGImageDestinationAddImage (dest , data , None )
307
321
if not CGImageDestinationFinalize (dest ):
308
322
raise ScreenshotError ('MSS: CGImageDestinationFinalize() failed.' )
@@ -333,13 +347,13 @@ def __init__(self):
333
347
if not x11 :
334
348
raise ScreenshotError ('MSS: no X11 library found.' )
335
349
self .xlib = cdll .LoadLibrary (x11 )
336
- self .debug ('init ' , 'xlib' , self .xlib )
350
+ self .debug ('__init__ ' , 'self. xlib' , self .xlib )
337
351
338
352
xrandr = find_library ('Xrandr' )
339
353
if not xrandr :
340
354
raise ScreenshotError ('MSS: no Xrandr library found.' )
341
355
self .xrandr = cdll .LoadLibrary (xrandr )
342
- self .debug ('init ' , 'xrandr' , self .xrandr )
356
+ self .debug ('__init__ ' , 'self. xrandr' , self .xrandr )
343
357
344
358
self ._set_argtypes ()
345
359
self ._set_restypes ()
@@ -354,16 +368,16 @@ def __init__(self):
354
368
except KeyError :
355
369
err = 'MSS: $DISPLAY not set. Stopping to prevent segfault.'
356
370
raise ScreenshotError (err )
357
- self .debug ('init ' , '$DISPLAY' , disp )
371
+ self .debug ('__init__ ' , '$DISPLAY' , disp )
358
372
359
373
# At this point, if there is no running server, it could end on
360
374
# a segmentation fault. And we cannot catch it.
361
375
self .display = self .xlib .XOpenDisplay (disp )
362
- self .debug ('init ' , 'display' , self .display )
376
+ self .debug ('__init__ ' , 'self. display' , self .display )
363
377
self .screen = self .xlib .XDefaultScreen (self .display )
364
- self .debug ('init ' , 'screen' , self .screen )
378
+ self .debug ('__init__ ' , 'self. screen' , self .screen )
365
379
self .root = self .xlib .XDefaultRootWindow (self .display , self .screen )
366
- self .debug ('init ' , 'root' , self .root )
380
+ self .debug ('__init__ ' , 'self. root' , self .root )
367
381
368
382
def _set_argtypes (self ):
369
383
''' Functions arguments. '''
@@ -422,6 +436,7 @@ def enum_display_monitors(self, screen=0):
422
436
if screen == - 1 :
423
437
gwa = XWindowAttributes ()
424
438
self .xlib .XGetWindowAttributes (self .display , self .root , byref (gwa ))
439
+ self .debug ('enum_display_monitors' , 'gwa' , gwa )
425
440
yield ({
426
441
b'left' : int (gwa .x ),
427
442
b'top' : int (gwa .y ),
@@ -433,6 +448,8 @@ def enum_display_monitors(self, screen=0):
433
448
# expected LP_Display instance instead of LP_XWindowAttributes
434
449
root = cast (self .root , POINTER (Display ))
435
450
mon = self .xrandr .XRRGetScreenResources (self .display , root )
451
+ self .debug ('enum_display_monitors' , 'root' , root )
452
+ self .debug ('enum_display_monitors' , 'mon' , mon )
436
453
self .debug ('enum_display_monitors' , 'number of monitors' ,
437
454
mon .contents .ncrtc )
438
455
for num in range (mon .contents .ncrtc ):
@@ -462,9 +479,11 @@ def get_pixels(self, monitor):
462
479
# Fix for XGetImage:
463
480
# expected LP_Display instance instead of LP_XWindowAttributes
464
481
root = cast (self .root , POINTER (Display ))
482
+ self .debug ('get_pixels' , 'root' , root )
465
483
466
484
ximage = self .xlib .XGetImage (self .display , root , left , top , width ,
467
485
height , allplanes , ZPixmap )
486
+ self .debug ('get_pixels' , 'ximage' , ximage )
468
487
if not ximage :
469
488
raise ScreenshotError ('MSS: XGetImage() failed.' )
470
489
@@ -474,17 +493,23 @@ def pix(pixel, _resultats={}, b=pack):
474
493
This method uses of memoization.
475
494
'''
476
495
if pixel not in _resultats :
477
- _resultats [pixel ] = b (b'<B' , (pixel & 16711680 ) >> 16 ) + \
478
- b (b'<B' , (pixel & 65280 ) >> 8 ) + b (b'<B' , pixel & 255 )
496
+ _resultats [pixel ] = b (b'<B' , (pixel & rmask ) >> 16 ) + \
497
+ b (b'<B' , (pixel & gmask ) >> 8 ) + b (b'<B' , pixel & bmask )
479
498
return _resultats [pixel ]
480
499
481
500
# http://cgit.freedesktop.org/xorg/lib/libX11/tree/src/ImUtil.c#n444
482
501
get_pix = self .xlib .XGetPixel
502
+ rmask = ximage .contents .red_mask
503
+ gmask = ximage .contents .green_mask
504
+ bmask = ximage .contents .blue_mask
505
+ self .debug ('get_pixels' , 'rmask' , rmask )
506
+ self .debug ('get_pixels' , 'gmask' , gmask )
507
+ self .debug ('get_pixels' , 'bmask' , bmask )
483
508
pixels = [pix (get_pix (ximage , x , y ))
484
509
for y in range (height ) for x in range (width )]
510
+ self .image = b'' .join (pixels )
485
511
486
512
self .xlib .XDestroyImage (ximage )
487
- self .image = b'' .join (pixels )
488
513
return self .image
489
514
490
515
@@ -644,7 +669,6 @@ def main():
644
669
645
670
systems = {'Darwin' : MSSMac , 'Linux' : MSSLinux , 'Windows' : MSSWindows }
646
671
mss = systems [system ()]()
647
- # mss.DEBUG = True
648
672
649
673
def on_exists (fname ):
650
674
''' Callback example when we try to overwrite an existing
0 commit comments