Skip to content

Commit 7c839e0

Browse files
committed
fix: 修复任务栏单位显示、DPI问题及串流兼容性
- 修正任务栏模式下数据速度单位显示(去掉"/s"后缀) - 修复设置窗口最小化按钮和任务栏显示问题 - 移除串流兼容性相关的WS_EX_NOACTIVATE逻辑,解决右键菜单激活问题 - 修复HighDPI下界面元素重叠和裁剪问题 - 重构MetricItem单位缓存逻辑,分离面板和任务栏配置
1 parent 1a1d538 commit 7c839e0

File tree

7 files changed

+51
-53
lines changed

7 files changed

+51
-53
lines changed

src/Core/MetricItem.cs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,30 +168,41 @@ public string GetFormattedText(bool isHorizontal)
168168

169169
// [Refactor] 使用新的原子函数分别构建普通和紧凑文本
170170

171-
// 1. 标准模式 (Panel)
171+
// === 1. 更新主界面缓存 (Panel) ===
172172
string valNormal = MetricUtils.GetValueStr(Key, DisplayValue, false);
173173
string unitNormal = MetricUtils.GetUnitStr(Key, DisplayValue, MetricUtils.UnitContext.Panel);
174+
string userFmtPanel = cfg?.UnitPanel;
174175

175-
CachedValueText = valNormal;
176-
CachedUnitText = MetricUtils.GetDisplayUnit(Key, unitNormal, userFormat);
177-
_cachedNormalText = CachedValueText + CachedUnitText;
176+
string finalUnitPanel = MetricUtils.GetDisplayUnit(Key, unitNormal, userFmtPanel);
177+
_cachedNormalText = valNormal + finalUnitPanel;
178178

179-
// 2. 紧凑模式 (Taskbar/Horizontal)
180-
if (HasCustomUnit)
179+
// === 2. 更新任务栏缓存 (Taskbar/Horizontal) ===
180+
// 逻辑修正:任务栏模式下,必须使用 Taskbar 上下文 (例如不带 /s)
181+
string userFmtTaskbar = cfg?.UnitTaskbar;
182+
bool hasCustomTaskbar = !string.IsNullOrEmpty(userFmtTaskbar);
183+
184+
// 自动模式:启用数值压缩 (Compact=true) 和 紧凑单位 (Taskbar Context)
185+
// 自定义模式:不做数值压缩 (false),但单位仍需基于 Taskbar 上下文计算基础值
186+
bool compact = !hasCustomTaskbar;
187+
188+
string valTaskbar = MetricUtils.GetValueStr(Key, DisplayValue, compact);
189+
string unitTaskbar = MetricUtils.GetUnitStr(Key, DisplayValue, MetricUtils.UnitContext.Taskbar);
190+
191+
string finalUnitTaskbar = MetricUtils.GetDisplayUnit(Key, unitTaskbar, userFmtTaskbar);
192+
_cachedHorizontalText = valTaskbar + finalUnitTaskbar;
193+
194+
// 更新公共属性以便调试 (显示当前请求模式的值)
195+
if (isHorizontal)
181196
{
182-
// 自定义单位模式下,不做数值压缩,保持与 Panel 一致
183-
_cachedHorizontalText = _cachedNormalText;
197+
CachedValueText = valTaskbar;
198+
CachedUnitText = finalUnitTaskbar;
199+
HasCustomUnit = hasCustomTaskbar;
184200
}
185201
else
186202
{
187-
// 自动模式:启用数值压缩 (Compact=true) 和 紧凑单位 (Taskbar Context)
188-
string valCompact = MetricUtils.GetValueStr(Key, DisplayValue, true);
189-
string unitCompact = MetricUtils.GetUnitStr(Key, DisplayValue, MetricUtils.UnitContext.Taskbar);
190-
191-
// 确保单位正确注入 (虽然 Auto 模式下 GetDisplayUnit 通常直接返回 unitCompact)
192-
string finalUnitCompact = MetricUtils.GetDisplayUnit(Key, unitCompact, null);
193-
194-
_cachedHorizontalText = valCompact + finalUnitCompact;
203+
CachedValueText = valNormal;
204+
CachedUnitText = finalUnitPanel;
205+
HasCustomUnit = !string.IsNullOrEmpty(userFmtPanel);
195206
}
196207

197208
// Only calculate color if NOT a plugin item (already handled above)

src/Core/MetricUtils.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ public static string GetUnitStr(string key, float? value, UnitContext context)
201201
// Settings 模式下,返回 {u} 占位符,提示用户这是动态单位
202202
// 仅 SettingsPanel 和 SettingsTaskbar 返回占位符
203203
if (context == UnitContext.SettingsPanel || context == UnitContext.SettingsTaskbar)
204-
return type == MetricType.DataSpeed ? "{u}/s" : "{u}";
204+
{
205+
if (type == MetricType.DataSpeed)
206+
return context == UnitContext.SettingsTaskbar ? "{u}" : "{u}/s";
207+
return "{u}";
208+
}
205209

206210
// 需要根据数值重新计算单位 (FormatDataSizeParts 开销很小)
207211
// UnitContext.Taskbar 对应紧凑模式 -> 整数 (0)

src/ThemeEditor/ThemeEditorForm.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ NumericUpDown AddNum(string label, Func<int> get, Action<int> set)
241241
{
242242
Text = label,
243243
Location = new Point((int)(10 * dpiScale), y + (int)(4 * dpiScale)),
244-
Width = (int)(240 * dpiScale)
244+
Width = (int)(240 * dpiScale),
245+
Height = (int)(25 * dpiScale) // Fix DPI clipping
245246
});
246247

247248
var n = new NumericUpDown
@@ -267,6 +268,7 @@ NumericUpDown AddNum(string label, Func<int> get, Action<int> set)
267268
Text = "说明:窗体圆角设置暂不支持预览 且仅win10下修改圆角有效",
268269
Location = new Point((int)(10 * dpiScale), y),
269270
Width = (int)(350 * dpiScale),
271+
Height = (int)(20 * dpiScale), // Fix DPI clipping
270272
ForeColor = Color.Gray,
271273
Font = new Font("Microsoft YaHei UI", 8f)
272274
});
@@ -305,7 +307,8 @@ ComboBox AddFontCombo(string label, Func<string> get, Action<string> set)
305307
{
306308
Text = label,
307309
Location = new Point((int)(10 * dpiScale), y + (int)(4 * dpiScale)),
308-
Width = (int)(180 * dpiScale)
310+
Width = (int)(180 * dpiScale),
311+
Height = (int)(25 * dpiScale) // Fix DPI clipping
309312
});
310313

311314
var combo = new ComboBox
@@ -336,7 +339,8 @@ NumericUpDown AddNum(string label, Func<double> get, Action<int> set)
336339
{
337340
Text = label,
338341
Location = new Point((int)(10 * dpiScale), y + (int)(4 * dpiScale)),
339-
Width = (int)(180 * dpiScale)
342+
Width = (int)(180 * dpiScale),
343+
Height = (int)(25 * dpiScale) // Fix DPI clipping
340344
});
341345

342346
var n = new NumericUpDown
@@ -406,7 +410,8 @@ Button AddColor(string label, Func<string> get, Action<string> set)
406410
{
407411
Text = label,
408412
Location = new Point((int)(10 * dpiScale), y + (int)(6 * dpiScale)),
409-
Width = (int)(210 * dpiScale)
413+
Width = (int)(210 * dpiScale),
414+
Height = (int)(25 * dpiScale) // Fix DPI clipping
410415
});
411416

412417
// 获取当前颜色

src/UI/Helpers/MainFormWinHelper.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,7 @@ public void InitializeStyle(bool topMost, bool clickThrough)
2727
_form.ShowInTaskbar = false;
2828
_form.TopMost = topMost;
2929

30-
// [Fix #286] 动态切换 WS_EX_NOACTIVATE
31-
// 当置顶开启时,启用 NOACTIVATE 以兼容串流场景;当置顶关闭时,禁用 NOACTIVATE 以恢复正常层级交互。
32-
try
33-
{
34-
int ex = GetWindowLong(_form.Handle, GWL_EXSTYLE);
35-
const int WS_EX_NOACTIVATE = 0x08000000;
36-
37-
if (topMost)
38-
SetWindowLong(_form.Handle, GWL_EXSTYLE, ex | WS_EX_NOACTIVATE);
39-
else
40-
SetWindowLong(_form.Handle, GWL_EXSTYLE, ex & ~WS_EX_NOACTIVATE);
41-
}
42-
catch { }
30+
4331

4432
// 解决 DoubleBuffered 访问权限问题
4533
typeof(Control).GetProperty("DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)

src/UI/MainForm_Transparent.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ protected override CreateParams CreateParams
3535
cp.ExStyle |= 0x80; // WS_EX_TOOLWINDOW
3636
cp.ExStyle &= ~0x00040000; // WS_EX_APPWINDOW
3737

38-
// [Fix #286] 兼容性修复:Moonlight/Parsec 串流时,鼠标悬浮会导致分辨率跳变。
39-
// 添加 WS_EX_NOACTIVATE 防止窗口抢占焦点,避免干扰串流软件的活动窗口判定。
40-
// 仅在置顶模式下启用,否则会导致无法通过点击将窗口置于顶层
41-
if (_cfg != null && _cfg.TopMost)
42-
{
43-
cp.ExStyle |= 0x08000000;
44-
}
45-
4638
// [Fix] 启动时应用鼠标穿透配置,防止因句柄重建导致样式丢失
4739
if (_cfg != null && _cfg.ClickThrough)
4840
{
@@ -206,14 +198,6 @@ private void BindEvents()
206198
_bizHelper.ClampToScreen();
207199
_bizHelper.SavePos();
208200
}
209-
else if (e.Button == MouseButtons.Right)
210-
{
211-
// [Fix] 兼容 Win10:在 WS_EX_NOACTIVATE (置顶) 模式下,
212-
// 右键菜单可能因为窗口未激活而表现异常(如点击无效、样式丢失)。
213-
// 因此在弹出菜单前,显式激活窗口。
214-
// 这虽然会暂时改变焦点,但作为用户主动的右键交互是合理的,不会影响纯悬浮时的防跳变功能。
215-
this.Activate();
216-
}
217201
};
218202

219203
// 双击

src/UI/Settings/MonitorPage.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ private void InitHeader()
7070
_btnTabBar.Click += (s, e) => SwitchTab(true);
7171

7272
_btnTabMain.Location = new Point(UIUtils.S(20), UIUtils.S(8));
73+
// [Fix] 动态跟随:防止 HighDPI 下 AutoSize 尚未计算完成导致重叠
74+
_btnTabMain.SizeChanged += (s, e) => {
75+
_btnTabBar.Location = new Point(_btnTabMain.Right + UIUtils.S(10), UIUtils.S(8));
76+
};
77+
// 初始也设置一次 (虽然此时 Width 可能不准,但有了 SizeChanged 兜底)
7378
_btnTabBar.Location = new Point(_btnTabMain.Right + UIUtils.S(10), UIUtils.S(8));
7479

7580
_chkLinkHorizontal = new LiteCheck(false, LanguageManager.T("Menu.HorizontalFollowsTaskbar"))
@@ -119,7 +124,8 @@ private void InitHeader()
119124

120125
private Button CreateTabButton(string text, bool active)
121126
{
122-
var btn = new Button { Text = text, AutoSize = true, FlatStyle = FlatStyle.Flat, Cursor = Cursors.Hand, Font = UIFonts.Bold(9F), Padding = new Padding(5, 0, 5, 0) };
127+
// [Fix] Scale Padding for High DPI
128+
var btn = new Button { Text = text, AutoSize = true, FlatStyle = FlatStyle.Flat, Cursor = Cursors.Hand, Font = UIFonts.Bold(9F), Padding = UIUtils.S(new Padding(5, 0, 5, 0)) };
123129
btn.FlatAppearance.BorderSize = 0;
124130
UpdateBtnStyle(btn, active);
125131
return btn;

src/UI/SettingsForm.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ private void InitializeComponent()
6969
this.Size = new Size(UIUtils.S(820), UIUtils.S(680));
7070
this.FormBorderStyle = FormBorderStyle.FixedDialog;
7171
this.MaximizeBox = false;
72-
this.MinimizeBox = false;
72+
this.MinimizeBox = true;
7373
this.StartPosition = FormStartPosition.CenterScreen;
7474
this.Text = LanguageManager.T("Menu.SettingsPanel");
7575
this.Font = new Font("Microsoft YaHei UI", 9F);
7676
this.BackColor = UIColors.MainBg;
77-
this.ShowInTaskbar = false;
77+
this.ShowInTaskbar = true;
7878

7979
// 侧边栏
8080
var pnlSidebar = new Panel { Dock = DockStyle.Left, Width = UIUtils.S(160), BackColor = UIColors.SidebarBg };

0 commit comments

Comments
 (0)