1
1
import logging
2
+ from math import ceil
2
3
from settings import APP_BAR_TITLE
3
4
from PyQt6 .QtWidgets import QWidget ,QHBoxLayout ,QGridLayout ,QFrame
4
5
from PyQt6 .QtGui import QScreen
@@ -212,20 +213,17 @@ def showEvent(self, event):
212
213
213
214
214
215
def is_foreground_fullscreen (self ):
215
- # Get the active window's handle using win32gui
216
+ """Check if the activeforeground window is in fullscreen mode."""
216
217
hwnd = win32gui .GetForegroundWindow ()
217
218
if not hwnd :
218
219
return
219
- hwnd_class_name = win32gui .GetClassName (hwnd )
220
-
221
- # Check if the foreground window is the desktop
222
- if hwnd_class_name in ["Progman" ,"WorkerW" ]:
220
+
221
+ class_name = win32gui .GetClassName (hwnd )
222
+ if class_name in ("Progman" ,"WorkerW" ,"XamlWindow" ):
223
223
return
224
- # Get the window rectangle: (left, top, right, bottom) then convert to (x, y, width, height)
225
- rect = win32gui .GetWindowRect (hwnd )
226
- window_rect = (rect [0 ],rect [1 ],rect [2 ]- rect [0 ],rect [3 ]- rect [1 ])
227
-
228
- # Get the primary screen geometry
224
+ left ,top ,right ,bottom = win32gui .GetWindowRect (hwnd )
225
+ window_rect = (left ,top ,right - left ,bottom - top )
226
+
229
227
screen_geometry = self .screen ().geometry ()
230
228
screen_rect = (
231
229
screen_geometry .x (),
@@ -234,19 +232,17 @@ def is_foreground_fullscreen(self):
234
232
screen_geometry .height ()
235
233
)
236
234
237
- # Determine fullscreen state
238
- is_fullscreen = ( window_rect == screen_rect )
239
- # Cache the previous state so we only update if it changes
240
- if hasattr (self ,"_prev_fullscreen_state" ) and self . _prev_fullscreen_state == is_fullscreen :
235
+ self . dpi = self . screen (). devicePixelRatio ()
236
+ scaled_screen_rect = screen_rect [: 2 ] + tuple ( round ( dim * self . dpi ) for dim in screen_rect [ 2 :] )
237
+ is_fullscreen = ( window_rect == scaled_screen_rect )
238
+ if getattr (self ,"_prev_fullscreen_state" , None ) == is_fullscreen :
241
239
return
240
+
242
241
self ._prev_fullscreen_state = is_fullscreen
243
- # Update visibility only when necessary
244
- if is_fullscreen :
245
- if self .isVisible ():
246
- self .hide ()
247
- else :
248
- if not self .isVisible ():
249
- self .show ()
242
+ if is_fullscreen and self .isVisible ():
243
+ self .hide ()
244
+ elif not is_fullscreen and not self .isVisible ():
245
+ self .show ()
250
246
251
247
252
248
def detect_os_theme (self )-> bool :