feat(焦点管理): 添加微缩模式时自动归还焦点功能

新增 return_focus_to_previous_window 方法,在切换到微缩模式时自动清除当前窗口焦点并将其置于其他窗口下方,同时尝试激活上一个窗口。更新README文档说明新增功能特性。
This commit is contained in:
2026-01-22 14:17:09 +08:00
parent 74b1de9b3a
commit dbaff55d3a
2 changed files with 208 additions and 0 deletions

View File

@@ -264,6 +264,9 @@ class TimerApp(QWidget):
x = screen_geometry.width() - self.width() - self.config['right_margin']
y = self.config['top_margin']
self.move(x, y)
# 将焦点还给上一个进程
self.return_focus_to_previous_window()
def center_on_screen(self):
screen = QApplication.primaryScreen()
@@ -382,6 +385,24 @@ class TimerApp(QWidget):
self.anim_group.addAnimation(self.flash_anim)
self.anim_group.start()
def return_focus_to_previous_window(self):
# 清除当前窗口的焦点
self.clearFocus()
# 将窗口置于其他窗口下方
self.lower()
# 尝试激活其他窗口
app = QApplication.instance()
windows = app.topLevelWindows()
# 找到不是当前窗口的其他窗口
for window in windows:
if window != self.windowHandle() and window.isVisible():
# 尝试激活其他窗口
window.requestActivate()
break
def open_config(self):
dialog = ConfigDialog(self, self.config)
if dialog.exec() == QDialog.Accepted: