Reduce macOS idle resource usage

This commit is contained in:
AuroraWright
2023-12-13 16:37:17 +01:00
parent 25d101f806
commit a12ddfd222

View File

@@ -153,6 +153,14 @@ def run(read_from='clipboard',
on_press=on_key_press, on_press=on_key_press,
on_release=on_key_release) on_release=on_key_release)
tmp_paused_listener.start() tmp_paused_listener.start()
if sys.platform == "darwin" and 'objc' in sys.modules:
from AppKit import NSPasteboard, NSPasteboardTypePNG, NSPasteboardTypeTIFF
pasteboard = NSPasteboard.generalPasteboard()
count = pasteboard.changeCount()
mac_clipboard_polling = True
else:
mac_clipboard_polling = False
else: else:
read_from = Path(read_from) read_from = Path(read_from)
if not read_from.is_dir(): if not read_from.is_dir():
@@ -225,6 +233,16 @@ def run(read_from='clipboard',
if read_from == 'clipboard': if read_from == 'clipboard':
if not paused and not tmp_paused: if not paused and not tmp_paused:
if mac_clipboard_polling:
changed = False
old_count = count
count = pasteboard.changeCount()
if not just_unpaused and count != old_count and any(x in pasteboard.types() for x in [NSPasteboardTypePNG, NSPasteboardTypeTIFF]):
changed = True
else:
changed = True
if changed:
old_img = img old_img = img
try: try: