mimo
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Take a screenshot of the HCIE iced app window using XDG portal or xdotool+import."""
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
def try_portal_screenshot():
|
||||
"""Try org.freedesktop.portal.Screenshot via dbus."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
['gdbus', 'call', '--session', '--dest', 'org.freedesktop.portal.Desktop',
|
||||
'--object-path', '/org/freedesktop/portal/desktop',
|
||||
'--method', 'org.freedesktop.portal.Screenshot.Screenshot',
|
||||
'', '{}'],
|
||||
capture_output=True, text=True, timeout=5
|
||||
)
|
||||
if result.returncode == 0:
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
def try_import_screenshot(output):
|
||||
"""Try ImageMagick import."""
|
||||
try:
|
||||
subprocess.run(['import', '-window', 'root', output], timeout=10)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def try_xdg_screenshot(output):
|
||||
"""Try gnome-screenshot or xfce4-screenshooter."""
|
||||
for cmd in [['gnome-screenshot', '-f', output],
|
||||
['xfce4-screenshooter', '-f', '-s', output]]:
|
||||
try:
|
||||
subprocess.run(cmd, timeout=10)
|
||||
import os
|
||||
if os.path.exists(output) and os.path.getsize(output) > 0:
|
||||
return True
|
||||
except Exception:
|
||||
continue
|
||||
return False
|
||||
|
||||
def try_xdotool_import(output):
|
||||
"""Use xdotool to find window and import."""
|
||||
try:
|
||||
result = subprocess.run(['xdotool', 'search', '--name', 'HCIE'],
|
||||
capture_output=True, text=True, timeout=5)
|
||||
wid = result.stdout.strip().split('\n')[0]
|
||||
if wid:
|
||||
subprocess.run(['import', '-window', wid, output], timeout=10)
|
||||
import os
|
||||
if os.path.exists(output) and os.path.getsize(output) > 0:
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
def try_grim_screenshot(output):
|
||||
"""Try grim for Wayland."""
|
||||
try:
|
||||
subprocess.run(['grim', output], timeout=10)
|
||||
import os
|
||||
if os.path.exists(output) and os.path.getsize(output) > 0:
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
def try_spectacle_screenshot(output):
|
||||
"""Try spectacle for KDE Wayland."""
|
||||
try:
|
||||
subprocess.run(['spectacle', '--nonotify', '-f', output], timeout=10)
|
||||
import os
|
||||
if os.path.exists(output) and os.path.getsize(output) > 0:
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
if __name__ == '__main__':
|
||||
output = sys.argv[1] if len(sys.argv) > 1 else '/tmp/hcie_screenshot.png'
|
||||
|
||||
methods = [
|
||||
("grim (Wayland)", try_grim_screenshot),
|
||||
("spectacle (KDE)", try_spectacle_screenshot),
|
||||
("import (ImageMagick)", try_import_screenshot),
|
||||
("xdotool+import", try_xdotool_import),
|
||||
("gnome-screenshot/xfce4", try_xdg_screenshot),
|
||||
]
|
||||
|
||||
for name, method in methods:
|
||||
print(f"Trying {name}...")
|
||||
if method(output):
|
||||
import os
|
||||
if os.path.exists(output) and os.path.getsize(output) > 0:
|
||||
print(f"SUCCESS: Screenshot saved to {output}")
|
||||
sys.exit(0)
|
||||
|
||||
print("FAILED: No screenshot method worked")
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user