@@ -26,30 +26,35 @@ def cgfloat():
2626 return ctypes .c_double if sys .maxsize > 2 ** 32 else ctypes .c_float
2727
2828
29- def get_infinity (maxi = False ):
30- # type: (bool) -> float
31- """ Get infinity "numbers". """
32-
33- return 1.7976931348623157e+308 if maxi else - 8.988465674311579e+307
34-
35-
3629class CGPoint (ctypes .Structure ):
3730 """ Structure that contains coordinates of a rectangle. """
3831
3932 _fields_ = [('x' , cgfloat ()), ('y' , cgfloat ())]
4033
34+ def __repr__ (self ):
35+ return '{0}(left={cls.x} top={cls.y})' .format (
36+ type (self ).__name__ , cls = self )
37+
4138
4239class CGSize (ctypes .Structure ):
4340 """ Structure that contains dimensions of an rectangle. """
4441
4542 _fields_ = [('width' , cgfloat ()), ('height' , cgfloat ())]
4643
44+ def __repr__ (self ):
45+ return '{0}(width={cls.width} height={cls.height})' .format (
46+ type (self ).__name__ , cls = self )
47+
4748
4849class CGRect (ctypes .Structure ):
4950 """ Structure that contains informations about a rectangle. """
5051
5152 _fields_ = [('origin' , CGPoint ), ('size' , CGSize )]
5253
54+ def __repr__ (self ):
55+ return '{0}<{cls.origin} {cls.size}>' .format (
56+ type (self ).__name__ , cls = self )
57+
5358
5459class MSS (MSSBase ):
5560 """
@@ -81,6 +86,7 @@ def _set_argtypes(self):
8186 ctypes .POINTER (ctypes .c_uint32 )]
8287 self .core .CGDisplayBounds .argtypes = [ctypes .c_uint32 ]
8388 self .core .CGRectStandardize .argtypes = [CGRect ]
89+ self .core .CGRectUnion .argtypes = [CGRect , CGRect ]
8490 self .core .CGDisplayRotation .argtypes = [ctypes .c_uint32 ]
8591 self .core .CGWindowListCreateImage .argtypes = [
8692 CGRect ,
@@ -100,6 +106,7 @@ def _set_restypes(self):
100106 self .core .CGGetActiveDisplayList .restype = ctypes .c_int32
101107 self .core .CGDisplayBounds .restype = CGRect
102108 self .core .CGRectStandardize .restype = CGRect
109+ self .core .CGRectUnion .restype = CGRect
103110 self .core .CGDisplayRotation .restype = ctypes .c_float
104111 self .core .CGWindowListCreateImage .restype = ctypes .c_void_p
105112 self .core .CGImageGetDataProvider .restype = ctypes .c_void_p
@@ -115,12 +122,10 @@ def monitors(self):
115122
116123 if not self ._monitors :
117124 # All monitors
118- self ._monitors .append ({
119- 'left' : int (get_infinity ()),
120- 'top' : int (get_infinity ()),
121- 'width' : int (get_infinity (True )),
122- 'height' : int (get_infinity (True )),
123- })
125+ # We need to update the value with every single monitor found
126+ # using CGRectUnion. Else we will end with infinite values.
127+ all_monitors = CGRect ()
128+ self ._monitors .append ({})
124129
125130 # Each monitors
126131 display_count = ctypes .c_uint32 (0 )
@@ -133,18 +138,28 @@ def monitors(self):
133138 display = active_displays [idx ]
134139 rect = self .core .CGDisplayBounds (display )
135140 rect = self .core .CGRectStandardize (rect )
136- left , top = rect .origin .x , rect .origin .y
137141 width , height = rect .size .width , rect .size .height
138142 rot = self .core .CGDisplayRotation (display )
139143 if rotations [rot ] in ['left' , 'right' ]:
140144 width , height = height , width
141145 self ._monitors .append ({
142- 'left' : int (left ),
143- 'top' : int (top ),
146+ 'left' : int (rect . origin . x ),
147+ 'top' : int (rect . origin . y ),
144148 'width' : int (width ),
145149 'height' : int (height ),
146150 })
147151
152+ # Update AiO monitor's values
153+ all_monitors = self .core .CGRectUnion (all_monitors , rect )
154+
155+ # Update AiO monitor's values
156+ self ._monitors [0 ] = {
157+ 'left' : int (all_monitors .origin .x ),
158+ 'top' : int (all_monitors .origin .y ),
159+ 'width' : int (all_monitors .size .width ),
160+ 'height' : int (all_monitors .size .height ),
161+ }
162+
148163 return self ._monitors
149164
150165 def grab (self , monitor ):
@@ -178,10 +193,6 @@ def grab(self, monitor):
178193 if rounded_width != monitor ['width' ]:
179194 data = self .resize (data , monitor )
180195
181- if len (data ) != monitor ['width' ] * monitor ['height' ] * 4 :
182- del data
183- raise ScreenShotError ('Data length mismatch.' , locals ())
184-
185196 return self .cls_image (data , monitor )
186197
187198 @staticmethod
0 commit comments