dsh-gufa-code 1.3.52 → 1.3.54
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/README.md +3 -2
- package/client.js +1 -1
- package/desktop/float/bin/gufa-float-macos-arm64 +0 -0
- package/desktop/float/bin/gufa-float-macos-universal +0 -0
- package/desktop/float/bin/gufa-float-macos-x64 +0 -0
- package/desktop/float/bin/linux-x64/gufa-float-linux +0 -0
- package/desktop/float/bin/win-x64/gufa-float-win.exe +0 -0
- package/desktop/float/linux/README-LINUX.md +12 -1
- package/desktop/float/linux/x11.c +336 -40
- package/desktop/float/linux/x11.h +4 -0
- package/desktop/float/win/CMakeLists.txt +1 -0
- package/desktop/float/win/README-WIN.md +13 -17
- package/desktop/float/win/main.cpp +582 -49
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/Info.plist +2 -2
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/MacOS/gufa-float +0 -0
- package/docs/FLOAT-ACCEPTANCE.md +16 -2
- package/host/dev.js +8 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,8 +89,9 @@ dsh plugin add dsh-gufa-code
|
|
|
89
89
|
- **macOS Apple Silicon / Intel:开箱可用**(npm 包内是 universal helper,arm64 + x86_64,无需自己编译);
|
|
90
90
|
- **Windows:可用(实验)**:npm 包内含 `desktop/float/bin/win-x64/gufa-float-win.exe`(CI 构建的 Win32 + WebView2 helper)。
|
|
91
91
|
前置条件:Windows 10/11 + **WebView2 Runtime**(Win10/11 的 Edge 通常已自带;缺失时 helper 会提示下载)。
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
**透明悬浮窗**已实现(DirectComposition + WebView2 CompositionController;系统不支持时自动回退不透明窗口并写日志);
|
|
93
|
+
composition 模式下顶部 22px 拖动条由网页层承担(按住可拖动、右键有退出/重置菜单),键盘输入依赖 WebView2 焦点(真机验收项);
|
|
94
|
+
暂有限制:虚拟桌面切换时悬浮窗可能留在原桌面;exe 未代码签名,首次运行可能被 SmartScreen 拦截(「更多信息 → 仍要运行」);
|
|
94
95
|
- **Linux:可用(实验,仅 X11)**:npm 包内含 `desktop/float/bin/linux-x64/gufa-float-linux`(CI 构建的 X11 + GTK3/WebKit2GTK helper)。
|
|
95
96
|
前置条件:X11 桌面 + GTK3/WebKit2GTK 运行库(`libgtk-3-0`、`libwebkit2gtk-4.1-0` 或 `4.0`、`libsoup-3.0-0` 或 `2.4`)。
|
|
96
97
|
暂有限制:**纯 Wayland 下不能跟随/隐藏其它窗口**(有 XWayland 时自动退到 X11 后端,可用;完全 Wayland 时只能自由悬浮);
|
package/client.js
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -113,8 +113,19 @@ WEBKIT_DISABLE_COMPOSITING_MODE=1 WEBKIT_DISABLE_DMABUF_RENDERER=1 LIBGL_ALWAYS_
|
|
|
113
113
|
- [x] 用目标的 `_NET_WM_DESKTOP` 同步自己窗口的工作区(best-effort)。
|
|
114
114
|
|
|
115
115
|
### 2.3 隐藏/恢复 DSH 主窗口(X11)
|
|
116
|
-
- [x] 隐藏:优先 `_NET_WM_PID == ownerPid`(Host payload 已带 `ownerPid`);对不上时按标题/WM_CLASS
|
|
116
|
+
- [x] 隐藏:优先 `_NET_WM_PID == ownerPid`(Host payload 已带 `ownerPid`);对不上时按标题/WM_CLASS/进程名启发式
|
|
117
117
|
(`deepseek harness` / `deepseek` 等)兜底;命中窗口 `XUnmapWindow`,最多 16 个。
|
|
118
|
+
- [x] 候选枚举 = **窗口树递归(root→frame→client,深度 ≤4,`_NET_WM_PID` 缺失时用 `WM_STATE` 识别 client)**
|
|
119
|
+
∪ **`_NET_CLIENT_LIST` / `_NET_CLIENT_LIST_STACKING`**(EWMH 权威清单),两者按窗口 ID 去重;
|
|
120
|
+
openbox/mutter 等 reparenting WM 下实测可拿到 xterm/Electron client。
|
|
121
|
+
- [x] 标题读取不再依赖 `XFetchName`(只认 STRING):`_NET_WM_NAME` / `WM_NAME` 按**原始字节**读(兼容
|
|
122
|
+
UTF8_STRING / STRING / COMPOUND_TEXT),`_NET_WM_PID` 缺失、窗口尺寸偏小、类型未声明时不误杀。
|
|
123
|
+
- [x] 标题被应用/Shell 覆盖时的兜底(CI 的 xterm 会被 bash prompt 的标题转义覆盖成
|
|
124
|
+
`runner@host: ~/work/...`,`-T "DeepSeek Harness"` 不再出现在窗口标题里):
|
|
125
|
+
匹配来源还包括 **`/proc/<pid>/cmdline`**(xterm 命令行保留 `-T "DeepSeek Harness"`)和
|
|
126
|
+
**Openbox 的 `_OB_APP_TITLE`**(WM 保存的原始标题);日志里会打出 `ob_app_title=` / `cmdline=`。
|
|
127
|
+
- [x] 每次隐藏都会把候选窗口写进日志:`win/pid/title/wm_class/comm/ob_app_title/cmdline/size/viewable/type_ok/wm_state`;
|
|
128
|
+
一个候选都没匹配时额外把整棵窗口树(含 frame/decor)dump 到日志,便于 CI/真机一次定位。
|
|
118
129
|
- [x] 恢复:退出前 `XMapWindow` + `XRaiseWindow` + `_NET_ACTIVE_WINDOW`(带 GDK server timestamp 提高 WM 接受率),
|
|
119
130
|
再 `XSync` 确保请求已处理;controlPath 退出、SIGTERM/SIGINT、菜单退出、窗口关闭都会走同一恢复路径。
|
|
120
131
|
- [x] 非 X11(Wayland 后端)时明确跳过并写日志,不会误操作其它窗口。
|
|
@@ -69,6 +69,50 @@ static gboolean gufa_x11_get_property(GufaX11 *x11, Window window, Atom atom, At
|
|
|
69
69
|
return TRUE;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/** 读任意类型、format 8 的属性原始字节。
|
|
73
|
+
* 标题属性(_NET_WM_NAME / WM_NAME)的 type 可能是 UTF8_STRING / STRING / COMPOUND_TEXT,
|
|
74
|
+
* 对 ASCII 标题这些编码的字节兼容,直接按字节返回,避免 XFetchName 只认 STRING 的局限。 */
|
|
75
|
+
static char *gufa_x11_get_property_text(GufaX11 *x11, Window window, Atom atom) {
|
|
76
|
+
unsigned char *data = NULL;
|
|
77
|
+
Atom type = None;
|
|
78
|
+
int format = 0;
|
|
79
|
+
unsigned long nitems = 0;
|
|
80
|
+
if (!gufa_x11_get_property(x11, window, atom, AnyPropertyType, &data, &type, &format, &nitems)) {
|
|
81
|
+
return NULL;
|
|
82
|
+
}
|
|
83
|
+
char *text = NULL;
|
|
84
|
+
if (format == 8 && nitems > 0 && data != NULL) {
|
|
85
|
+
text = g_strndup((const char *)data, (gsize)nitems);
|
|
86
|
+
}
|
|
87
|
+
XFree(data);
|
|
88
|
+
return text;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** 窗口是否被 WM 管理(有 WM_STATE 属性)。reparenting WM 的 frame/decor 窗口没有该属性,
|
|
92
|
+
* client 窗口有;用于在 _NET_WM_PID 缺失时仍然识别真正的应用窗口。 */
|
|
93
|
+
static gboolean gufa_x11_window_has_wm_state(GufaX11 *x11, Window window) {
|
|
94
|
+
unsigned char *data = NULL;
|
|
95
|
+
Atom type = None;
|
|
96
|
+
int format = 0;
|
|
97
|
+
unsigned long nitems = 0;
|
|
98
|
+
if (!gufa_x11_get_property(x11, window, x11->atom_wm_state, AnyPropertyType,
|
|
99
|
+
&data, &type, &format, &nitems)) {
|
|
100
|
+
return FALSE;
|
|
101
|
+
}
|
|
102
|
+
XFree(data);
|
|
103
|
+
return TRUE;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** 把日志里的窗口标题 sanitize 成单行。 */
|
|
107
|
+
static char *gufa_x11_log_text(const char *text) {
|
|
108
|
+
if (text == NULL) return g_strdup("(null)");
|
|
109
|
+
char *copy = g_strdup(text);
|
|
110
|
+
for (char *p = copy; *p != '\0'; p++) {
|
|
111
|
+
if ((unsigned char)*p < 0x20) *p = '?';
|
|
112
|
+
}
|
|
113
|
+
return copy;
|
|
114
|
+
}
|
|
115
|
+
|
|
72
116
|
long gufa_x11_window_pid(GufaX11 *x11, Window window) {
|
|
73
117
|
unsigned char *data = NULL;
|
|
74
118
|
Atom type = None;
|
|
@@ -86,19 +130,15 @@ long gufa_x11_window_pid(GufaX11 *x11, Window window) {
|
|
|
86
130
|
}
|
|
87
131
|
|
|
88
132
|
char *gufa_x11_window_title(GufaX11 *x11, Window window) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
XFree(data);
|
|
100
|
-
if (title != NULL) return title;
|
|
101
|
-
}
|
|
133
|
+
/* EWMH 标题优先(规范要求 UTF-8,但类型可能被写成 STRING,按原始字节读更稳) */
|
|
134
|
+
char *title = gufa_x11_get_property_text(x11, window, x11->atom_net_wm_name);
|
|
135
|
+
if (title != NULL && *title != '\0') return title;
|
|
136
|
+
g_free(title);
|
|
137
|
+
/* ICCCM WM_NAME:type 可能是 STRING / COMPOUND_TEXT / UTF8_STRING,按原始字节读 */
|
|
138
|
+
title = gufa_x11_get_property_text(x11, window, x11->atom_wm_name);
|
|
139
|
+
if (title != NULL && *title != '\0') return title;
|
|
140
|
+
g_free(title);
|
|
141
|
+
/* 最后的 encoding 感知回退(STRING) */
|
|
102
142
|
char *wm_name = NULL;
|
|
103
143
|
if (x11->dpy != NULL && XFetchName(x11->dpy, window, &wm_name) != 0 && wm_name != NULL) {
|
|
104
144
|
char *copy = g_strdup(wm_name);
|
|
@@ -166,6 +206,38 @@ static gboolean gufa_x11_window_type_followable(GufaX11 *x11, Window window) {
|
|
|
166
206
|
return followable;
|
|
167
207
|
}
|
|
168
208
|
|
|
209
|
+
/** 隐藏场景的类型过滤:只排除明确不是普通应用窗口的类型;未知/空类型/NORMAL/DIALOG/UTILITY 都允许,
|
|
210
|
+
* 避免 xterm 之类不声明类型的窗口被误杀。 */
|
|
211
|
+
static gboolean gufa_x11_window_type_hideable(GufaX11 *x11, Window window) {
|
|
212
|
+
unsigned char *data = NULL;
|
|
213
|
+
Atom type = None;
|
|
214
|
+
int format = 0;
|
|
215
|
+
unsigned long nitems = 0;
|
|
216
|
+
if (!gufa_x11_get_property(x11, window, x11->atom_net_wm_window_type, XA_ATOM,
|
|
217
|
+
&data, &type, &format, &nitems)) {
|
|
218
|
+
return TRUE;
|
|
219
|
+
}
|
|
220
|
+
gboolean hideable = TRUE;
|
|
221
|
+
if (format == 32 && data != NULL) {
|
|
222
|
+
long *atoms = (long *)(void *)data;
|
|
223
|
+
for (unsigned long i = 0; i < nitems; i++) {
|
|
224
|
+
Atom value = (Atom)atoms[i];
|
|
225
|
+
if (value == x11->atom_net_wm_window_type_desktop ||
|
|
226
|
+
value == x11->atom_net_wm_window_type_dock ||
|
|
227
|
+
value == x11->atom_net_wm_window_type_toolbar ||
|
|
228
|
+
value == x11->atom_net_wm_window_type_menu ||
|
|
229
|
+
value == x11->atom_net_wm_window_type_dropdown ||
|
|
230
|
+
value == x11->atom_net_wm_window_type_tooltip ||
|
|
231
|
+
value == x11->atom_net_wm_window_type_splash) {
|
|
232
|
+
hideable = FALSE;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
XFree(data);
|
|
238
|
+
return hideable;
|
|
239
|
+
}
|
|
240
|
+
|
|
169
241
|
static void gufa_x11_collect_children(GufaX11 *x11, Window parent, int depth, Window skip,
|
|
170
242
|
gboolean include_unmapped, GArray *out) {
|
|
171
243
|
Window root_return = 0;
|
|
@@ -183,9 +255,15 @@ static void gufa_x11_collect_children(GufaX11 *x11, Window parent, int depth, Wi
|
|
|
183
255
|
if (attributes.override_redirect) continue;
|
|
184
256
|
if (attributes.class != InputOutput) continue;
|
|
185
257
|
long pid = gufa_x11_window_pid(x11, window);
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
258
|
+
gboolean usable = attributes.width >= 40 && attributes.height >= 40 &&
|
|
259
|
+
(include_unmapped || attributes.map_state == IsViewable);
|
|
260
|
+
gboolean is_managed = FALSE;
|
|
261
|
+
if (pid <= 0 && usable) {
|
|
262
|
+
/* _NET_WM_PID 缺失时,用 WM_STATE 识别真正的 client 窗口(reparenting WM 的 frame 没有) */
|
|
263
|
+
is_managed = gufa_x11_window_has_wm_state(x11, window);
|
|
264
|
+
}
|
|
265
|
+
if (pid > 0 || is_managed) {
|
|
266
|
+
if (!usable) continue;
|
|
189
267
|
int root_x = 0;
|
|
190
268
|
int root_y = 0;
|
|
191
269
|
Window child_return = 0;
|
|
@@ -202,19 +280,82 @@ static void gufa_x11_collect_children(GufaX11 *x11, Window parent, int depth, Wi
|
|
|
202
280
|
info.height = attributes.height;
|
|
203
281
|
info.viewable = attributes.map_state == IsViewable;
|
|
204
282
|
g_array_append_val(out, info);
|
|
205
|
-
}
|
|
206
|
-
|
|
283
|
+
}
|
|
284
|
+
if (pid <= 0 && depth < 4) {
|
|
285
|
+
/* 有 WM 时 root 的子窗口是 frame/decor,真正的 client 在更深层;深度放宽到 4 层 */
|
|
207
286
|
gufa_x11_collect_children(x11, window, depth + 1, skip, include_unmapped, out);
|
|
208
287
|
}
|
|
209
288
|
}
|
|
210
289
|
if (children != NULL) XFree(children);
|
|
211
290
|
}
|
|
212
291
|
|
|
213
|
-
/**
|
|
292
|
+
/** 用 EWMH 的 _NET_CLIENT_LIST / _NET_CLIENT_LIST_STACKING 补齐候选:比窗口树更权威,
|
|
293
|
+
* 即使树层级/深度/pid 有任何意外也能拿到 WM 管理的 client 窗口。 */
|
|
294
|
+
static void gufa_x11_collect_client_list(GufaX11 *x11, Window skip, gboolean include_unmapped,
|
|
295
|
+
GArray *out) {
|
|
296
|
+
Atom atoms[2];
|
|
297
|
+
atoms[0] = x11->atom_net_client_list;
|
|
298
|
+
atoms[1] = x11->atom_net_client_list_stacking;
|
|
299
|
+
GHashTable *seen = g_hash_table_new(g_direct_hash, g_direct_equal);
|
|
300
|
+
for (guint i = 0; i < out->len; i++) {
|
|
301
|
+
GufaX11WindowInfo *info = &g_array_index(out, GufaX11WindowInfo, i);
|
|
302
|
+
g_hash_table_add(seen, (gpointer)(guintptr)info->win);
|
|
303
|
+
}
|
|
304
|
+
for (int a = 0; a < 2; a++) {
|
|
305
|
+
unsigned char *data = NULL;
|
|
306
|
+
Atom type = None;
|
|
307
|
+
int format = 0;
|
|
308
|
+
unsigned long nitems = 0;
|
|
309
|
+
if (!gufa_x11_get_property(x11, x11->root, atoms[a], AnyPropertyType,
|
|
310
|
+
&data, &type, &format, &nitems)) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (format != 32 || data == NULL) {
|
|
314
|
+
XFree(data);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
Window *windows = (Window *)(void *)data;
|
|
318
|
+
if (nitems > 512) nitems = 512;
|
|
319
|
+
for (unsigned long i = 0; i < nitems; i++) {
|
|
320
|
+
Window window = windows[i];
|
|
321
|
+
if (window == 0 || window == skip) continue;
|
|
322
|
+
if (g_hash_table_contains(seen, (gpointer)(guintptr)window)) continue;
|
|
323
|
+
XWindowAttributes attributes;
|
|
324
|
+
memset(&attributes, 0, sizeof(attributes));
|
|
325
|
+
if (XGetWindowAttributes(x11->dpy, window, &attributes) == 0) continue;
|
|
326
|
+
if (attributes.override_redirect) continue;
|
|
327
|
+
if (attributes.width < 40 || attributes.height < 40) continue;
|
|
328
|
+
if (!include_unmapped && attributes.map_state != IsViewable) continue;
|
|
329
|
+
int root_x = 0;
|
|
330
|
+
int root_y = 0;
|
|
331
|
+
Window child_return = 0;
|
|
332
|
+
if (XTranslateCoordinates(x11->dpy, window, x11->root, 0, 0, &root_x, &root_y, &child_return) == 0) {
|
|
333
|
+
root_x = 0;
|
|
334
|
+
root_y = 0;
|
|
335
|
+
}
|
|
336
|
+
GufaX11WindowInfo info;
|
|
337
|
+
info.win = window;
|
|
338
|
+
info.pid = gufa_x11_window_pid(x11, window);
|
|
339
|
+
info.x = root_x;
|
|
340
|
+
info.y = root_y;
|
|
341
|
+
info.width = attributes.width;
|
|
342
|
+
info.height = attributes.height;
|
|
343
|
+
info.viewable = attributes.map_state == IsViewable;
|
|
344
|
+
g_array_append_val(out, info);
|
|
345
|
+
g_hash_table_add(seen, (gpointer)(guintptr)window);
|
|
346
|
+
}
|
|
347
|
+
XFree(data);
|
|
348
|
+
}
|
|
349
|
+
g_hash_table_destroy(seen);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** 枚举「WM 管理的顶层 client 窗口」:窗口树递归 + EWMH client list 并集;
|
|
353
|
+
* include_unmapped 时也收其它工作区/最小化的窗口。 */
|
|
214
354
|
static GArray *gufa_x11_enumerate(GufaX11 *x11, Window skip, gboolean include_unmapped) {
|
|
215
355
|
GArray *out = g_array_new(FALSE, FALSE, sizeof(GufaX11WindowInfo));
|
|
216
356
|
if (x11 == NULL || !x11->ok) return out;
|
|
217
357
|
gufa_x11_collect_children(x11, x11->root, 0, skip, include_unmapped, out);
|
|
358
|
+
gufa_x11_collect_client_list(x11, skip, include_unmapped, out);
|
|
218
359
|
return out;
|
|
219
360
|
}
|
|
220
361
|
|
|
@@ -243,6 +384,8 @@ static gboolean gufa_text_contains_ci(const char *haystack, const char *needle)
|
|
|
243
384
|
}
|
|
244
385
|
|
|
245
386
|
static char *gufa_x11_process_comm(long pid);
|
|
387
|
+
static char *gufa_x11_process_cmdline(long pid);
|
|
388
|
+
static char *gufa_x11_window_original_title(GufaX11 *x11, Window window);
|
|
246
389
|
|
|
247
390
|
/* ── 对外接口 ───────────────────────────────────────────────────────── */
|
|
248
391
|
|
|
@@ -266,9 +409,13 @@ gboolean gufa_x11_open(GufaX11 *x11) {
|
|
|
266
409
|
#define GUFA_ATOM(field, name) (x11->field = XInternAtom(x11->dpy, (name), False))
|
|
267
410
|
GUFA_ATOM(atom_net_wm_pid, "_NET_WM_PID");
|
|
268
411
|
GUFA_ATOM(atom_net_wm_name, "_NET_WM_NAME");
|
|
412
|
+
GUFA_ATOM(atom_wm_name, "WM_NAME");
|
|
413
|
+
GUFA_ATOM(atom_wm_state, "WM_STATE");
|
|
414
|
+
GUFA_ATOM(atom_ob_app_title, "_OB_APP_TITLE");
|
|
269
415
|
GUFA_ATOM(atom_utf8_string, "UTF8_STRING");
|
|
270
416
|
GUFA_ATOM(atom_net_active_window, "_NET_ACTIVE_WINDOW");
|
|
271
417
|
GUFA_ATOM(atom_net_client_list, "_NET_CLIENT_LIST");
|
|
418
|
+
GUFA_ATOM(atom_net_client_list_stacking, "_NET_CLIENT_LIST_STACKING");
|
|
272
419
|
GUFA_ATOM(atom_net_wm_window_type, "_NET_WM_WINDOW_TYPE");
|
|
273
420
|
GUFA_ATOM(atom_net_wm_window_type_normal, "_NET_WM_WINDOW_TYPE_NORMAL");
|
|
274
421
|
GUFA_ATOM(atom_net_wm_window_type_dialog, "_NET_WM_WINDOW_TYPE_DIALOG");
|
|
@@ -448,73 +595,197 @@ void gufa_x11_copy_desktop(GufaX11 *x11, Window target, Window own) {
|
|
|
448
595
|
(unsigned long)target, (unsigned long)own);
|
|
449
596
|
}
|
|
450
597
|
|
|
451
|
-
|
|
598
|
+
/** 无匹配时把窗口树(含 frame/decor)打进日志,便于 CI/真机一次定位。 */
|
|
599
|
+
static void gufa_x11_debug_dump_tree(GufaX11 *x11, Window window, int depth, int *budget) {
|
|
600
|
+
if (window == 0 || depth > 3 || *budget <= 0) return;
|
|
601
|
+
XWindowAttributes attributes;
|
|
602
|
+
memset(&attributes, 0, sizeof(attributes));
|
|
603
|
+
if (XGetWindowAttributes(x11->dpy, window, &attributes) == 0) return;
|
|
604
|
+
if (!attributes.override_redirect) {
|
|
605
|
+
(*budget)--;
|
|
606
|
+
char *title = gufa_x11_window_title(x11, window);
|
|
607
|
+
char *wm_class = gufa_x11_window_class(x11, window);
|
|
608
|
+
char *title_text = gufa_x11_log_text(title);
|
|
609
|
+
char *class_text = gufa_x11_log_text(wm_class);
|
|
610
|
+
gufa_log("x11: tree depth=%d win=0x%lx class=%d map=%d size=%dx%d pid=%ld wm_state=%d "
|
|
611
|
+
"title=\"%s\" wm_class=\"%s\"",
|
|
612
|
+
depth, (unsigned long)window, attributes.class, attributes.map_state,
|
|
613
|
+
attributes.width, attributes.height, gufa_x11_window_pid(x11, window),
|
|
614
|
+
gufa_x11_window_has_wm_state(x11, window) ? 1 : 0, title_text, class_text);
|
|
615
|
+
g_free(title_text);
|
|
616
|
+
g_free(class_text);
|
|
617
|
+
g_free(title);
|
|
618
|
+
g_free(wm_class);
|
|
619
|
+
}
|
|
620
|
+
if (depth < 3) {
|
|
621
|
+
Window root_return = 0;
|
|
622
|
+
Window parent_return = 0;
|
|
623
|
+
Window *children = NULL;
|
|
624
|
+
unsigned int child_count = 0;
|
|
625
|
+
if (XQueryTree(x11->dpy, window, &root_return, &parent_return, &children, &child_count) == 0) {
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
for (unsigned int i = 0; i < child_count && *budget > 0; i++) {
|
|
629
|
+
gufa_x11_debug_dump_tree(x11, children[i], depth + 1, budget);
|
|
630
|
+
}
|
|
631
|
+
if (children != NULL) XFree(children);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
void gufa_x11_hide_windows_like_dsh(GufaX11 *x11, long owner_pid, const char *title_hint,
|
|
636
|
+
GufaX11WindowList *hidden) {
|
|
452
637
|
gufa_x11_window_list_clear(hidden);
|
|
453
638
|
if (x11 == NULL || !x11->ok || hidden == NULL) return;
|
|
454
639
|
GArray *windows = gufa_x11_enumerate(x11, 0, FALSE);
|
|
640
|
+
gufa_log("x11: 隐藏 DSH 前枚举到 %u 个候选窗口(ownerPid=%ld,窗口树 + _NET_CLIENT_LIST)",
|
|
641
|
+
windows->len, owner_pid);
|
|
642
|
+
|
|
643
|
+
/* 逐候选诊断日志:定位“为什么没匹配” */
|
|
644
|
+
int logged = 0;
|
|
645
|
+
for (guint i = 0; i < windows->len; i++) {
|
|
646
|
+
GufaX11WindowInfo *info = &g_array_index(windows, GufaX11WindowInfo, i);
|
|
647
|
+
if (logged >= 64) {
|
|
648
|
+
gufa_log("x11: 候选过多,其余 %u 个不再逐条打印", windows->len - (guint)logged);
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
logged++;
|
|
652
|
+
char *title = gufa_x11_window_title(x11, info->win);
|
|
653
|
+
char *wm_class = gufa_x11_window_class(x11, info->win);
|
|
654
|
+
char *comm = info->pid > 0 ? gufa_x11_process_comm(info->pid) : NULL;
|
|
655
|
+
char *cmdline = info->pid > 0 ? gufa_x11_process_cmdline(info->pid) : NULL;
|
|
656
|
+
char *orig_title = gufa_x11_window_original_title(x11, info->win);
|
|
657
|
+
char *title_text = gufa_x11_log_text(title);
|
|
658
|
+
char *class_text = gufa_x11_log_text(wm_class);
|
|
659
|
+
char *comm_text = gufa_x11_log_text(comm);
|
|
660
|
+
char *orig_text = gufa_x11_log_text(orig_title);
|
|
661
|
+
char *cmdline_short = cmdline != NULL ? g_strndup(cmdline, 160) : g_strdup("(null)");
|
|
662
|
+
gufa_log("x11: 候选 win=0x%lx pid=%ld title=\"%s\" wm_class=\"%s\" comm=\"%s\" "
|
|
663
|
+
"ob_app_title=\"%s\" cmdline=\"%s\" size=%dx%d viewable=%d type_ok=%d wm_state=%d",
|
|
664
|
+
(unsigned long)info->win, info->pid, title_text, class_text, comm_text,
|
|
665
|
+
orig_text, cmdline_short, info->width, info->height, info->viewable ? 1 : 0,
|
|
666
|
+
gufa_x11_window_type_hideable(x11, info->win) ? 1 : 0,
|
|
667
|
+
gufa_x11_window_has_wm_state(x11, info->win) ? 1 : 0);
|
|
668
|
+
g_free(title);
|
|
669
|
+
g_free(wm_class);
|
|
670
|
+
g_free(comm);
|
|
671
|
+
g_free(cmdline);
|
|
672
|
+
g_free(orig_title);
|
|
673
|
+
g_free(title_text);
|
|
674
|
+
g_free(class_text);
|
|
675
|
+
g_free(comm_text);
|
|
676
|
+
g_free(orig_text);
|
|
677
|
+
g_free(cmdline_short);
|
|
678
|
+
}
|
|
679
|
+
|
|
455
680
|
GArray *matched = g_array_new(FALSE, FALSE, sizeof(Window));
|
|
456
|
-
|
|
681
|
+
|
|
682
|
+
/* 第一轮:ownerPid 精确匹配(优先级最高,行为保持不变) */
|
|
457
683
|
if (owner_pid > 0) {
|
|
458
684
|
for (guint i = 0; i < windows->len; i++) {
|
|
459
685
|
GufaX11WindowInfo *info = &g_array_index(windows, GufaX11WindowInfo, i);
|
|
460
686
|
if (info->pid != owner_pid) continue;
|
|
461
687
|
if (info->pid == x11->self_pid) continue;
|
|
462
|
-
if (info->width <
|
|
463
|
-
if (!
|
|
688
|
+
if (info->width < 50 || info->height < 50) continue;
|
|
689
|
+
if (!gufa_x11_window_type_hideable(x11, info->win)) continue;
|
|
690
|
+
gufa_log("x11: ownerPid 精确命中 win=0x%lx pid=%ld size=%dx%d",
|
|
691
|
+
(unsigned long)info->win, info->pid, info->width, info->height);
|
|
464
692
|
Window window = info->win;
|
|
465
693
|
g_array_append_val(matched, window);
|
|
466
694
|
}
|
|
695
|
+
gufa_log("x11: ownerPid 精确匹配到 %u 个窗口", matched->len);
|
|
467
696
|
}
|
|
468
|
-
|
|
697
|
+
|
|
698
|
+
/* 第二轮:标题 / WM_CLASS / 进程名启发式(ownerPid 对不上时兜底;Electron DSH 与 CI xterm 都覆盖) */
|
|
469
699
|
if (matched->len == 0) {
|
|
470
700
|
const char *needles[] = {"deepseek harness", "deepseek-harness", "deepseek"};
|
|
471
701
|
for (guint i = 0; i < windows->len; i++) {
|
|
472
702
|
GufaX11WindowInfo *info = &g_array_index(windows, GufaX11WindowInfo, i);
|
|
473
703
|
if (info->pid == x11->self_pid) continue;
|
|
474
|
-
if (info->width <
|
|
475
|
-
if (!
|
|
704
|
+
if (info->width < 16 || info->height < 16) continue;
|
|
705
|
+
if (!gufa_x11_window_type_hideable(x11, info->win)) continue;
|
|
476
706
|
char *title = gufa_x11_window_title(x11, info->win);
|
|
477
707
|
char *wm_class = gufa_x11_window_class(x11, info->win);
|
|
478
|
-
char *comm = gufa_x11_process_comm(info->pid);
|
|
708
|
+
char *comm = info->pid > 0 ? gufa_x11_process_comm(info->pid) : NULL;
|
|
709
|
+
char *cmdline = info->pid > 0 ? gufa_x11_process_cmdline(info->pid) : NULL;
|
|
710
|
+
char *orig_title = gufa_x11_window_original_title(x11, info->win);
|
|
479
711
|
gboolean matched_title = FALSE;
|
|
480
|
-
|
|
481
|
-
|
|
712
|
+
const char *why = NULL;
|
|
713
|
+
if (title_hint != NULL && *title_hint != '\0') {
|
|
714
|
+
if (gufa_text_contains_ci(title, title_hint)) {
|
|
715
|
+
matched_title = TRUE;
|
|
716
|
+
why = "title_hint";
|
|
717
|
+
} else if (gufa_text_contains_ci(orig_title, title_hint)) {
|
|
718
|
+
matched_title = TRUE;
|
|
719
|
+
why = "ob_app_title_hint";
|
|
720
|
+
} else if (gufa_text_contains_ci(cmdline, title_hint)) {
|
|
721
|
+
/* 窗口标题可能被应用/Shell 覆盖(CI 的 xterm 被 bash prompt 覆盖),
|
|
722
|
+
但进程命令行里仍带着原始标题(如 `xterm -T "DeepSeek Harness"`) */
|
|
723
|
+
matched_title = TRUE;
|
|
724
|
+
why = "cmdline_hint";
|
|
725
|
+
}
|
|
482
726
|
}
|
|
483
727
|
for (gsize n = 0; n < G_N_ELEMENTS(needles) && !matched_title; n++) {
|
|
484
|
-
if (gufa_text_contains_ci(title, needles[n])
|
|
485
|
-
|
|
728
|
+
if (gufa_text_contains_ci(title, needles[n])) {
|
|
729
|
+
matched_title = TRUE;
|
|
730
|
+
why = "title";
|
|
731
|
+
} else if (gufa_text_contains_ci(orig_title, needles[n])) {
|
|
732
|
+
matched_title = TRUE;
|
|
733
|
+
why = "ob_app_title";
|
|
734
|
+
} else if (gufa_text_contains_ci(cmdline, needles[n])) {
|
|
486
735
|
matched_title = TRUE;
|
|
736
|
+
why = "cmdline";
|
|
737
|
+
} else if (gufa_text_contains_ci(wm_class, needles[n])) {
|
|
738
|
+
matched_title = TRUE;
|
|
739
|
+
why = "wm_class";
|
|
740
|
+
} else if (gufa_text_contains_ci(comm, needles[n])) {
|
|
741
|
+
matched_title = TRUE;
|
|
742
|
+
why = "process";
|
|
487
743
|
}
|
|
488
744
|
}
|
|
489
745
|
if (matched_title) {
|
|
490
746
|
if (matched->len >= 16) {
|
|
747
|
+
gufa_log("x11: 启发式命中窗口超过 16 个,已截断");
|
|
491
748
|
g_free(title);
|
|
492
749
|
g_free(wm_class);
|
|
493
750
|
g_free(comm);
|
|
751
|
+
g_free(cmdline);
|
|
752
|
+
g_free(orig_title);
|
|
494
753
|
break;
|
|
495
754
|
}
|
|
755
|
+
char *title_text = gufa_x11_log_text(title);
|
|
756
|
+
char *orig_text = gufa_x11_log_text(orig_title);
|
|
757
|
+
gufa_log("x11: 标题启发式命中 win=0x%lx pid=%ld by=%s title=\"%s\" ob_app_title=\"%s\" size=%dx%d",
|
|
758
|
+
(unsigned long)info->win, info->pid, why != NULL ? why : "?",
|
|
759
|
+
title_text, orig_text, info->width, info->height);
|
|
760
|
+
g_free(title_text);
|
|
761
|
+
g_free(orig_text);
|
|
496
762
|
Window window = info->win;
|
|
497
763
|
g_array_append_val(matched, window);
|
|
498
764
|
}
|
|
499
765
|
g_free(title);
|
|
500
766
|
g_free(wm_class);
|
|
501
767
|
g_free(comm);
|
|
768
|
+
g_free(cmdline);
|
|
769
|
+
g_free(orig_title);
|
|
502
770
|
}
|
|
771
|
+
gufa_log("x11: 标题启发式匹配到 %u 个窗口", matched->len);
|
|
503
772
|
}
|
|
504
|
-
|
|
505
|
-
if (matched->len > 16) g_array_set_size(matched, 16);
|
|
506
|
-
for (guint i = 0; i < matched->len; i++) {
|
|
507
|
-
Window window = g_array_index(matched, Window, i);
|
|
508
|
-
XUnmapWindow(x11->dpy, window);
|
|
509
|
-
gufa_x11_window_list_add(hidden, window);
|
|
510
|
-
gufa_log("x11: 隐藏 DSH 主窗口 0x%lx", (unsigned long)window);
|
|
511
|
-
}
|
|
773
|
+
|
|
512
774
|
if (matched->len == 0) {
|
|
513
|
-
gufa_log("x11: 没找到 DSH 主窗口(ownerPid=%ld
|
|
775
|
+
gufa_log("x11: 没找到 DSH 主窗口(ownerPid=%ld),跳过隐藏;dump 窗口树如下", owner_pid);
|
|
776
|
+
int budget = 120;
|
|
777
|
+
gufa_x11_debug_dump_tree(x11, x11->root, 0, &budget);
|
|
514
778
|
} else {
|
|
779
|
+
for (guint i = 0; i < matched->len; i++) {
|
|
780
|
+
Window window = g_array_index(matched, Window, i);
|
|
781
|
+
XUnmapWindow(x11->dpy, window);
|
|
782
|
+
gufa_x11_window_list_add(hidden, window);
|
|
783
|
+
gufa_log("x11: 隐藏 DSH 主窗口 0x%lx", (unsigned long)window);
|
|
784
|
+
}
|
|
515
785
|
gufa_log("x11: 已隐藏 DSH 主窗口 %u 个", hidden->n);
|
|
516
786
|
}
|
|
517
787
|
XSync(x11->dpy, False);
|
|
788
|
+
g_array_free(windows, TRUE);
|
|
518
789
|
g_array_free(matched, TRUE);
|
|
519
790
|
}
|
|
520
791
|
|
|
@@ -549,6 +820,31 @@ static char *gufa_x11_process_comm(long pid) {
|
|
|
549
820
|
return contents;
|
|
550
821
|
}
|
|
551
822
|
|
|
823
|
+
/** 读 /proc/<pid>/cmdline(NUL 分隔转空格)。CI 的 xterm 标题会被 shell prompt 覆盖,
|
|
824
|
+
* 但进程命令行里仍保留 `-T "DeepSeek Harness"`,可作为窗口身份匹配的兜底信号。 */
|
|
825
|
+
static char *gufa_x11_process_cmdline(long pid) {
|
|
826
|
+
if (pid <= 0) return NULL;
|
|
827
|
+
char path[64];
|
|
828
|
+
snprintf(path, sizeof(path), "/proc/%ld/cmdline", pid);
|
|
829
|
+
char *contents = NULL;
|
|
830
|
+
gsize length = 0;
|
|
831
|
+
if (!g_file_get_contents(path, &contents, &length, NULL) || contents == NULL) return NULL;
|
|
832
|
+
for (gsize i = 0; i < length; i++) {
|
|
833
|
+
if (contents[i] == '\0') contents[i] = ' ';
|
|
834
|
+
}
|
|
835
|
+
g_strchomp(contents);
|
|
836
|
+
return contents;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/** 部分 WM(Openbox)会把“窗口映射时的原始标题”存到 client 的 _OB_APP_TITLE,
|
|
840
|
+
* 应用后来改标题也能读回,作为标题匹配的补充来源。 */
|
|
841
|
+
static char *gufa_x11_window_original_title(GufaX11 *x11, Window window) {
|
|
842
|
+
char *title = gufa_x11_get_property_text(x11, window, x11->atom_ob_app_title);
|
|
843
|
+
if (title != NULL && *title != '\0') return title;
|
|
844
|
+
g_free(title);
|
|
845
|
+
return NULL;
|
|
846
|
+
}
|
|
847
|
+
|
|
552
848
|
static void gufa_x11_app_destroy(gpointer data) {
|
|
553
849
|
GufaX11App *app = (GufaX11App *)data;
|
|
554
850
|
if (app == NULL) return;
|
|
@@ -45,9 +45,13 @@ typedef struct {
|
|
|
45
45
|
long self_pid;
|
|
46
46
|
Atom atom_net_wm_pid;
|
|
47
47
|
Atom atom_net_wm_name;
|
|
48
|
+
Atom atom_wm_name;
|
|
49
|
+
Atom atom_wm_state;
|
|
50
|
+
Atom atom_ob_app_title;
|
|
48
51
|
Atom atom_utf8_string;
|
|
49
52
|
Atom atom_net_active_window;
|
|
50
53
|
Atom atom_net_client_list;
|
|
54
|
+
Atom atom_net_client_list_stacking;
|
|
51
55
|
Atom atom_net_wm_window_type;
|
|
52
56
|
Atom atom_net_wm_window_type_normal;
|
|
53
57
|
Atom atom_net_wm_window_type_dialog;
|
|
@@ -134,26 +134,22 @@ CI 传入:`{"appUrl":"http://127.0.0.1:1/","authUrl":"http://127.0.0.1:1/","ci
|
|
|
134
134
|
首次创建失败会自动用 `%LOCALAPPDATA%\gufa-float\webview2-retry-<pid>-<tick>` 再试一次。
|
|
135
135
|
- 自由悬浮窗口位置:`%LOCALAPPDATA%\gufa-float\frame.ini`。
|
|
136
136
|
|
|
137
|
-
## 已知限制 / TODO
|
|
138
|
-
|
|
139
|
-
1.
|
|
140
|
-
|
|
141
|
-
`
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
`WM_DPICHANGED` 时更新 DComp visual 的 offset/clip;
|
|
149
|
-
- 页面 CSS(`html[data-gufa-float]` 已把背景改成 rgba)即可透出下层 App。
|
|
150
|
-
另一条低风险折中路线:`WS_EX_LAYERED + SetLayeredWindowAttributes(LWA_ALPHA)`(窗口整体 alpha,
|
|
151
|
-
与网页 CSS 叠加,观感一般,且 WebView2 下稳定性待真机验证),未采用。
|
|
137
|
+
## 已知限制 / TODO
|
|
138
|
+
|
|
139
|
+
1. **透明窗口:已实现(DirectComposition),失败自动回退不透明**。
|
|
140
|
+
用 `WS_EX_NOREDIRECTIONBITMAP` 窗口 + `DCompositionCreateDevice2(nullptr)`(默认渲染设备,无需 d3d11)
|
|
141
|
+
+ `IDCompositionTarget/Visual` + `ICoreWebView2Environment3::CreateCoreWebView2CompositionController`
|
|
142
|
+
+ `ICoreWebView2Controller2::put_DefaultBackgroundColor({A:0})`,页面 CSS rgba 背景即可透出下层 App;
|
|
143
|
+
鼠标输入手动转发(`SendMouseInput`、capture/leave/cursor),键盘由 WebView2 焦点处理(窗口激活时 `MoveFocus`)。
|
|
144
|
+
dcomp/目标/visual/Environment3/CompositionController/put_RootVisualTarget/12s 看门狗任一步失败 →
|
|
145
|
+
按原 rect 重建 windowed 窗口继续(日志 `transparent-mode=fallback reason=...`)。
|
|
146
|
+
`payload.opaque=true` 可强制 windowed 调试。CI 已断言 `transparent-mode=composition` + `WS_EX_NOREDIRECTIONBITMAP`。
|
|
147
|
+
真机还需确认:视觉透明观感、键盘输入、较高缩放比下 follow 与输入命中。
|
|
152
148
|
2. **Windows 虚拟桌面**:没有稳定公开 API,切换虚拟桌面时悬浮窗可能留在原桌面;
|
|
153
149
|
只保证「当前桌面可用」(协议 §2.7 要求写明的平台限制)。
|
|
154
150
|
3. **窗口无系统阴影/圆角**(`WM_NCCALCSIZE` 去掉了非客户区);不影响功能,后续可用 DWM 相关 API 美化。
|
|
155
|
-
4. **`payload.alpha`
|
|
156
|
-
页面自己会通过 `float.getPrefs`/`--gufa-float-alpha`
|
|
151
|
+
4. **`payload.alpha` 未用于原生窗口**:透明度按协议「优先由网页 CSS 决定」;
|
|
152
|
+
页面自己会通过 `float.getPrefs`/`--gufa-float-alpha` 读取偏好(composition 下 CSS rgba 直接作用于合成结果)。
|
|
157
153
|
5. **helper 不提供 `--list-windows`**:Windows 的摸鱼窗口列表由 Host 侧用 PowerShell 实现
|
|
158
154
|
(`host/dev.js` 的 `listFloatWindowsWin`,协议 §5.1「列表 Host 侧实现」)。
|
|
159
155
|
6. **缓存策略**:按 payload.build 分 WebView2 profile 目录,未实现 macOS 那样的「同版本只清内存缓存」;
|