diff --git a/claude_vision_auto/screenshot.py b/claude_vision_auto/screenshot.py index 0d61f87..805a54a 100644 --- a/claude_vision_auto/screenshot.py +++ b/claude_vision_auto/screenshot.py @@ -26,11 +26,14 @@ def find_screenshot_tool() -> Optional[str]: def take_screenshot() -> Optional[str]: """ - Take screenshot of active terminal window + Take screenshot of full screen Returns: Path to screenshot file, or None if capture failed """ + import os + import time + tool = find_screenshot_tool() if not tool: @@ -40,41 +43,49 @@ def take_screenshot() -> Optional[str]: # Create temporary file cache_dir = config.get_cache_dir() - screenshot_path = cache_dir / f"screenshot_{int(subprocess.check_output(['date', '+%s']).decode().strip())}.png" + screenshot_path = cache_dir / f"screenshot_{int(time.time())}.png" + + # Preserve DISPLAY environment variable + env = os.environ.copy() + if 'DISPLAY' not in env: + env['DISPLAY'] = ':0' # Default X display try: if tool == "scrot": - # Capture active window - subprocess.run( - ["scrot", "-u", str(screenshot_path)], + # Capture full screen (more reliable than -u for active window) + result = subprocess.run( + ["scrot", str(screenshot_path)], check=True, capture_output=True, - timeout=config.SCREENSHOT_TIMEOUT + timeout=config.SCREENSHOT_TIMEOUT, + env=env ) elif tool == "gnome-screenshot": - # Capture active window - subprocess.run( - ["gnome-screenshot", "-w", "-f", str(screenshot_path)], + # Capture full screen + result = subprocess.run( + ["gnome-screenshot", "-f", str(screenshot_path)], check=True, capture_output=True, - timeout=config.SCREENSHOT_TIMEOUT + timeout=config.SCREENSHOT_TIMEOUT, + env=env ) elif tool == "import": # ImageMagick - capture root window - subprocess.run( + result = subprocess.run( ["import", "-window", "root", str(screenshot_path)], check=True, capture_output=True, - timeout=config.SCREENSHOT_TIMEOUT + timeout=config.SCREENSHOT_TIMEOUT, + env=env ) elif tool == "maim": - # Capture active window - subprocess.run( - ["maim", "-i", "$(xdotool getactivewindow)", str(screenshot_path)], - shell=True, + # Capture full screen + result = subprocess.run( + ["maim", str(screenshot_path)], check=True, capture_output=True, - timeout=config.SCREENSHOT_TIMEOUT + timeout=config.SCREENSHOT_TIMEOUT, + env=env ) else: return None @@ -86,17 +97,19 @@ def take_screenshot() -> Optional[str]: else: return None - except subprocess.TimeoutExpired: + except subprocess.TimeoutExpired as e: if config.DEBUG: print(f"[DEBUG] Screenshot timeout with tool: {tool}") return None except subprocess.CalledProcessError as e: if config.DEBUG: - print(f"[DEBUG] Screenshot failed: {e}") + print(f"[DEBUG] Screenshot failed with {tool}: {e}") + if e.stderr: + print(f"[DEBUG] Error output: {e.stderr.decode('utf-8', errors='ignore')}") return None except Exception as e: if config.DEBUG: - print(f"[DEBUG] Unexpected error: {e}") + print(f"[DEBUG] Unexpected screenshot error: {type(e).__name__}: {e}") return None