Keep custom title bar while preserving responsiveness
This commit is contained in:
parent
f65c37407c
commit
8053dc297a
49
app/app.py
49
app/app.py
|
|
@ -85,16 +85,17 @@ class ICRAApp(
|
|||
default_y = (screen_height - default_height) // 4
|
||||
self._window_geometry = f"{default_width}x{default_height}+{default_x}+{default_y}"
|
||||
self._is_maximized = True
|
||||
self._use_overrideredirect = True
|
||||
self._use_overrideredirect = platform.system() != "Windows"
|
||||
self.root.geometry(f"{screen_width}x{screen_height}+0+0")
|
||||
self.root.configure(bg="#f2f2f7")
|
||||
try:
|
||||
self.root.overrideredirect(True)
|
||||
except Exception:
|
||||
if self._use_overrideredirect:
|
||||
try:
|
||||
self.root.attributes("-type", "splash")
|
||||
self.root.overrideredirect(True)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
self.root.attributes("-type", "splash")
|
||||
except Exception:
|
||||
pass
|
||||
self._window_icon_ref = None
|
||||
self._apply_window_icon()
|
||||
self._init_window_chrome()
|
||||
|
|
@ -110,27 +111,16 @@ class ICRAApp(
|
|||
return
|
||||
|
||||
GWL_EXSTYLE = -20
|
||||
GWL_HWNDPARENT = -8
|
||||
WS_EX_TOOLWINDOW = 0x00000080
|
||||
WS_EX_APPWINDOW = 0x00040000
|
||||
SWP_NOSIZE = 0x0001
|
||||
SWP_NOMOVE = 0x0002
|
||||
SWP_NOZORDER = 0x0004
|
||||
SWP_FRAMECHANGED = 0x0020
|
||||
SWP_NOOWNERZORDER = 0x0200
|
||||
SWP_SHOWWINDOW = 0x0040
|
||||
|
||||
user32 = ctypes.windll.user32 # type: ignore[attr-defined]
|
||||
shell32 = ctypes.windll.shell32 # type: ignore[attr-defined]
|
||||
|
||||
set_long = getattr(user32, "SetWindowLongPtrW", user32.SetWindowLongW)
|
||||
get_long = getattr(user32, "GetWindowLongPtrW", user32.GetWindowLongW)
|
||||
ptr_type = ctypes.c_longlong if ctypes.sizeof(ctypes.c_void_p) == 8 else ctypes.c_long
|
||||
get_long.restype = ptr_type # type: ignore[attr-defined]
|
||||
get_long.argtypes = [wintypes.HWND, ctypes.c_int] # type: ignore[attr-defined]
|
||||
set_long.restype = ptr_type # type: ignore[attr-defined]
|
||||
set_long.argtypes = [wintypes.HWND, ctypes.c_int, ptr_type] # type: ignore[attr-defined]
|
||||
|
||||
style = user32.GetWindowLongW(hwnd, GWL_EXSTYLE)
|
||||
new_style = (style & ~WS_EX_TOOLWINDOW) | WS_EX_APPWINDOW
|
||||
if new_style != style:
|
||||
|
|
@ -142,20 +132,9 @@ class ICRAApp(
|
|||
0,
|
||||
0,
|
||||
0,
|
||||
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_SHOWWINDOW,
|
||||
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED,
|
||||
)
|
||||
|
||||
set_long(hwnd, GWL_HWNDPARENT, ptr_type(0))
|
||||
user32.SetWindowPos(
|
||||
hwnd,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_SHOWWINDOW,
|
||||
)
|
||||
|
||||
app_id = ctypes.c_wchar_p("ICRA.App")
|
||||
shell32.SetCurrentProcessExplicitAppUserModelID(app_id)
|
||||
except Exception:
|
||||
|
|
@ -174,9 +153,15 @@ class ICRAApp(
|
|||
def _init_window_chrome(self) -> None:
|
||||
"""Configure a borderless window while retaining a taskbar entry."""
|
||||
try:
|
||||
self.root.bind("<Map>", self._restore_borderless)
|
||||
self.root.after(0, self._restore_borderless)
|
||||
self.root.after(0, self._ensure_taskbar_entry)
|
||||
if platform.system() == "Windows":
|
||||
self.root.after(0, self._apply_windows_borderless_style)
|
||||
self.root.after(0, self._ensure_taskbar_entry)
|
||||
self.root.bind("<Map>", lambda _e: self._apply_windows_borderless_style(), add="+")
|
||||
self.root.bind("<Map>", lambda _e: self._ensure_taskbar_entry(), add="+")
|
||||
else:
|
||||
self.root.bind("<Map>", self._restore_borderless)
|
||||
self.root.after(0, self._restore_borderless)
|
||||
self.root.after(0, self._ensure_taskbar_entry)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue