v1.9.15: fix minimize/restore — remove grab_set, add Win32 restore fallback

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
chrome-storm-c442
2026-03-05 03:58:32 -05:00
parent f9a81a4825
commit 01ab318e4b
7 changed files with 79 additions and 44 deletions

View File

@@ -15,10 +15,12 @@ class AboutDialog(ctk.CTkToplevel):
self.geometry("500x480")
self.resizable(False, False)
self.transient(master)
self.grab_set()
self.focus_force()
self.protocol("WM_DELETE_WINDOW", self._on_close)
self._master_ref = master
self._map_bind_id = master.bind("<Map>", self._on_parent_map, add="+")
# ── Header ──
ctk.CTkLabel(
self, text=t("about_title"),
@@ -78,9 +80,20 @@ class AboutDialog(ctk.CTkToplevel):
self, text=t("close"), width=120, command=self._on_close
).pack(pady=(10, 20))
def _on_parent_map(self, event=None):
"""Restore dialog when parent is un-minimized."""
try:
if not self.winfo_exists():
return
self.deiconify()
self.lift()
self.focus_force()
except Exception:
pass
def _on_close(self):
try:
self.grab_release()
self._master_ref.unbind("<Map>", self._map_bind_id)
except Exception:
pass
self.destroy()

View File

@@ -3,6 +3,7 @@ Main application window — sidebar + tabview layout.
"""
import tkinter
import sys
import customtkinter as ctk
from tkinter import messagebox
@@ -118,6 +119,37 @@ class App(ctk.CTk):
# Cleanup on close
self.protocol("WM_DELETE_WINDOW", self._on_close)
# Fix: restore window after Win+D (Show Desktop)
self.bind("<Map>", self._on_map, add="+")
if sys.platform == "win32":
self._setup_win32_restore()
def _on_map(self, event=None):
"""Ensure window is fully visible when restored from taskbar."""
try:
self.deiconify()
self.lift()
except Exception:
pass
def _setup_win32_restore(self):
"""Win32 fallback: periodic check for stuck minimized state."""
import ctypes
self._user32 = ctypes.windll.user32
self._hwnd = int(self.wm_frame(), 16)
self._check_minimized()
def _check_minimized(self):
"""If window is iconic but should be visible, force restore."""
try:
if self._user32.IsIconic(self._hwnd):
fg = self._user32.GetForegroundWindow()
if fg == self._hwnd:
self._user32.ShowWindow(self._hwnd, 9) # SW_RESTORE
except Exception:
pass
self.after(500, self._check_minimized)
def _build_layout(self):
# PanedWindow — resizable sidebar | main area
self._paned = tkinter.PanedWindow(

View File

@@ -32,13 +32,11 @@ class GroupDialog(ctk.CTkToplevel):
self.geometry("340x200")
self.resizable(False, False)
self.transient(master)
self.grab_set()
self.focus_force()
self.protocol("WM_DELETE_WINDOW", self._on_close)
# Fix: restore dialog when parent is un-minimized
self._master_ref = master
master.bind("<Map>", self._on_parent_map, add="+")
self.bind("<Unmap>", self._on_unmap, add="+")
self._map_bind_id = master.bind("<Map>", self._on_parent_map, add="+")
# ── Name ──
ctk.CTkLabel(self, text=t("group_name"), anchor="w").pack(
@@ -103,23 +101,12 @@ class GroupDialog(ctk.CTkToplevel):
self.deiconify()
self.lift()
self.focus_force()
self.grab_set()
except Exception:
pass
def _on_unmap(self, event=None):
try:
self.grab_release()
except Exception:
pass
def _on_close(self):
try:
self._master_ref.unbind("<Map>")
except Exception:
pass
try:
self.grab_release()
self._master_ref.unbind("<Map>", self._map_bind_id)
except Exception:
pass
self.destroy()

View File

@@ -54,18 +54,13 @@ class ServerDialog(ctk.CTkToplevel):
self.geometry("450x720")
self.resizable(False, False)
# transient BEFORE grab_set — prevents focus lock on minimize
self.transient(master)
self.grab_set()
self.focus_force()
# Release grab on close (prevents stuck app)
self.protocol("WM_DELETE_WINDOW", self._on_close)
# Fix: restore dialog when parent is un-minimized
# Restore dialog when parent is un-minimized
self._master_ref = master
master.bind("<Map>", self._on_parent_map, add="+")
self.bind("<Unmap>", self._on_unmap, add="+")
self._map_bind_id = master.bind("<Map>", self._on_parent_map, add="+")
self._field_frames: dict[str, ctk.CTkFrame] = {}
self._build_ui(server)
@@ -491,32 +486,19 @@ class ServerDialog(ctk.CTkToplevel):
self._show_error(str(e))
def _on_parent_map(self, event=None):
"""Force-restore dialog when parent window is un-minimized."""
"""Restore dialog when parent window is un-minimized."""
try:
if not self.winfo_exists():
return
self.deiconify()
self.lift()
self.focus_force()
self.grab_set()
except Exception:
pass
def _on_unmap(self, event=None):
"""Release grab when dialog is minimized to prevent input lock."""
try:
self.grab_release()
except Exception:
pass
def _on_close(self):
"""Release grab and destroy — prevents stuck app on minimize."""
try:
self._master_ref.unbind("<Map>")
except Exception:
pass
try:
self.grab_release()
self._master_ref.unbind("<Map>", self._map_bind_id)
except Exception:
pass
self.destroy()

View File

@@ -83,7 +83,11 @@ class UpdateDialog(ctk.CTkToplevel):
self.geometry("500x420")
self.resizable(False, False)
self.transient(parent)
self.grab_set()
self.focus_force()
self.protocol("WM_DELETE_WINDOW", self._on_close)
self._master_ref = parent
self._map_bind_id = parent.bind("<Map>", self._on_parent_map, add="+")
self._info = info
self._downloaded_path = downloaded_path
@@ -99,6 +103,23 @@ class UpdateDialog(ctk.CTkToplevel):
py = parent.winfo_y() + (parent.winfo_height() - 420) // 2
self.geometry(f"+{px}+{py}")
def _on_parent_map(self, event=None):
try:
if not self.winfo_exists():
return
self.deiconify()
self.lift()
self.focus_force()
except Exception:
pass
def _on_close(self):
try:
self._master_ref.unbind("<Map>", self._map_bind_id)
except Exception:
pass
self.destroy()
def _build_ui(self):
from version import __version__
@@ -194,7 +215,7 @@ class UpdateDialog(ctk.CTkToplevel):
width=80, height=34, corner_radius=8,
fg_color="#4b5563", hover_color="#374151",
font=ctk.CTkFont(size=13),
command=self.destroy,
command=self._on_close,
).pack(side="right", padx=(8, 0))
ctk.CTkButton(
@@ -268,4 +289,4 @@ class UpdateDialog(ctk.CTkToplevel):
def _on_skip_click(self):
if self._on_skip:
self._on_skip(self._info["version"])
self.destroy()
self._on_close()

View File

@@ -1,6 +1,6 @@
"""Version info for ServerManager."""
__version__ = "1.9.14"
__version__ = "1.9.15"
__app_name__ = "ServerManager"
__author__ = "aibot777"
__description__ = "Desktop GUI for managing remote servers"