Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/mss/darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@
import ctypes
import ctypes.util
import sys
from ctypes import POINTER, Structure, c_double, c_float, c_int32, c_ubyte, c_uint32, c_uint64, c_void_p
from ctypes import (
POINTER,
Structure,
c_double,
c_float,
c_int32,
c_long,
c_size_t,
c_ubyte,
c_uint32,
c_void_p,
)
from platform import mac_ver
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -75,17 +86,17 @@ def __repr__(self) -> str:
# Syntax: cfunction: (attr, argtypes, restype)
"CGDataProviderCopyData": ("core", [c_void_p], c_void_p),
"CGDisplayBounds": ("core", [c_uint32], CGRect),
"CGDisplayRotation": ("core", [c_uint32], c_float),
"CFDataGetBytePtr": ("core", [c_void_p], c_void_p),
"CFDataGetLength": ("core", [c_void_p], c_uint64),
"CFRelease": ("core", [c_void_p], c_void_p),
"CGDataProviderRelease": ("core", [c_void_p], c_void_p),
"CGDisplayRotation": ("core", [c_uint32], c_double),
"CFDataGetBytePtr": ("core", [c_void_p], POINTER(c_ubyte)),
"CFDataGetLength": ("core", [c_void_p], c_long),
"CFRelease": ("core", [c_void_p], None),
"CGDataProviderRelease": ("core", [c_void_p], None),
"CGGetActiveDisplayList": ("core", [c_uint32, POINTER(c_uint32), POINTER(c_uint32)], c_int32),
"CGImageGetBitsPerPixel": ("core", [c_void_p], int),
"CGImageGetBytesPerRow": ("core", [c_void_p], int),
"CGImageGetBitsPerPixel": ("core", [c_void_p], c_size_t),
"CGImageGetBytesPerRow": ("core", [c_void_p], c_size_t),
"CGImageGetDataProvider": ("core", [c_void_p], c_void_p),
"CGImageGetHeight": ("core", [c_void_p], int),
"CGImageGetWidth": ("core", [c_void_p], int),
"CGImageGetHeight": ("core", [c_void_p], c_size_t),
"CGImageGetWidth": ("core", [c_void_p], c_size_t),
"CGRectStandardize": ("core", [CGRect], CGRect),
"CGRectUnion": ("core", [CGRect, CGRect], CGRect),
"CGWindowListCreateImage": ("core", [CGRect, c_uint32, c_uint32, c_uint32], c_void_p),
Expand Down Expand Up @@ -197,7 +208,7 @@ def _grab_impl(self, monitor: Monitor, /) -> ScreenShot:

width = core.CGImageGetWidth(image_ref)
height = core.CGImageGetHeight(image_ref)
prov = copy_data = None
copy_data = None
try:
prov = core.CGImageGetDataProvider(image_ref)
copy_data = core.CGDataProviderCopyData(prov)
Expand All @@ -219,10 +230,9 @@ def _grab_impl(self, monitor: Monitor, /) -> ScreenShot:
cropped.extend(data[start:end])
data = cropped
finally:
if prov:
core.CGDataProviderRelease(prov)
Comment thread
BoboTiG marked this conversation as resolved.
if copy_data:
core.CFRelease(copy_data)
core.CFRelease(image_ref)

return self.cls_image(data, monitor, size=Size(width, height))

Expand Down