@@ -120,75 +120,60 @@ def cfactory(func, argtypes, restype):
120120 cfactory (func = "CGDataProviderRelease" , argtypes = [void ], restype = void )
121121 cfactory (func = "CFRelease" , argtypes = [void ], restype = void )
122122
123- @property
124- def monitors (self ):
125- # type: () -> Monitors
126- """ Get positions of monitors (see parent class). """
127-
128- if not self ._monitors :
129- int_ = int
130- core = self .core
131-
132- # All monitors
133- # We need to update the value with every single monitor found
134- # using CGRectUnion. Else we will end with infinite values.
135- all_monitors = CGRect ()
136- self ._monitors .append ({})
137-
138- # Each monitors
139- display_count = ctypes .c_uint32 (0 )
140- active_displays = (ctypes .c_uint32 * self .max_displays )()
141- core .CGGetActiveDisplayList (
142- self .max_displays , active_displays , ctypes .byref (display_count )
123+ def _monitors_impl (self ):
124+ # type: () -> None
125+ """ Get positions of monitors. It will populate self._monitors. """
126+
127+ int_ = int
128+ core = self .core
129+
130+ # All monitors
131+ # We need to update the value with every single monitor found
132+ # using CGRectUnion. Else we will end with infinite values.
133+ all_monitors = CGRect ()
134+ self ._monitors .append ({})
135+
136+ # Each monitors
137+ display_count = ctypes .c_uint32 (0 )
138+ active_displays = (ctypes .c_uint32 * self .max_displays )()
139+ core .CGGetActiveDisplayList (
140+ self .max_displays , active_displays , ctypes .byref (display_count )
141+ )
142+ rotations = {0.0 : "normal" , 90.0 : "right" , - 90.0 : "left" }
143+ for idx in range (display_count .value ):
144+ display = active_displays [idx ]
145+ rect = core .CGDisplayBounds (display )
146+ rect = core .CGRectStandardize (rect )
147+ width , height = rect .size .width , rect .size .height
148+ rot = core .CGDisplayRotation (display )
149+ if rotations [rot ] in ["left" , "right" ]:
150+ width , height = height , width
151+ self ._monitors .append (
152+ {
153+ "left" : int_ (rect .origin .x ),
154+ "top" : int_ (rect .origin .y ),
155+ "width" : int_ (width ),
156+ "height" : int_ (height ),
157+ }
143158 )
144- rotations = {0.0 : "normal" , 90.0 : "right" , - 90.0 : "left" }
145- for idx in range (display_count .value ):
146- display = active_displays [idx ]
147- rect = core .CGDisplayBounds (display )
148- rect = core .CGRectStandardize (rect )
149- width , height = rect .size .width , rect .size .height
150- rot = core .CGDisplayRotation (display )
151- if rotations [rot ] in ["left" , "right" ]:
152- width , height = height , width
153- self ._monitors .append (
154- {
155- "left" : int_ (rect .origin .x ),
156- "top" : int_ (rect .origin .y ),
157- "width" : int_ (width ),
158- "height" : int_ (height ),
159- }
160- )
161-
162- # Update AiO monitor's values
163- all_monitors = core .CGRectUnion (all_monitors , rect )
164-
165- # Set the AiO monitor's values
166- self ._monitors [0 ] = {
167- "left" : int_ (all_monitors .origin .x ),
168- "top" : int_ (all_monitors .origin .y ),
169- "width" : int_ (all_monitors .size .width ),
170- "height" : int_ (all_monitors .size .height ),
171- }
172-
173- return self ._monitors
174-
175- def grab (self , monitor ):
159+
160+ # Update AiO monitor's values
161+ all_monitors = core .CGRectUnion (all_monitors , rect )
162+
163+ # Set the AiO monitor's values
164+ self ._monitors [0 ] = {
165+ "left" : int_ (all_monitors .origin .x ),
166+ "top" : int_ (all_monitors .origin .y ),
167+ "width" : int_ (all_monitors .size .width ),
168+ "height" : int_ (all_monitors .size .height ),
169+ }
170+
171+ def _grab_impl (self , monitor ):
176172 # type: (Monitor) -> ScreenShot
177- """
178- See :meth:`MSSBase.grab <mss.base.MSSBase.grab>` for full details.
179- """
173+ """ Retrieve all pixels from a monitor. Pixels have to be RGB. """
180174
181175 # pylint: disable=too-many-locals
182176
183- # Convert PIL bbox style
184- if isinstance (monitor , tuple ):
185- monitor = {
186- "left" : monitor [0 ],
187- "top" : monitor [1 ],
188- "width" : monitor [2 ] - monitor [0 ],
189- "height" : monitor [3 ] - monitor [1 ],
190- }
191-
192177 core = self .core
193178 rect = CGRect (
194179 (monitor ["left" ], monitor ["top" ]), (monitor ["width" ], monitor ["height" ])
0 commit comments