Skip to content

Commit

Permalink
web: correct the behavior of the maximize button on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulMelody committed Sep 28, 2024
1 parent d3d4649 commit f7de77a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions libresvip/web/pages.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import argparse
import asyncio
import ctypes
import dataclasses
import enum
import functools
import io
import math
import pathlib
import platform
import re
import secrets
import shutil
Expand Down Expand Up @@ -1625,6 +1627,52 @@ def switch_language(event: ValueChangeEventArguments) -> None:
options_tab = ui.tab(_("Advanced Settings"))
ui.space()
if app.native.main_window is not None:
if platform.system() == "Windows":
import clr

clr.AddReference("System")
clr.AddReference("System.Windows.Forms")

from System import IntPtr
from System.Windows.Forms import Screen

user32 = ctypes.windll.user32
rect_tuple = (0, 0, 1200, 800)
_maximized = False

def _maximize() -> None:
nonlocal _maximized, rect_tuple
if not _maximized:
hwnd = user32.GetForegroundWindow()
screen = Screen.FromHandle(IntPtr(hwnd))
rect = ctypes.wintypes.RECT()
user32.GetWindowRect(hwnd, ctypes.pointer(rect))
rect_tuple = (
rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
)
user32.MoveWindow(
hwnd,
screen.Bounds.X,
screen.Bounds.Y,
screen.WorkingArea.Width,
screen.WorkingArea.Height,
True,
)
_maximized = True

app.native.main_window.maximize = _maximize

def _restore() -> None:
nonlocal _maximized
if _maximized:
_maximized = False
hwnd = user32.GetForegroundWindow()
user32.MoveWindow(hwnd, *rect_tuple, True)

app.native.main_window.restore = _restore
maximized = False
maximize_text = _("Maximize")
restore_text = _("Restore")
Expand Down

0 comments on commit f7de77a

Please sign in to comment.