dsh-gufa-code 1.3.198 → 1.3.199

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/client.js CHANGED
@@ -16,7 +16,7 @@ const GUFA_NS = 'gufa-code'
16
16
  const G = {}
17
17
  G.NS = GUFA_NS
18
18
  /** 客户端构建标记(排查页面是否加载了新代码时看标题栏) */
19
- G.BUILD = '1.3.198'
19
+ G.BUILD = '1.3.199'
20
20
  G.PANEL_ID = 'gufa-code'
21
21
  /** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
22
22
  G.pendingEntryWorkspace = null
@@ -94,6 +94,8 @@ constexpr int kControllerWatchdogMs = 12000;
94
94
  const COLORREF kBackgroundColor = RGB(13, 15, 19);
95
95
 
96
96
  HINSTANCE g_instance = nullptr;
97
+ class FloatApp;
98
+ FloatApp* g_activeFloatApp = nullptr;
97
99
  std::wstring g_logPath;
98
100
  /* 崩溃兜底:记录被隐藏的 DSH 窗口,异常退出前尽量恢复(全局变量便于崩溃过滤器访问) */
99
101
  std::vector<HWND> g_crashRestoreWindows;
@@ -973,6 +975,8 @@ class FloatApp {
973
975
  void OnFollowTimer();
974
976
  void ApplyFollowFrame();
975
977
  void ApplyClickThrough();
978
+ void ForwardMouseToUnderlying(UINT message, const MSLLHOOKSTRUCT* info);
979
+ static LRESULT CALLBACK LowLevelMouseProc(int code, WPARAM wparam, LPARAM lparam);
976
980
  void OnHideDshTimer();
977
981
  void HideDshWindows();
978
982
  void RestoreDshWindows();
@@ -1044,8 +1048,11 @@ class FloatApp {
1044
1048
  bool suppressWindowDestroy_ = false;
1045
1049
  bool hideDshDone_ = false;
1046
1050
  bool clickThrough_ = false;
1047
- bool clickThroughLayered_ = false;
1048
1051
  bool clickThroughHotkey_ = false;
1052
+ HHOOK mouseHook_ = nullptr;
1053
+ bool mouseHookInstalled_ = false;
1054
+ HWND forwardedTarget_ = nullptr;
1055
+ bool forwardedLeftDown_ = false;
1049
1056
  };
1050
1057
 
1051
1058
  namespace {
@@ -1091,6 +1098,7 @@ static void ShowFloatContextMenu(HWND owner, FloatApp* app) {
1091
1098
  }
1092
1099
 
1093
1100
  FloatApp::~FloatApp() {
1101
+ if (g_activeFloatApp == this) g_activeFloatApp = nullptr;
1094
1102
  if (hostProcess_ != nullptr) {
1095
1103
  CloseHandle(hostProcess_);
1096
1104
  hostProcess_ = nullptr;
@@ -1362,10 +1370,9 @@ bool FloatApp::CreateMainWindow() {
1362
1370
  bool FloatApp::CreateHostWindow(const RECT& rect, bool composition) {
1363
1371
  hostingMode_ = composition ? HostingMode::Composition : HostingMode::Windowed;
1364
1372
  DWORD extendedStyle = WS_EX_TOPMOST | WS_EX_TOOLWINDOW;
1365
- /* 透明 + 鼠标穿透的正确组合:WS_EX_LAYERED 与 DirectComposition 可以共存;
1366
- WS_EX_NOREDIRECTIONBITMAP 与 LAYERED 语义冲突会出白色矩形,而且 NORD 本身
1367
- 不实现穿透(HTTRANSPARENT 又只在同线程生效)。 */
1368
- if (composition) extendedStyle |= WS_EX_LAYERED;
1373
+ /* 透明视觉继续用 NORD + DComp(per-pixel alpha 正确);穿透改为鼠标钩子转发,
1374
+ 不再用 LAYERED 改变窗口合成路径(否则透明白底/黑底,摸鱼透明度会乱)。 */
1375
+ if (composition) extendedStyle |= WS_EX_NOREDIRECTIONBITMAP;
1369
1376
  const DWORD style = WS_POPUP | WS_THICKFRAME | WS_CLIPCHILDREN;
1370
1377
  hwnd_ = CreateWindowExW(extendedStyle, kMainWindowClass, kWindowTitle, style, rect.left,
1371
1378
  rect.top, rect.right - rect.left, rect.bottom - rect.top, nullptr,
@@ -1375,12 +1382,10 @@ bool FloatApp::CreateHostWindow(const RECT& rect, bool composition) {
1375
1382
  static_cast<unsigned long>(GetLastError()));
1376
1383
  return false;
1377
1384
  }
1385
+ g_activeFloatApp = this;
1378
1386
  LogFmt(L"main-window-created composition=%d rect=(%ld,%ld)-(%ld,%ld) dpi=%u",
1379
1387
  composition ? 1 : 0, static_cast<long>(rect.left), static_cast<long>(rect.top),
1380
1388
  static_cast<long>(rect.right), static_cast<long>(rect.bottom), WindowDpi(hwnd_));
1381
- if (composition) {
1382
- SetLayeredWindowAttributes(hwnd_, 0, 255, LWA_ALPHA);
1383
- }
1384
1389
  if (RegisterHotKey(hwnd_, kHotkeyClickThrough, MOD_CONTROL | MOD_ALT | MOD_SHIFT, 'G')) {
1385
1390
  clickThroughHotkey_ = true;
1386
1391
  Log(L"click-through-hotkey=registered Ctrl+Alt+Shift+G");
@@ -2537,29 +2542,122 @@ void FloatApp::ToggleClickThrough() {
2537
2542
 
2538
2543
  void FloatApp::ApplyClickThrough() {
2539
2544
  if (hwnd_ == nullptr) return;
2540
- LONG_PTR exStyle = GetWindowLongPtrW(hwnd_, GWL_EXSTYLE);
2541
- /* 跨进程穿透只有 WS_EX_LAYERED | WS_EX_TRANSPARENT 有效:
2542
- - NORD 窗口不受 WS_EX_TRANSPARENT 影响;
2543
- - WM_NCHITTEST→HTTRANSPARENT 只在同线程窗口间下传,跨进程会吞掉点击。
2544
- 所以 composition 窗口改成 LAYERED + DComp,穿透只翻转 TRANSPARENT 位。 */
2545
- LONG_PTR next = clickThrough_ ? (exStyle | WS_EX_TRANSPARENT | WS_EX_LAYERED)
2546
- : (exStyle & ~static_cast<LONG_PTR>(WS_EX_TRANSPARENT));
2547
- if ((next & WS_EX_LAYERED) != 0 && (exStyle & WS_EX_LAYERED) == 0) {
2548
- SetLayeredWindowAttributes(hwnd_, 0, 255, LWA_ALPHA);
2549
- }
2550
- clickThroughLayered_ = (next & WS_EX_LAYERED) != 0;
2551
- if (next != exStyle) {
2552
- SetWindowLongPtrW(hwnd_, GWL_EXSTYLE, next);
2553
- SetWindowPos(hwnd_, nullptr, 0, 0, 0, 0,
2554
- SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
2555
- }
2556
- int childCount = 0;
2557
- EnumChildWindows(hwnd_, CountChildWindow, reinterpret_cast<LPARAM>(&childCount));
2558
- EnumChildWindows(hwnd_, SetChildClickThrough, clickThrough_ ? 1 : 0);
2559
- LogFmt(L"click-through=%d mode=%s layered=%d styleTransparent=%d children=%d", clickThrough_ ? 1 : 0,
2545
+ /* 保持 NORD+DComp 的 per-pixel 透明,不切 LAYERED。
2546
+ 穿透通过 WH_MOUSE_LL 钩子把鼠标消息转发给下层窗口实现(跨进程唯一不破坏透明的方式):
2547
+ - 点击/滚轮:临时隐藏自身 → WindowFromPoint 找下层窗口 → 显示自身 → SendMessage 转发;
2548
+ - 左键按住拖动期间保持隐藏,松开后恢复,drag 直接作用在下层 App。 */
2549
+ if (clickThrough_ && !mouseHookInstalled_) {
2550
+ mouseHook_ = SetWindowsHookExW(WH_MOUSE_LL, LowLevelMouseProc, g_instance, 0);
2551
+ mouseHookInstalled_ = mouseHook_ != nullptr;
2552
+ if (!mouseHookInstalled_) {
2553
+ LogFmt(L"click-through-hook=register-failed err=%lu", static_cast<unsigned long>(GetLastError()));
2554
+ clickThrough_ = false;
2555
+ }
2556
+ } else if (!clickThrough_ && mouseHookInstalled_) {
2557
+ if (mouseHook_ != nullptr) UnhookWindowsHookEx(mouseHook_);
2558
+ mouseHook_ = nullptr;
2559
+ mouseHookInstalled_ = false;
2560
+ forwardedTarget_ = nullptr;
2561
+ forwardedLeftDown_ = false;
2562
+ if (IsWindowVisible(hwnd_) == FALSE) ShowWindow(hwnd_, SW_SHOWNOACTIVATE);
2563
+ }
2564
+ LogFmt(L"click-through=%d mode=%s hook=%d", clickThrough_ ? 1 : 0,
2560
2565
  hostingMode_ == HostingMode::Composition ? L"composition" : L"windowed",
2561
- clickThroughLayered_ ? 1 : 0,
2562
- (GetWindowLongPtrW(hwnd_, GWL_EXSTYLE) & WS_EX_TRANSPARENT) != 0 ? 1 : 0, childCount);
2566
+ mouseHookInstalled_ ? 1 : 0);
2567
+ }
2568
+
2569
+ void FloatApp::ForwardMouseToUnderlying(UINT message, const MSLLHOOKSTRUCT* info) {
2570
+ if (hwnd_ == nullptr || info == nullptr) return;
2571
+ const POINT screenPoint = info->pt;
2572
+ auto sendToTarget = [&](HWND target, UINT msg, WPARAM wparam, LPARAM lparam) {
2573
+ if (target == nullptr) return;
2574
+ DWORD_PTR result = 0;
2575
+ SendMessageTimeoutW(target, msg, wparam, lparam, SMTO_ABORTIFHUNG, 200, &result);
2576
+ };
2577
+ auto findTarget = [&]() -> HWND {
2578
+ const bool wasVisible = IsWindowVisible(hwnd_) != FALSE;
2579
+ if (wasVisible) ShowWindow(hwnd_, SW_HIDE);
2580
+ HWND target = WindowFromPoint(screenPoint);
2581
+ if (wasVisible) ShowWindow(hwnd_, SW_SHOWNOACTIVATE);
2582
+ if (target == hwnd_ || (target != nullptr && IsChild(hwnd_, target))) return nullptr;
2583
+ return target;
2584
+ };
2585
+ auto clientLParam = [&](HWND target) -> LPARAM {
2586
+ POINT clientPoint = screenPoint;
2587
+ ScreenToClient(target, &clientPoint);
2588
+ return MAKELPARAM(static_cast<short>(clientPoint.x), static_cast<short>(clientPoint.y));
2589
+ };
2590
+ switch (message) {
2591
+ case WM_LBUTTONDOWN:
2592
+ forwardedTarget_ = findTarget();
2593
+ if (forwardedTarget_ == nullptr) return;
2594
+ forwardedLeftDown_ = true;
2595
+ if (IsWindowVisible(hwnd_) != FALSE) ShowWindow(hwnd_, SW_HIDE);
2596
+ sendToTarget(forwardedTarget_, WM_LBUTTONDOWN, MK_LBUTTON, clientLParam(forwardedTarget_));
2597
+ return;
2598
+ case WM_MOUSEMOVE:
2599
+ if (!forwardedLeftDown_ || forwardedTarget_ == nullptr) return;
2600
+ sendToTarget(forwardedTarget_, WM_MOUSEMOVE, MK_LBUTTON, clientLParam(forwardedTarget_));
2601
+ return;
2602
+ case WM_LBUTTONUP:
2603
+ if (!forwardedLeftDown_ || forwardedTarget_ == nullptr) return;
2604
+ sendToTarget(forwardedTarget_, WM_LBUTTONUP, 0, clientLParam(forwardedTarget_));
2605
+ forwardedTarget_ = nullptr;
2606
+ forwardedLeftDown_ = false;
2607
+ if (IsWindowVisible(hwnd_) == FALSE) ShowWindow(hwnd_, SW_SHOWNOACTIVATE);
2608
+ return;
2609
+ case WM_RBUTTONDOWN:
2610
+ case WM_RBUTTONUP:
2611
+ case WM_MBUTTONDOWN:
2612
+ case WM_MBUTTONUP:
2613
+ case WM_MOUSEWHEEL:
2614
+ case WM_MOUSEHWHEEL: {
2615
+ HWND target = findTarget();
2616
+ if (target == nullptr) return;
2617
+ const LPARAM clientPos = clientLParam(target);
2618
+ WPARAM wparam = 0;
2619
+ if (message == WM_MOUSEWHEEL || message == WM_MOUSEHWHEEL) {
2620
+ wparam = static_cast<WPARAM>(static_cast<short>(HIWORD(info->mouseData)));
2621
+ sendToTarget(target, message, wparam, MAKELPARAM(screenPoint.x, screenPoint.y));
2622
+ return;
2623
+ }
2624
+ if (message == WM_RBUTTONDOWN) wparam = MK_RBUTTON;
2625
+ if (message == WM_MBUTTONDOWN) wparam = MK_MBUTTON;
2626
+ sendToTarget(target, message, wparam, clientPos);
2627
+ return;
2628
+ }
2629
+ default:
2630
+ return;
2631
+ }
2632
+ }
2633
+
2634
+ LRESULT CALLBACK FloatApp::LowLevelMouseProc(int code, WPARAM wparam, LPARAM lparam) {
2635
+ if (code < 0) return CallNextHookEx(nullptr, code, wparam, lparam);
2636
+ FloatApp* app = g_activeFloatApp;
2637
+ if (app == nullptr || app->hwnd_ == nullptr || !app->clickThrough_) return CallNextHookEx(nullptr, code, wparam, lparam);
2638
+ const MSLLHOOKSTRUCT* info = reinterpret_cast<const MSLLHOOKSTRUCT*>(lparam);
2639
+ if (info == nullptr) return CallNextHookEx(nullptr, code, wparam, lparam);
2640
+ /* 只拦截落在悬浮层范围内的鼠标 */
2641
+ RECT rect = {};
2642
+ if (!GetWindowRect(app->hwnd_, &rect)) return CallNextHookEx(nullptr, code, wparam, lparam);
2643
+ if (info->pt.x < rect.left || info->pt.x >= rect.right || info->pt.y < rect.top || info->pt.y >= rect.bottom) {
2644
+ return CallNextHookEx(nullptr, code, wparam, lparam);
2645
+ }
2646
+ switch (wparam) {
2647
+ case WM_LBUTTONDOWN:
2648
+ case WM_LBUTTONUP:
2649
+ case WM_MOUSEMOVE:
2650
+ case WM_RBUTTONDOWN:
2651
+ case WM_RBUTTONUP:
2652
+ case WM_MBUTTONDOWN:
2653
+ case WM_MBUTTONUP:
2654
+ case WM_MOUSEWHEEL:
2655
+ case WM_MOUSEHWHEEL:
2656
+ app->ForwardMouseToUnderlying(static_cast<UINT>(wparam), info);
2657
+ return 1;
2658
+ default:
2659
+ return CallNextHookEx(nullptr, code, wparam, lparam);
2660
+ }
2563
2661
  }
2564
2662
 
2565
2663
  void FloatApp::StopFollowing() {
@@ -2578,6 +2676,11 @@ void FloatApp::DoGracefulExit() {
2578
2676
  return;
2579
2677
  }
2580
2678
  Log(L"graceful-exit-start");
2679
+ if (mouseHookInstalled_) {
2680
+ if (mouseHook_ != nullptr) UnhookWindowsHookEx(mouseHook_);
2681
+ mouseHook_ = nullptr;
2682
+ mouseHookInstalled_ = false;
2683
+ }
2581
2684
  if (clickThroughHotkey_ && hwnd_ != nullptr) {
2582
2685
  UnregisterHotKey(hwnd_, kHotkeyClickThrough);
2583
2686
  clickThroughHotkey_ = false;
@@ -2598,6 +2701,11 @@ void FloatApp::DoGracefulExit() {
2598
2701
  }
2599
2702
 
2600
2703
  void FloatApp::OnWindowDestroyed() {
2704
+ if (mouseHookInstalled_) {
2705
+ if (mouseHook_ != nullptr) UnhookWindowsHookEx(mouseHook_);
2706
+ mouseHook_ = nullptr;
2707
+ mouseHookInstalled_ = false;
2708
+ }
2601
2709
  if (clickThroughHotkey_ && hwnd_ != nullptr) {
2602
2710
  UnregisterHotKey(hwnd_, kHotkeyClickThrough);
2603
2711
  clickThroughHotkey_ = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.198",
3
+ "version": "1.3.199",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [