@copylee/dsh-computer-use 0.14.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/helper/Native.cs CHANGED
@@ -50,8 +50,14 @@ namespace DshComputerUse
50
50
  [DllImport("user32.dll", SetLastError = true)] public static extern bool DestroyIcon(IntPtr hIcon);
51
51
  [DllImport("user32.dll", SetLastError = true)] public static extern bool SetSystemCursor(IntPtr hcur, uint id);
52
52
  [DllImport("user32.dll", SetLastError = true)] public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, IntPtr pvParam, uint fWinIni);
53
- public const uint SPI_SETCURSORS = 0x0057;
54
- public const uint OCR_NORMAL = 32512, OCR_IBEAM = 32513, OCR_HAND = 32649;
53
+ [DllImport("user32.dll", SetLastError = true)] public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, out bool pvParam, uint fWinIni);
54
+ [DllImport("winmm.dll")] public static extern uint timeBeginPeriod(uint uPeriod);
55
+ [DllImport("winmm.dll")] public static extern uint timeEndPeriod(uint uPeriod);
56
+ [StructLayout(LayoutKind.Sequential)]
57
+ public struct BITMAPINFOHEADER { public uint biSize; public int biWidth; public int biHeight; public ushort biPlanes; public ushort biBitCount; public uint biCompression; public uint biSizeImage; public int biXPelsPerMeter; public int biYPelsPerMeter; public uint biClrUsed; public uint biClrImportant; }
58
+ [DllImport("gdi32.dll")] public static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFOHEADER pbmi, uint iUsage, out IntPtr ppvBits, IntPtr hSection, uint dwOffset);
59
+ public const uint SPI_SETCURSORS = 0x0057, SPI_GETMOUSEVANISH = 0x1020, SPI_SETMOUSEVANISH = 0x1021;
60
+ public const uint OCR_NORMAL = 32512, OCR_IBEAM = 32513, OCR_WAIT = 32514, OCR_HAND = 32649, OCR_APPSTARTING = 32650;
55
61
 
56
62
  public delegate bool MonitorEnumProc(IntPtr hMonitor, IntPtr hdc, ref RECT rect, IntPtr data);
57
63
  [DllImport("user32.dll")] public static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr clip, MonitorEnumProc proc, IntPtr data);
@@ -67,6 +73,7 @@ namespace DshComputerUse
67
73
  [DllImport("gdi32.dll")] public static extern bool DeleteDC(IntPtr hdc);
68
74
  [DllImport("gdi32.dll")] public static extern IntPtr SelectObject(IntPtr hdc, IntPtr obj);
69
75
  [DllImport("gdi32.dll")] public static extern bool DeleteObject(IntPtr obj);
76
+ [DllImport("gdi32.dll")] public static extern IntPtr CreateBitmap(int nWidth, int nHeight, uint cPlanes, uint cBitsPerPel, IntPtr lpvBits);
70
77
 
71
78
  public delegate bool EnumWindowsProc(IntPtr hwnd, IntPtr data);
72
79
  [DllImport("user32.dll")] public static extern bool EnumWindows(EnumWindowsProc proc, IntPtr data);
package/helper/Overlay.cs CHANGED
@@ -217,6 +217,7 @@ namespace DshComputerUse
217
217
  {
218
218
  readonly bool clickThrough;
219
219
  public Rectangle Physical;
220
+ int affinityState = -1;
220
221
 
221
222
  public LayeredForm(bool clickThrough)
222
223
  {
@@ -245,6 +246,7 @@ namespace DshComputerUse
245
246
  {
246
247
  base.OnHandleCreated(e);
247
248
  // Keep the overlay out of every screenshot, including our own.
249
+ affinityState = Overlay.ExcludeFromCapture ? 1 : 0;
248
250
  if (Overlay.ExcludeFromCapture) { try { Native.SetWindowDisplayAffinity(Handle, 0x11); } catch (Exception) { } }
249
251
  }
250
252
 
@@ -291,6 +293,9 @@ namespace DshComputerUse
291
293
 
292
294
  public void SetCapturable(bool capturable)
293
295
  {
296
+ int want = capturable ? 0 : 1;
297
+ if (affinityState == want) return;
298
+ affinityState = want;
294
299
  try { Native.SetWindowDisplayAffinity(Handle, capturable ? 0u : 0x11u); } catch (Exception) { }
295
300
  }
296
301
  }
@@ -377,14 +382,21 @@ namespace DshComputerUse
377
382
  static volatile bool visible;
378
383
  static volatile bool paused;
379
384
  static volatile bool petWaiting;
385
+ static DateTime petWaitingSince = DateTime.UtcNow;
386
+ static string petPhase = "";
387
+ static DateTime petPhaseSince = DateTime.UtcNow;
388
+ static int lastPhaseSec = -1;
380
389
  public static volatile bool SkipWaitRequested;
381
390
  static volatile bool clickTargetEnabled = true;
382
391
  static volatile bool customCursorActive;
392
+ static volatile bool disabledMouseVanish;
383
393
  static string cursorBadge = "DSH";
384
394
  static LayeredForm markForm;
385
395
  static DateTime markExpiresAt = DateTime.MinValue;
386
396
  static bool markActive;
387
397
  static bool markIsResting;
398
+ static LayeredForm clickRippleForm;
399
+ static DateTime clickRippleExpiresAt = DateTime.MinValue;
388
400
  static float cachedMarkScale;
389
401
  static bool cachedMarkFlipX, cachedMarkFlipY, cachedMarkRipple, cachedMarkArrow;
390
402
  static string cachedMarkText = "";
@@ -646,33 +658,67 @@ namespace DshComputerUse
646
658
  g.DrawPolygon(outline, arrow);
647
659
  }
648
660
  }
649
- IntPtr hIcon = bmp.GetHicon();
661
+ // Build a clean 32-bit premultiplied ARGB DIB cursor + all-zero monochrome AND mask
662
+ // so Windows DWM composites it purely on the hardware cursor plane without flicker.
663
+ IntPtr hbmColor = IntPtr.Zero;
664
+ IntPtr hbmMask = IntPtr.Zero;
650
665
  try
651
666
  {
652
- Native.ICONINFO ii;
653
- if (Native.GetIconInfo(hIcon, out ii))
667
+ var bmi = new Native.BITMAPINFOHEADER();
668
+ bmi.biSize = (uint)Marshal.SizeOf(typeof(Native.BITMAPINFOHEADER));
669
+ bmi.biWidth = size;
670
+ bmi.biHeight = -size; // top-down DIB
671
+ bmi.biPlanes = 1;
672
+ bmi.biBitCount = 32;
673
+ bmi.biCompression = 0; // BI_RGB
674
+ IntPtr bits = IntPtr.Zero;
675
+ IntPtr screenDc = Native.GetDC(IntPtr.Zero);
676
+ try { hbmColor = Native.CreateDIBSection(screenDc, ref bmi, 0, out bits, IntPtr.Zero, 0); }
677
+ finally { Native.ReleaseDC(IntPtr.Zero, screenDc); }
678
+ hbmMask = Native.CreateBitmap(size, size, 1, 1, IntPtr.Zero);
679
+ if (hbmColor != IntPtr.Zero && hbmMask != IntPtr.Zero && bits != IntPtr.Zero)
654
680
  {
681
+ var rect = new Rectangle(0, 0, size, size);
682
+ BitmapData data = bmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb);
655
683
  try
656
684
  {
657
- ii.fIcon = false;
658
- ii.xHotspot = tipX;
659
- ii.yHotspot = tipY;
660
- hCursor = Native.CreateIconIndirect(ref ii);
661
- }
662
- finally
663
- {
664
- if (ii.hbmMask != IntPtr.Zero) Native.DeleteObject(ii.hbmMask);
665
- if (ii.hbmColor != IntPtr.Zero) Native.DeleteObject(ii.hbmColor);
685
+ int totalBytes = size * size * 4;
686
+ byte[] buf = new byte[totalBytes];
687
+ for (int row = 0; row < size; row++)
688
+ {
689
+ Marshal.Copy(new IntPtr(data.Scan0.ToInt64() + (long)row * data.Stride), buf, row * size * 4, size * 4);
690
+ }
691
+ Marshal.Copy(buf, 0, bits, totalBytes);
666
692
  }
693
+ finally { bmp.UnlockBits(data); }
694
+ var ii = new Native.ICONINFO();
695
+ ii.fIcon = false;
696
+ ii.xHotspot = tipX;
697
+ ii.yHotspot = tipY;
698
+ ii.hbmColor = hbmColor;
699
+ ii.hbmMask = hbmMask;
700
+ hCursor = Native.CreateIconIndirect(ref ii);
667
701
  }
668
702
  }
669
703
  finally
670
704
  {
671
- Native.DestroyIcon(hIcon);
705
+ if (hbmColor != IntPtr.Zero) Native.DeleteObject(hbmColor);
706
+ if (hbmMask != IntPtr.Zero) Native.DeleteObject(hbmMask);
672
707
  }
673
708
  }
674
709
  if (hCursor == IntPtr.Zero) return;
675
- uint[] ids = new uint[] { Native.OCR_NORMAL, Native.OCR_IBEAM, Native.OCR_HAND };
710
+ // Disable Windows' "Hide pointer while typing" (SPI_SETMOUSEVANISH) temporarily so
711
+ // synthetic keyboard typing never makes our hardware cursor vanish for 1-2 seconds.
712
+ if (!disabledMouseVanish)
713
+ {
714
+ bool vanishOn = false;
715
+ if (Native.SystemParametersInfo(Native.SPI_GETMOUSEVANISH, 0, out vanishOn, 0) && vanishOn)
716
+ {
717
+ if (Native.SystemParametersInfo(Native.SPI_SETMOUSEVANISH, 0, IntPtr.Zero, 0))
718
+ disabledMouseVanish = true;
719
+ }
720
+ }
721
+ uint[] ids = new uint[] { Native.OCR_NORMAL, Native.OCR_IBEAM, Native.OCR_HAND, Native.OCR_APPSTARTING, Native.OCR_WAIT };
676
722
  bool anyApplied = false;
677
723
  for (int i = 0; i < ids.Length; i++)
678
724
  {
@@ -690,9 +736,14 @@ namespace DshComputerUse
690
736
  }
691
737
  }
692
738
 
693
- /** Reload the user's native Windows cursor scheme (idempotent & crash-safe). */
739
+ /** Reload the user's native Windows cursor scheme and mouse-vanish setting (idempotent & crash-safe). */
694
740
  public static void RestoreSystemCursor(bool force)
695
741
  {
742
+ if (disabledMouseVanish)
743
+ {
744
+ try { Native.SystemParametersInfo(Native.SPI_SETMOUSEVANISH, 0, new IntPtr(1), 0); } catch (Exception) { }
745
+ disabledMouseVanish = false;
746
+ }
696
747
  if (!force && !customCursorActive) return;
697
748
  try { Native.SystemParametersInfo(Native.SPI_SETCURSORS, 0, IntPtr.Zero, 0); } catch (Exception) { }
698
749
  customCursorActive = false;
@@ -755,7 +806,28 @@ namespace DshComputerUse
755
806
  {
756
807
  if (thread == null) return;
757
808
  if (value) SkipWaitRequested = false;
758
- Ui(delegate { petWaiting = value; if (visible) RenderPill(); });
809
+ Ui(delegate
810
+ {
811
+ petWaiting = value;
812
+ if (value) { petWaitingSince = DateTime.UtcNow; lastPhaseSec = -1; }
813
+ if (visible) RenderPill();
814
+ });
815
+ }
816
+
817
+ public static void SetPhase(string phase)
818
+ {
819
+ if (thread == null) return;
820
+ Ui(delegate
821
+ {
822
+ string next = phase ?? "";
823
+ if (petPhase != next)
824
+ {
825
+ petPhase = next;
826
+ petPhaseSince = DateTime.UtcNow;
827
+ lastPhaseSec = -1;
828
+ }
829
+ if (visible && !petFinished) RenderPill();
830
+ });
759
831
  }
760
832
 
761
833
  public static void Hide()
@@ -772,6 +844,8 @@ namespace DshComputerUse
772
844
  CloseInput(false);
773
845
  petFinished = false;
774
846
  petWaiting = false;
847
+ petPhase = "";
848
+ lastPhaseSec = -1;
775
849
  SkipWaitRequested = false;
776
850
  petReply = "";
777
851
  visible = false;
@@ -857,15 +931,16 @@ namespace DshComputerUse
857
931
  float pillW = textSize.Width > 0 ? (float)Math.Ceiling(textSize.Width + 2f * pillPadX) : 0f;
858
932
  float pillH = textSize.Height > 0 ? Math.Max(19f * s, (float)Math.Ceiling(textSize.Height + 5f * s)) : 0f;
859
933
 
860
- // Offsets relative to the pointer tip at (0, 0). Clear the native Windows pointer
861
- // arrow cleanly when attaching to the live OS cursor (drawArrow == false).
862
- float tagX = flipX ? (-10f * s - pillW) : (drawArrow ? 13f * s : 14f * s);
863
- float tagY = flipY ? (-10f * s - pillH) : (drawArrow ? 15f * s : 18f * s);
934
+ // Offsets relative to the pointer tip at (0, 0). When not showing a click ripple,
935
+ // keep the layered pill strictly outside the hardware cursor's bounding box so
936
+ // Windows DWM never flickers the hardware cursor plane over WDA_EXCLUDEFROMCAPTURE.
937
+ float tagX = flipX ? (-10f * s - pillW) : (ripple ? 14f * s : 16f * s);
938
+ float tagY = flipY ? (-10f * s - pillH) : (ripple ? 16f * s : 21f * s);
864
939
 
865
- float minX = Math.Min(-glowR, pillW > 0 ? tagX : 0f) - pad;
866
- float maxX = Math.Max(glowR, Math.Max(14f * s, pillW > 0 ? tagX + pillW : 0f)) + pad;
867
- float minY = Math.Min(-glowR, pillH > 0 ? tagY : 0f) - pad;
868
- float maxY = Math.Max(glowR, Math.Max(22f * s, pillH > 0 ? tagY + pillH : 0f)) + pad;
940
+ float minX = ripple ? Math.Min(-glowR, pillW > 0 ? tagX : 0f) - pad : (pillW > 0 ? tagX - pad : 0f);
941
+ float maxX = ripple ? Math.Max(glowR, Math.Max(14f * s, pillW > 0 ? tagX + pillW : 0f)) + pad : (pillW > 0 ? tagX + pillW + pad : 1f);
942
+ float minY = ripple ? Math.Min(-glowR, pillH > 0 ? tagY : 0f) - pad : (pillH > 0 ? tagY - pad : 0f);
943
+ float maxY = ripple ? Math.Max(glowR, Math.Max(22f * s, pillH > 0 ? tagY + pillH : 0f)) + pad : (pillH > 0 ? tagY + pillH + pad + 2f * s : 1f);
869
944
 
870
945
  int W = Math.Max(1, (int)Math.Ceiling(maxX - minX));
871
946
  int H = Math.Max(1, (int)Math.Ceiling(maxY - minY));
@@ -879,16 +954,19 @@ namespace DshComputerUse
879
954
  g.SmoothingMode = SmoothingMode.AntiAlias;
880
955
  g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
881
956
 
882
- // 1. Soft radial spotlight centered right under the tip (cx, cy).
883
- using (var spot = new GraphicsPath())
957
+ // 1. Soft radial spotlight ONLY on post-click ripples (avoid overlapping the live hardware cursor).
958
+ if (ripple)
884
959
  {
885
- spot.AddEllipse(cx - glowR, cy - glowR, glowR * 2f, glowR * 2f);
886
- using (var glow = new PathGradientBrush(spot))
960
+ using (var spot = new GraphicsPath())
887
961
  {
888
- glow.CenterPoint = new PointF(cx, cy);
889
- glow.CenterColor = Color.FromArgb(ripple ? 135 : 115, color);
890
- glow.SurroundColors = new Color[] { Color.FromArgb(0, color) };
891
- g.FillPath(glow, spot);
962
+ spot.AddEllipse(cx - glowR, cy - glowR, glowR * 2f, glowR * 2f);
963
+ using (var glow = new PathGradientBrush(spot))
964
+ {
965
+ glow.CenterPoint = new PointF(cx, cy);
966
+ glow.CenterColor = Color.FromArgb(135, color);
967
+ glow.SurroundColors = new Color[] { Color.FromArgb(0, color) };
968
+ g.FillPath(glow, spot);
969
+ }
892
970
  }
893
971
  }
894
972
 
@@ -1033,7 +1111,7 @@ namespace DshComputerUse
1033
1111
  PlaceMarkOnUi(latestMouseX, latestMouseY, cursorBadge, Accent, 0, false, false, true);
1034
1112
  }
1035
1113
 
1036
- /** Smooth EaseOutCubic glide (~150ms @ ~60-90Hz) moving both OS cursor and cached badge in lockstep. */
1114
+ /** Smooth true-120Hz EaseOutCubic glide (~140ms) moving OS cursor and cached DSH badge in lockstep. */
1037
1115
  public static void GlideMark(int x, int y, string text, Color color, int holdMs, bool capturable, bool ripple)
1038
1116
  {
1039
1117
  int startX, startY;
@@ -1042,22 +1120,34 @@ namespace DshComputerUse
1042
1120
  else if (hasLastMark) { startX = lastMarkX; startY = lastMarkY; }
1043
1121
  else { startX = x; startY = y; }
1044
1122
  double dist = Math.Sqrt((double)(x - startX) * (x - startX) + (double)(y - startY) * (y - startY));
1045
- if (dist >= 30.0)
1123
+ if (dist >= 24.0)
1046
1124
  {
1047
- int steps = Math.Max(8, Math.Min(16, (int)(dist / 65.0) + 8));
1048
- for (int i = 1; i < steps; i++)
1125
+ double durationMs = Math.Max(95.0, Math.Min(190.0, 85.0 + dist * 0.085));
1126
+ bool highRes = false;
1127
+ try
1128
+ {
1129
+ highRes = Native.timeBeginPeriod(1) == 0;
1130
+ var sw = Stopwatch.StartNew();
1131
+ while (true)
1132
+ {
1133
+ double elapsed = sw.Elapsed.TotalMilliseconds;
1134
+ if (elapsed >= durationMs) break;
1135
+ double t = elapsed / durationMs;
1136
+ double ease = 1.0 - Math.Pow(1.0 - t, 3.0); // EaseOutCubic
1137
+ int ix = startX + (int)Math.Round((x - startX) * ease);
1138
+ int iy = startY + (int)Math.Round((y - startY) * ease);
1139
+ try { Native.SetCursorPos(ix, iy); } catch (Exception) { }
1140
+ Mark(ix, iy, text, color, holdMs, false, false);
1141
+ Thread.Sleep(7);
1142
+ }
1143
+ }
1144
+ finally
1049
1145
  {
1050
- double t = (double)i / steps;
1051
- double ease = 1.0 - Math.Pow(1.0 - t, 3.0); // EaseOutCubic
1052
- int ix = startX + (int)Math.Round((x - startX) * ease);
1053
- int iy = startY + (int)Math.Round((y - startY) * ease);
1054
- try { Native.SetCursorPos(ix, iy); } catch (Exception) { }
1055
- Mark(ix, iy, text, color, holdMs, capturable, false);
1056
- Thread.Sleep(10);
1146
+ if (highRes) { try { Native.timeEndPeriod(1); } catch (Exception) { } }
1057
1147
  }
1058
1148
  }
1059
1149
  try { Native.SetCursorPos(x, y); } catch (Exception) { }
1060
- Mark(x, y, text, color, holdMs, capturable, ripple);
1150
+ Mark(x, y, text, color, holdMs, false, false);
1061
1151
  }
1062
1152
 
1063
1153
  static void ShowRestingMarkOnUi(int x, int y)
@@ -1071,6 +1161,42 @@ namespace DshComputerUse
1071
1161
  Ui(delegate { PlaceMarkOnUi(x, y, text, color, holdMs, capturable, ripple, false); });
1072
1162
  }
1073
1163
 
1164
+ /** Render post-click ripple on a separate capturable form so the live DSH badge never toggles affinity or blinks. */
1165
+ static void ShowClickRippleOnUi(int x, int y, string text, Color color, int holdMs)
1166
+ {
1167
+ if (clickRippleForm == null)
1168
+ {
1169
+ clickRippleForm = new LayeredForm(true);
1170
+ clickRippleForm.SetCapturable(true);
1171
+ clickRippleForm.Show();
1172
+ }
1173
+ float scale; Rectangle mon;
1174
+ MonitorAt(x, y, out scale, out mon);
1175
+ float s = Math.Max(0.75f, Math.Min(3f, scale));
1176
+ string labelText = text ?? "";
1177
+ int estW = (int)((Math.Max(6, labelText.Length) * 11 + 36) * s);
1178
+ bool flipX = !mon.IsEmpty && x + estW > mon.Right;
1179
+ bool flipY = !mon.IsEmpty && y + (int)(52 * s) > mon.Bottom;
1180
+ int cx, cy;
1181
+ using (var bmp = DrawMark(labelText, color, scale, flipX, flipY, true, false, out cx, out cy))
1182
+ {
1183
+ clickRippleForm.SetBitmap(bmp, new Rectangle(x - cx, y - cy, bmp.Width, bmp.Height), 255);
1184
+ }
1185
+ clickRippleForm.KeepOnTop();
1186
+ clickRippleExpiresAt = DateTime.UtcNow.AddMilliseconds(holdMs);
1187
+ if (!timer.Enabled) timer.Start();
1188
+ }
1189
+
1190
+ static void HideClickRipple()
1191
+ {
1192
+ clickRippleExpiresAt = DateTime.MinValue;
1193
+ if (clickRippleForm != null)
1194
+ {
1195
+ clickRippleForm.Close();
1196
+ clickRippleForm = null;
1197
+ }
1198
+ }
1199
+
1074
1200
  public static void MarkResult(int x, int y, string button, int count, string coordLabel)
1075
1201
  {
1076
1202
  Color color;
@@ -1080,11 +1206,23 @@ namespace DshComputerUse
1080
1206
  else if (button == "right") { color = Color.FromArgb(16, 185, 129); verb = "已右键"; }
1081
1207
  else if (button == "middle") { color = Color.FromArgb(6, 182, 212); verb = "已中键"; }
1082
1208
  else { color = Color.FromArgb(59, 130, 246); verb = "已单击"; }
1083
- Mark(x, y, verb + " " + coordLabel, color, 900, true, true);
1209
+ Ensure();
1210
+ Ui(delegate
1211
+ {
1212
+ ShowClickRippleOnUi(x, y, verb + " " + coordLabel, color, 750);
1213
+ // Keep the live DSH badge immediately tracking the pointer without freezing at the click spot.
1214
+ if (visible && clickTargetEnabled && !petFinished && !paused)
1215
+ {
1216
+ Native.POINT cp;
1217
+ if (Native.GetCursorPos(out cp)) ShowRestingMarkOnUi(cp.X, cp.Y);
1218
+ else ShowRestingMarkOnUi(x, y);
1219
+ }
1220
+ });
1084
1221
  }
1085
1222
 
1086
1223
  static void HideMark()
1087
1224
  {
1225
+ HideClickRipple();
1088
1226
  markActive = false;
1089
1227
  markIsResting = false;
1090
1228
  hasCachedMarkBitmap = false;
@@ -1186,6 +1324,10 @@ namespace DshComputerUse
1186
1324
 
1187
1325
  static void Tick()
1188
1326
  {
1327
+ if (clickRippleForm != null && DateTime.UtcNow >= clickRippleExpiresAt)
1328
+ {
1329
+ HideClickRipple();
1330
+ }
1189
1331
  if (markActive && DateTime.UtcNow >= markExpiresAt)
1190
1332
  {
1191
1333
  if (visible && clickTargetEnabled && !petFinished && !paused)
@@ -1199,7 +1341,7 @@ namespace DshComputerUse
1199
1341
  }
1200
1342
  if (!visible)
1201
1343
  {
1202
- if (!markActive) timer.Stop();
1344
+ if (!markActive && clickRippleForm == null) timer.Stop();
1203
1345
  return;
1204
1346
  }
1205
1347
  if (visible && clickTargetEnabled && !petFinished && !paused && !markActive)
@@ -1227,12 +1369,16 @@ namespace DshComputerUse
1227
1369
  byte alpha = (byte)Math.Max(0, Math.Min(255, 255 * fadeIn * breathe));
1228
1370
  foreach (var g in glows) g.SetAlpha(alpha);
1229
1371
  if (Key() != rendered) RenderPill(); // typing started or stopped
1372
+ else if (!paused && (petWaiting || petPhase == "llm"))
1373
+ {
1374
+ int sec = (int)Math.Max(0, Math.Floor((DateTime.UtcNow - (petWaiting ? petWaitingSince : petPhaseSince)).TotalSeconds));
1375
+ if (sec != lastPhaseSec) { lastPhaseSec = sec; RenderPill(); }
1376
+ }
1230
1377
  if ((int)(t * 25) % 50 == 0)
1231
1378
  {
1232
1379
  foreach (var g in glows) g.KeepOnTop();
1233
1380
  if (pill != null) pill.KeepOnTop();
1234
1381
  if (pet != null) pet.KeepOnTop();
1235
- if (markForm != null) markForm.KeepOnTop();
1236
1382
  if (input != null) Native.SetWindowPos(input.Handle, new IntPtr(-1), 0, 0, 0, 0, 0x0001 | 0x0002 | 0x0010);
1237
1383
  }
1238
1384
  }
@@ -1397,13 +1543,20 @@ namespace DshComputerUse
1397
1543
 
1398
1544
  bool isCompact = petSize == "compact";
1399
1545
  bool isDetailed = petSize == "detailed";
1546
+ int waitSec = petWaiting ? (int)Math.Max(0, Math.Floor((DateTime.UtcNow - petWaitingSince).TotalSeconds)) : 0;
1547
+ int llmSec = petPhase == "llm" ? (int)Math.Max(0, Math.Floor((DateTime.UtcNow - petPhaseSince).TotalSeconds)) : 0;
1548
+ bool hasReply = !petFinished && petReply.Length > 0;
1549
+ bool showLlmWait = !petFinished && !paused && !petWaiting && petPhase == "llm" && !hasReply && petThinking.Length == 0;
1400
1550
  string hoverTip = ButtonTip(hoveredBtn);
1401
1551
  string title = hoverTip.Length > 0
1402
1552
  ? (isCompact ? "" : "DSH")
1403
1553
  : petFinished ? "已完成" : (isCompact && label.Length > 12 ? label.Substring(0, 11) + "…" : label);
1404
1554
  string state = hoverTip.Length > 0 ? hoverTip
1405
1555
  : petFinished ? "" : paused ? (input != null ? "输入指令中…" : "已暂停 · Esc 继续")
1406
- : Typing() ? "你正在操作,已暂停" : (isCompact ? "" : "Esc 暂停");
1556
+ : Typing() ? "你正在操作,已暂停"
1557
+ : petWaiting ? (isCompact ? ("等待 " + waitSec + "s") : ("等待画面 " + waitSec + "s"))
1558
+ : showLlmWait ? (isCompact ? ("模型响应 " + llmSec + "s") : ("等待模型响应 " + llmSec + "s"))
1559
+ : (isCompact ? "" : "Esc 暂停");
1407
1560
  // Header buttons, right to left.
1408
1561
  var actions = new List<string>(); var glyphs = new List<string>();
1409
1562
  if (petFinished) { actions.Add("close"); glyphs.Add("\uE711"); }
@@ -1422,13 +1575,16 @@ namespace DshComputerUse
1422
1575
  float bodyW = (isCompact ? 320f : isDetailed ? 484f : 420f) * s;
1423
1576
  float pad = (isCompact ? 13f : 16f) * s;
1424
1577
  float headH = (isCompact ? 40f : 44f) * s;
1425
- bool showThinking = !isCompact || petExpanded || (!petFinished && petReply.Length > 0);
1578
+ bool showThinking = !isCompact || petExpanded || hasReply || petWaiting || showLlmWait;
1426
1579
  bool showTimeline = petExpanded || isDetailed;
1427
1580
  float replyH = showThinking ? (isDetailed && !petExpanded ? 42f * s : 26f * s) : 0f;
1428
- bool hasReply = !petFinished && petReply.Length > 0;
1429
1581
  string progressPrefix = hasReply ? "说明 · " : "思考 · ";
1430
1582
  string progressBody = hasReply ? petReply : petThinking;
1431
- string progress = petFinished ? "已交还电脑控制" : progressBody.Length > 0 ? progressPrefix + progressBody : "正在操作,等待下一步…";
1583
+ string progress = petFinished ? "已交还电脑控制"
1584
+ : petWaiting ? ("等待画面变化… " + waitSec + "s(点右上角 ⏭ 可提前继续)")
1585
+ : progressBody.Length > 0 ? progressPrefix + progressBody
1586
+ : showLlmWait ? ("等待模型响应中… " + llmSec + "s")
1587
+ : "正在操作,等待下一步…";
1432
1588
  if (showThinking && (petExpanded || isDetailed))
1433
1589
  {
1434
1590
  using (var probe = new Bitmap(1, 1))
@@ -1837,11 +1993,11 @@ namespace DshComputerUse
1837
1993
  if (nCode >= 0 && visible)
1838
1994
  {
1839
1995
  int msg = wParam.ToInt32();
1840
- // Hardware-rate cursor tracking on WM_MOUSEMOVE: never triggers takeover, only moves
1841
- // the cached resting badge via SetWindowPos for silky native-grade responsiveness.
1996
+ // Native-rate cursor tracking on WM_MOUSEMOVE: Interlocked.Exchange coalesces bursts
1997
+ // directly to the UI message loop rate (60Hz/120Hz/144Hz+) with zero 15.6ms TickCount lag.
1842
1998
  if (msg == 0x0200)
1843
1999
  {
1844
- if (clickTargetEnabled && !petFinished && markActive && markIsResting && invoker != null)
2000
+ if (clickTargetEnabled && !petFinished && !paused && markActive && markIsResting && invoker != null)
1845
2001
  {
1846
2002
  var mm = (Native.MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Native.MSLLHOOKSTRUCT));
1847
2003
  latestMouseX = mm.pt.X;
package/helper/Program.cs CHANGED
@@ -231,6 +231,7 @@ namespace DshComputerUse
231
231
  case "overlay_show": Overlay.ExcludeFromCapture = Args.Bool(r, "excludeFromCapture", true); Overlay.Show(r); return null;
232
232
  case "overlay_pause": Overlay.SetPaused(Args.Bool(r, "paused", false)); return null;
233
233
  case "overlay_waiting": Overlay.SetWaiting(Args.Bool(r, "waiting", false)); return null;
234
+ case "overlay_phase": Overlay.SetPhase(Args.Str(r, "phase", "")); return null;
234
235
  case "window_card": CardLayer.SetOpacity(Args.Int(r, "opacity", 100)); return Windows.Card(new IntPtr(Convert.ToInt64(r["hwnd"])), Args.Int(r, "x", 0), Args.Int(r, "y", 0), Args.Int(r, "width", 0), Args.Int(r, "height", 0));
235
236
  case "window_uncard": return Windows.Uncard(new IntPtr(Convert.ToInt64(r["hwnd"])));
236
237
  case "overlay_status": Overlay.Status(Args.Str(r, "status", "")); return null;
package/helper/Uia.cs CHANGED
@@ -158,11 +158,22 @@ namespace DshComputerUse
158
158
  else if (action == "set_checked")
159
159
  {
160
160
  bool want = Args.Bool(r, "checked", true);
161
+ ToggleState desired = want ? ToggleState.On : ToggleState.Off;
161
162
  var tp = (TogglePattern)pattern;
162
- bool isOn = tp.Current.ToggleState == ToggleState.On;
163
- if (isOn != want) tp.Toggle();
164
- result["changed"] = isOn != want;
165
- result["checked"] = want;
163
+ ToggleState initial = tp.Current.ToggleState;
164
+ bool changed = false;
165
+ // Handle tri-state checkboxes (Indeterminate -> On -> Off) with up to 2 toggles.
166
+ for (int attempt = 0; attempt < 2 && tp.Current.ToggleState != desired; attempt++)
167
+ {
168
+ tp.Toggle();
169
+ changed = true;
170
+ Thread.Sleep(20);
171
+ }
172
+ ToggleState actual = tp.Current.ToggleState;
173
+ result["changed"] = changed || actual != initial;
174
+ result["checked"] = actual == ToggleState.On;
175
+ result["toggleState"] = actual.ToString();
176
+ result["verified"] = actual == desired;
166
177
  }
167
178
  else if (action == "expand" || action == "collapse")
168
179
  {
@@ -174,21 +185,41 @@ namespace DshComputerUse
174
185
  {
175
186
  if (wantExpand) ec.Expand();
176
187
  else ec.Collapse();
188
+ Thread.Sleep(25);
177
189
  }
190
+ var actual = ec.Current.ExpandCollapseState;
191
+ bool verified = wantExpand
192
+ ? (actual == ExpandCollapseState.Expanded || actual == ExpandCollapseState.PartiallyExpanded)
193
+ : (actual == ExpandCollapseState.Collapsed);
178
194
  result["changed"] = !already;
195
+ result["state"] = actual.ToString();
196
+ result["verified"] = verified;
179
197
  }
180
198
  else if (action == "select")
181
199
  {
182
200
  var sp = (SelectionItemPattern)pattern;
183
201
  bool already = sp.Current.IsSelected;
184
- if (!already) sp.Select();
202
+ if (!already)
203
+ {
204
+ sp.Select();
205
+ Thread.Sleep(20);
206
+ }
207
+ bool actual = sp.Current.IsSelected;
185
208
  result["changed"] = !already;
209
+ result["selected"] = actual;
210
+ result["verified"] = actual;
186
211
  }
187
212
  else if (action == "set_value")
188
213
  {
189
214
  string val = Args.Str(r, "value", "");
190
- ((ValuePattern)pattern).SetValue(val);
215
+ var vp = (ValuePattern)pattern;
216
+ vp.SetValue(val);
217
+ Thread.Sleep(20);
218
+ string actual = "";
219
+ try { actual = vp.Current.Value ?? ""; } catch (Exception) { actual = ""; }
191
220
  result["changed"] = true;
221
+ result["verified"] = actual == val;
222
+ result["actualLength"] = actual.Length;
192
223
  }
193
224
  result["performed"] = true;
194
225
  return result;
@@ -229,6 +260,7 @@ namespace DshComputerUse
229
260
  string query = Args.Str(r, "query", "").Trim();
230
261
  int maxMatches = Math.Max(1, Math.Min(120, Args.Int(r, "maxMatches", 24)));
231
262
  List<object> result = null;
263
+ bool truncated = false;
232
264
  Exception error = null;
233
265
 
234
266
  var worker = new Thread(delegate ()
@@ -268,7 +300,6 @@ namespace DshComputerUse
268
300
  string qLower = query.ToLowerInvariant();
269
301
  foreach (AutomationElement el in found)
270
302
  {
271
- if (list.Count >= maxMatches) break;
272
303
  var rect = (System.Windows.Rect)el.GetCachedPropertyValue(AutomationElement.BoundingRectangleProperty);
273
304
  if (rect.IsEmpty || rect.Width < 2 || rect.Height < 2) continue;
274
305
  var type = (ControlType)el.GetCachedPropertyValue(AutomationElement.ControlTypeProperty);
@@ -278,6 +309,7 @@ namespace DshComputerUse
278
309
  && elName.ToLowerInvariant().IndexOf(qLower, StringComparison.Ordinal) < 0
279
310
  && elAid.ToLowerInvariant().IndexOf(qLower, StringComparison.Ordinal) < 0)
280
311
  continue;
312
+ if (list.Count >= maxMatches) { truncated = true; break; }
281
313
 
282
314
  bool isPwd = false;
283
315
  try
@@ -321,6 +353,7 @@ namespace DshComputerUse
321
353
  if (error != null) throw error;
322
354
  var outMap = Windows.Describe(hwnd);
323
355
  outMap["elements"] = result ?? new List<object>();
356
+ outMap["truncated"] = truncated;
324
357
  return outMap;
325
358
  }
326
359