跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

WindowLayout.cs

35 行 · 1.4 KB历史下载
1using System.Drawing;
2
3namespace Cage.Windows;
4
5internal sealed record WindowPlacement(int X, int Y, int Width, int Height, int Dpi, bool Maximized);
6
7internal static class WindowLayout
8{
9 public static Size Minimum(Rectangle work, int dpi) => new(
10 Math.Min(work.Width, (int)Math.Round(820 * dpi / 96.0)),
11 Math.Min(work.Height, (int)Math.Round(580 * dpi / 96.0)));
12
13 public static Rectangle Bounds(Rectangle work, int dpi, WindowPlacement? saved)
14 {
15 var minimum = Minimum(work, dpi);
16 int width, height, x, y;
17 if (saved is { Width: > 0, Height: > 0, Dpi: > 0 })
18 {
19 width = (int)Math.Round(saved.Width * dpi / (double)saved.Dpi);
20 height = (int)Math.Round(saved.Height * dpi / (double)saved.Dpi);
21 x = saved.X; y = saved.Y;
22 }
23 else
24 {
25 var scale = Math.Min(work.Width * .85 / 1280, work.Height * .85 / 850);
26 width = (int)Math.Round(1280 * scale); height = (int)Math.Round(850 * scale);
27 x = work.Left + (work.Width - width) / 2;
28 y = work.Top + (work.Height - height) / 2;
29 }
30 width = Math.Clamp(width, minimum.Width, work.Width);
31 height = Math.Clamp(height, minimum.Height, work.Height);
32 return new Rectangle(Math.Clamp(x, work.Left, work.Right - width),
33 Math.Clamp(y, work.Top, work.Bottom - height), width, height);
34 }
35}