-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlegacy_window_hacks.py
More file actions
80 lines (63 loc) · 3.33 KB
/
legacy_window_hacks.py
File metadata and controls
80 lines (63 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import ctypes
from PyQt6.QtCore import QTimer
from PyQt6.QtWidgets import QWidget
# This file contains "aggressive" window management logic that was used
# to force the window to stay on top of games. It caused instability
# (window disappearing) and was removed from main.py on 2026-02-19.
class LegacyWindowHacks:
"""
Code snippets removed from VideoWindow class.
NOT FOR DIRECT EXECUTION. Reference only.
"""
def _enforce_window_styles(self):
"""Единый метод для принудительной установки стилей (Иконка + Поверх всех) - Aggressive Version"""
try:
hwnd = int(self.winId())
# Константы Win32
GWL_EXSTYLE = -20
WS_EX_APPWINDOW = 0x00040000
WS_EX_TOOLWINDOW = 0x00000080
WS_EX_TOPMOST = 0x00000008
# 1. Читаем стили
style = ctypes.windll.user32.GetWindowLongW(hwnd, GWL_EXSTYLE)
# 2. Модифицируем биты
# Убираем ToolWindow (вернет иконку)
if style & WS_EX_TOOLWINDOW:
style = style & ~WS_EX_TOOLWINDOW
# Добавляем AppWindow (иконка) и TopMost (поверх всех)
style = style | WS_EX_APPWINDOW | WS_EX_TOPMOST
# 3. Применяем стили (только если изменились, чтобы не мерцало)
# Но для надежности можно и всегда
ctypes.windll.user32.SetWindowLongW(hwnd, GWL_EXSTYLE, style)
# 4. Дополнительно пинаем Z-Order через SetWindowPos
HWND_TOPMOST = -1
SWP_NOMOVE = 0x0002
SWP_NOSIZE = 0x0001
SWP_NOACTIVATE = 0x0010
ctypes.windll.user32.SetWindowPos(
hwnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE
)
except Exception as e:
# print(f"Style error: {e}") # Спам в консоль не нужен
pass
def focusOutEvent(self, event):
"""Если потеряли фокус - немедленно восстанавливаем стили (с повторами)"""
super().focusOutEvent(event)
# Сразу
self._enforce_window_styles()
# Через 100мс (когда игра уже перехватила фокус)
QTimer.singleShot(100, self._enforce_window_styles)
# Через 500мс (контрольный)
QTimer.singleShot(500, self._enforce_window_styles)
def showEvent(self, event):
super().showEvent(event)
# 1. Принудительно ставим все необходимые стили (Icon + TopMost)
self._enforce_window_styles()
# 2. Win32: NOACTIVATE
self._apply_win32_noactivate()
# 3. Запускаем таймер постоянного контроля (200мс)
if not hasattr(self, 'topmost_timer'):
self.topmost_timer = QTimer(self)
self.topmost_timer.timeout.connect(self._reassert_topmost)
self.topmost_timer.start(200)