diff --git a/app/app.py b/app/app.py index bc7eb6f..a34546d 100644 --- a/app/app.py +++ b/app/app.py @@ -73,7 +73,6 @@ class ICRAApp( self.bring_to_front() def _setup_window(self) -> None: - self.root.overrideredirect(True) screen_width = self.root.winfo_screenwidth() screen_height = self.root.winfo_screenheight() default_width = int(screen_width * 0.8) @@ -84,15 +83,7 @@ class ICRAApp( self._is_maximized = True self.root.geometry(f"{screen_width}x{screen_height}+0+0") self.root.configure(bg="#f2f2f7") - self.root.bind("", self._restore_borderless) - self.root.after(0, self._ensure_taskbar_entry) - - def _restore_borderless(self, _event=None) -> None: - try: - self.root.overrideredirect(True) - self._ensure_taskbar_entry() - except Exception: - pass + self._init_window_chrome() def _ensure_taskbar_entry(self) -> None: """Force the borderless window to show up in the Windows taskbar.""" @@ -105,6 +96,7 @@ class ICRAApp( import ctypes hwnd = self.root.winfo_id() if not hwnd: + self.root.after(50, self._ensure_taskbar_entry) return GWL_EXSTYLE = -20 @@ -137,6 +129,63 @@ class ICRAApp( except Exception: pass + def _init_window_chrome(self) -> None: + """Configure a borderless window while retaining a taskbar entry.""" + try: + import platform + + system = platform.system() + if system == "Windows": + self.root.after(0, self._apply_windows_borderless_style) + self.root.after(0, self._ensure_taskbar_entry) + else: + self.root.overrideredirect(True) + except Exception: + self.root.overrideredirect(True) + + def _apply_windows_borderless_style(self) -> None: + try: + import platform + import ctypes + + if platform.system() != "Windows": + return + + hwnd = self.root.winfo_id() + if not hwnd: + self.root.after(50, self._apply_windows_borderless_style) + return + + user32 = ctypes.windll.user32 # type: ignore[attr-defined] + GWL_STYLE = -16 + WS_CAPTION = 0x00C00000 + WS_THICKFRAME = 0x00040000 + WS_MAXIMIZEBOX = 0x00010000 + WS_MINIMIZEBOX = 0x00020000 + WS_SYSMENU = 0x00080000 + SWP_NOSIZE = 0x0001 + SWP_NOMOVE = 0x0002 + SWP_NOZORDER = 0x0004 + SWP_FRAMECHANGED = 0x0020 + + style = user32.GetWindowLongW(hwnd, GWL_STYLE) + new_style = style & ~( + WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU + ) + if new_style != style: + user32.SetWindowLongW(hwnd, GWL_STYLE, new_style) + user32.SetWindowPos( + hwnd, + 0, + 0, + 0, + 0, + 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED, + ) + except Exception: + pass + def start_app() -> None: """Entry point used by the CLI script."""