diff --git a/ui/hud_overlay.py b/ui/hud_overlay.py index bd373ec..0be2a07 100644 --- a/ui/hud_overlay.py +++ b/ui/hud_overlay.py @@ -146,10 +146,11 @@ class HUDOverlay(QWidget): self._drag_offset = QPoint() self._modifier_pressed = False - # Game window detection - self._auto_hide_with_game = True # Auto-hide when game not focused + # Game window detection (disabled by default - enable after testing) + self._auto_hide_with_game = False # Auto-hide when game not focused self._game_window_title = "Entropia Universe" # Window title to track self._was_visible_before_unfocus = False + self._debug_window_detection = False # Set to True to debug # Timer for session time updates self._timer = QTimer(self) @@ -660,24 +661,56 @@ class HUDOverlay(QWidget): GetWindowTextW(hwnd, buffer, length + 1) title = buffer.value - # Check if game is in foreground - is_game_focused = self._game_window_title in title + if self._debug_window_detection: + print(f"[HUD DEBUG] Foreground window: '{title}'") + + # Check if game is in foreground (case insensitive) + is_game_focused = self._game_window_title.lower() in title.lower() if is_game_focused: - # Game is focused - show HUD if it was hidden - if self._was_visible_before_unfocus and not self.isVisible(): + # Game is focused - show HUD if needed + if not self.isVisible(): self.show() + if self._debug_window_detection: + print(f"[HUD DEBUG] Game focused - showing HUD") else: # Game not focused - hide HUD if visible if self.isVisible(): - self._was_visible_before_unfocus = True self.hide() - else: - self._was_visible_before_unfocus = False - except Exception: - # Silently ignore errors (e.g., Windows API issues) + if self._debug_window_detection: + print(f"[HUD DEBUG] Game unfocused - hiding HUD") + except Exception as e: + if self._debug_window_detection: + print(f"[HUD DEBUG] Error: {e}") pass + def get_foreground_window_title(self) -> Optional[str]: + """ + Get the title of the current foreground window. + Useful for debugging window detection. + + Returns: + Window title string or None if unavailable + """ + if sys.platform != 'win32': + return None + + try: + hwnd = GetForegroundWindow() + if hwnd: + length = GetWindowTextLengthW(hwnd) + if length > 0: + buffer = ctypes.create_unicode_buffer(length + 1) + GetWindowTextW(hwnd, buffer, length + 1) + return buffer.value + except Exception: + pass + return None + + def set_debug_window_detection(self, enabled: bool) -> None: + """Enable/disable debug output for window detection.""" + self._debug_window_detection = enabled + def set_auto_hide_with_game(self, enabled: bool) -> None: """ Enable/disable auto-hide when game not focused.