From 696de614ac91deabc643423d3439ce7674f7c083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Sat, 30 Nov 2024 04:03:13 +0800 Subject: [PATCH] . --- cpp/version.cmake | 2 +- cpp/winsharedutils/hwnd.cpp | 16 ++++++++++++++++ py/LunaTranslator/gui/translatorUI.py | 3 +++ py/LunaTranslator/winsharedutils.py | 4 ++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cpp/version.cmake b/cpp/version.cmake index a1b01021..92db64ea 100644 --- a/cpp/version.cmake +++ b/cpp/version.cmake @@ -1,7 +1,7 @@ set(VERSION_MAJOR 6) set(VERSION_MINOR 8) -set(VERSION_PATCH 2) +set(VERSION_PATCH 3) set(VERSION_REVISION 0) set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp) diff --git a/cpp/winsharedutils/hwnd.cpp b/cpp/winsharedutils/hwnd.cpp index c308d8d2..6db6eecc 100644 --- a/cpp/winsharedutils/hwnd.cpp +++ b/cpp/winsharedutils/hwnd.cpp @@ -139,3 +139,19 @@ DECLARE_API UINT GetMonitorDpiScaling(HWND hwnd) return dpiX; } } + +DECLARE_API bool check_window_viewable(HWND hwnd) +{ + RECT windowRect; + if (!GetWindowRect(hwnd, &windowRect)) + return false; + HMONITOR hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); + if (!hMonitor) + return false; + MONITORINFO monitorInfo; + monitorInfo.cbSize = sizeof(MONITORINFO); + if (!GetMonitorInfo(hMonitor, &monitorInfo)) + return false; + RECT _; + return IntersectRect(&_, &windowRect, &monitorInfo.rcWork); +} \ No newline at end of file diff --git a/py/LunaTranslator/gui/translatorUI.py b/py/LunaTranslator/gui/translatorUI.py index 7c4c5ec5..0abd0b5c 100644 --- a/py/LunaTranslator/gui/translatorUI.py +++ b/py/LunaTranslator/gui/translatorUI.py @@ -297,6 +297,9 @@ class TranslatorWindow(resizableframeless): if not rect: lastpos = None continue + if not winsharedutils.check_window_viewable(hwnd): + lastpos = None + continue rate = self.devicePixelRatioF() rect = QRect( int(rect[0] / rate), diff --git a/py/LunaTranslator/winsharedutils.py b/py/LunaTranslator/winsharedutils.py index fd6322a1..2cf18531 100644 --- a/py/LunaTranslator/winsharedutils.py +++ b/py/LunaTranslator/winsharedutils.py @@ -356,3 +356,7 @@ StartCaptureAsync.argtypes = (StartCaptureAsync_cb,) StartCaptureAsync.restype = HANDLE StopCaptureAsync = utilsdll.StopCaptureAsync StopCaptureAsync.argtypes = (HANDLE,) + +check_window_viewable = utilsdll.check_window_viewable +check_window_viewable.argtypes = (HWND,) +check_window_viewable.restype = c_bool