优化更新
This commit is contained in:
@@ -87,21 +87,19 @@ class GlobalHotkey(QAbstractNativeEventFilter):
|
||||
super().__init__()
|
||||
self._panel = panel
|
||||
self._ball = ball
|
||||
self._hwnd = None
|
||||
|
||||
def install(self):
|
||||
if sys.platform != "win32":
|
||||
return
|
||||
# 用一个隐藏窗口的 HWND 来接收 WM_HOTKEY
|
||||
self._hwnd = int(self._panel.winId())
|
||||
# 注册线程级别的全局热键,避免因主窗口 hide/show 导致 HWND 重建/失效
|
||||
ctypes.windll.user32.RegisterHotKey(
|
||||
self._hwnd, self._HOTKEY_ID, self._MOD_ALT, self._VK_BACKTICK
|
||||
None, self._HOTKEY_ID, self._MOD_ALT, self._VK_BACKTICK
|
||||
)
|
||||
QApplication.instance().installNativeEventFilter(self)
|
||||
|
||||
def uninstall(self):
|
||||
if self._hwnd:
|
||||
ctypes.windll.user32.UnregisterHotKey(self._hwnd, self._HOTKEY_ID)
|
||||
if sys.platform == "win32":
|
||||
ctypes.windll.user32.UnregisterHotKey(None, self._HOTKEY_ID)
|
||||
QApplication.instance().removeNativeEventFilter(self)
|
||||
|
||||
def nativeEventFilter(self, event_type, message):
|
||||
@@ -114,7 +112,7 @@ class GlobalHotkey(QAbstractNativeEventFilter):
|
||||
return False, 0
|
||||
|
||||
def _toggle(self):
|
||||
if self._panel.isVisible():
|
||||
if self._panel.is_really_visible():
|
||||
self._panel.minimize_to_ball()
|
||||
else:
|
||||
self._panel.show_near(self._ball.pos(), BALL_SIZE)
|
||||
|
||||
Reference in New Issue
Block a user