dsh-quay-bot 0.7.4 → 1.0.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/LICENSE +21 -0
- package/README.md +105 -28
- package/bin/doctor.mjs +148 -0
- package/botscreen/requirements-offline.txt +11 -0
- package/client.js +1 -2
- package/cordis.patch.yml +1 -1
- package/host/api.js +0 -4
- package/host/remote.js +2 -140
- package/host/screen.js +85 -21
- package/market/index.json +41 -0
- package/package.json +32 -13
- package/vendor/wheels/any/annotated_doc-0.0.7-py3-none-any.whl +0 -0
- package/vendor/wheels/any/annotated_types-0.8.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/anyio-4.16.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/certifi-2026.11.20-py3-none-any.whl +0 -0
- package/vendor/wheels/any/click-8.5.1-py3-none-any.whl +0 -0
- package/vendor/wheels/any/fastapi-0.165.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/h11-0.16.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/httpcore-1.0.9-py3-none-any.whl +0 -0
- package/vendor/wheels/any/httpx-0.29.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/idna-3.20-py3-none-any.whl +0 -0
- package/vendor/wheels/any/mss-10.2.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/opentelemetry_api-1.45.2-py3-none-any.whl +0 -0
- package/vendor/wheels/any/pydantic-2.14.4-py3-none-any.whl +0 -0
- package/vendor/wheels/any/python_multipart-0.0.34-py3-none-any.whl +0 -0
- package/vendor/wheels/any/python_xlib-0.33-py2.py3-none-any.whl +0 -0
- package/vendor/wheels/any/six-1.17.0-py2.py3-none-any.whl +0 -0
- package/vendor/wheels/any/starlette-1.10.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/typing_extensions-4.16.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/typing_inspection-0.4.5-py3-none-any.whl +0 -0
- package/vendor/wheels/any/uvicorn-0.54.0-py3-none-any.whl +0 -0
- package/vendor/wheels/linux-aarch64/pillow-12.2.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl +0 -0
- package/vendor/wheels/linux-aarch64/pydantic_core-2.50.5-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl +0 -0
- package/vendor/wheels/linux-aarch64/websockets-17.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl +0 -0
- package/vendor/wheels/linux-x86_64/pillow-12.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl +0 -0
- package/vendor/wheels/linux-x86_64/pydantic_core-2.50.5-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl +0 -0
- package/vendor/wheels/linux-x86_64/websockets-17.4-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl +0 -0
- package/botscreen/botscreen/__init__.py +0 -2
- package/botscreen/botscreen/__main__.py +0 -5
- package/botscreen/botscreen/artifacts.py +0 -388
- package/botscreen/botscreen/audit.py +0 -94
- package/botscreen/botscreen/cgroup.py +0 -293
- package/botscreen/botscreen/config.py +0 -320
- package/botscreen/botscreen/desktop/assets/chrome.png +0 -0
- package/botscreen/botscreen/desktop/assets/codex.png +0 -0
- package/botscreen/botscreen/desktop/assets/drive.png +0 -0
- package/botscreen/botscreen/desktop/assets/folder.png +0 -0
- package/botscreen/botscreen/desktop/assets/search.png +0 -0
- package/botscreen/botscreen/desktop/assets/terminal.png +0 -0
- package/botscreen/botscreen/desktop/assets/trash.png +0 -0
- package/botscreen/botscreen/desktop/assets/wallpaper.png +0 -0
- package/botscreen/botscreen/desktop.py +0 -244
- package/botscreen/botscreen/driver.py +0 -832
- package/botscreen/botscreen/gateway.py +0 -2089
- package/botscreen/botscreen/iconlayer.py +0 -841
- package/botscreen/botscreen/mcp_server.py +0 -435
- package/botscreen/botscreen/resources.py +0 -494
- package/botscreen/botscreen/screen.py +0 -1282
- package/botscreen/botscreen/session.py +0 -706
- package/botscreen/botscreen/state.py +0 -330
- package/botscreen/botscreen/streamer.py +0 -388
- package/remote/bin/dsh-remote.mjs +0 -418
- package/remote/package.json +0 -27
- package/remote/src/config.mjs +0 -183
- package/remote/src/crypto.mjs +0 -220
- package/remote/src/keys.mjs +0 -226
- package/remote/src/proxy.mjs +0 -1028
- package/remote/src/sessions.mjs +0 -163
- package/remote/src/shim.js +0 -838
- package/remote/src/supervisor.mjs +0 -207
- package/remote/src/tunnel.mjs +0 -489
- package/remote/src/upstream.mjs +0 -372
- package/remote/src/util.mjs +0 -139
- package/remote/src/ws.mjs +0 -313
- package/requirements.txt +0 -8
|
@@ -1,841 +0,0 @@
|
|
|
1
|
-
"""统一轻量虚拟桌面壳:壁纸 + 桌面图标 + 顶部导航/任务栏 + 底部简洁 Dock + 桌面右键菜单。
|
|
2
|
-
|
|
3
|
-
设计目标
|
|
4
|
-
--------
|
|
5
|
-
1. **所有 Bot 100% 统一规格与样式**:完全不依赖外部 `tint2` / `xfce4-panel` / `xfdesktop` /
|
|
6
|
-
`picom` / `gvfs`(不同宿主机缺包或竞态会导致导航栏/Dock 错位、壁纸黑屏、图标重复)。
|
|
7
|
-
2. **纯 python-xlib + Pillow 单进程(~20MB 内存,0.2s 秒启,无多余动画)**:
|
|
8
|
-
* `botscreen-desktop`(`_NET_WM_WINDOW_TYPE_DESKTOP`,1280×720 固定在 (0,0)):
|
|
9
|
-
壁纸 + 左侧竖排桌面图标(双击启动)+ 右键弹出简洁桌面菜单;
|
|
10
|
-
* `botscreen-topbar`(`_NET_WM_WINDOW_TYPE_DOCK`,1280×34 固定在 (0,0),带顶边 STRUT):
|
|
11
|
-
左侧快捷启动(浏览器/终端/文件)+ 中间 EWMH 实时窗口任务栏 + 右侧时钟;
|
|
12
|
-
* `botscreen-dock`(`_NET_WM_WINDOW_TYPE_DOCK`,284×60 固定在底部居中,带底边 76px STRUT 且位于 below 层):
|
|
13
|
-
静态简洁圆角 Dock(浏览器/搜索/终端/文件,无动画),窗口最大化后精确停在 Dock 上方绝不被遮挡;
|
|
14
|
-
* `botscreen-menu`(`override_redirect=True` 弹出菜单):
|
|
15
|
-
右键桌面即点即弹,支持打开应用、新建文件夹、显示桌面、刷新桌面。
|
|
16
|
-
3. **零空转 CPU**:基于 `select.select` 监听 X11 socket + `PropertyNotify`,静置 CPU ~0%。
|
|
17
|
-
"""
|
|
18
|
-
from __future__ import annotations
|
|
19
|
-
|
|
20
|
-
import argparse
|
|
21
|
-
import os
|
|
22
|
-
import select
|
|
23
|
-
import shutil
|
|
24
|
-
import signal
|
|
25
|
-
import subprocess
|
|
26
|
-
import sys
|
|
27
|
-
import time
|
|
28
|
-
from typing import Dict, List, Optional, Tuple
|
|
29
|
-
|
|
30
|
-
from PIL import Image, ImageDraw, ImageFont
|
|
31
|
-
from Xlib import X, Xatom, display as xdisplay, protocol
|
|
32
|
-
|
|
33
|
-
from .config import DOCK_MARGIN_BOTTOM, SCREEN_HEIGHT, SCREEN_WIDTH, TOPBAR_HEIGHT
|
|
34
|
-
|
|
35
|
-
TILE_W, TILE_H = 100, 96
|
|
36
|
-
ICON_PX = 48
|
|
37
|
-
ICON_TOP = 6
|
|
38
|
-
TEXT_BASELINE = 58
|
|
39
|
-
COL_GAP = 18
|
|
40
|
-
ROW_GAP = 18
|
|
41
|
-
ORIGIN = (22, TOPBAR_HEIGHT + 20)
|
|
42
|
-
|
|
43
|
-
DOCK_W = 284
|
|
44
|
-
DOCK_H = 60
|
|
45
|
-
DOCK_BOTTOM_GAP = 10
|
|
46
|
-
DOCK_ICON_PX = 40
|
|
47
|
-
|
|
48
|
-
MENU_W = 196
|
|
49
|
-
MENU_ROW_H = 30
|
|
50
|
-
MENU_SEP_H = 9
|
|
51
|
-
MENU_PAD_Y = 6
|
|
52
|
-
|
|
53
|
-
FONT_CANDIDATES = (
|
|
54
|
-
"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
|
|
55
|
-
"/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc",
|
|
56
|
-
"/usr/share/fonts/noto/NotoSansCJK-Regular.ttc",
|
|
57
|
-
"/usr/share/fonts/truetype/wqy/wqy-microhei.ttc",
|
|
58
|
-
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
SKIP_TASKBAR_CLASSES = {
|
|
62
|
-
"botscreen-desktop",
|
|
63
|
-
"botscreen-topbar",
|
|
64
|
-
"botscreen-dock",
|
|
65
|
-
"botscreen-menu",
|
|
66
|
-
"xfdesktop",
|
|
67
|
-
"tint2",
|
|
68
|
-
"xfce4-panel",
|
|
69
|
-
}
|
|
70
|
-
SKIP_TASKBAR_TYPES = {
|
|
71
|
-
"_NET_WM_WINDOW_TYPE_DESKTOP",
|
|
72
|
-
"_NET_WM_WINDOW_TYPE_DOCK",
|
|
73
|
-
"_NET_WM_WINDOW_TYPE_SPLASH",
|
|
74
|
-
"_NET_WM_WINDOW_TYPE_NOTIFICATION",
|
|
75
|
-
"_NET_WM_WINDOW_TYPE_TOOLTIP",
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
_FONT_CACHE: Dict[int, ImageFont.ImageFont] = {}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def _font(size: int = 13) -> ImageFont.ImageFont:
|
|
82
|
-
cached = _FONT_CACHE.get(size)
|
|
83
|
-
if cached is not None:
|
|
84
|
-
return cached
|
|
85
|
-
for path in FONT_CANDIDATES:
|
|
86
|
-
if os.path.exists(path):
|
|
87
|
-
try:
|
|
88
|
-
f = ImageFont.truetype(path, size)
|
|
89
|
-
_FONT_CACHE[size] = f
|
|
90
|
-
return f
|
|
91
|
-
except OSError:
|
|
92
|
-
continue
|
|
93
|
-
f = ImageFont.load_default()
|
|
94
|
-
_FONT_CACHE[size] = f
|
|
95
|
-
return f
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
def _chrome_bin() -> str:
|
|
99
|
-
for name in ("google-chrome", "chromium", "chromium-browser"):
|
|
100
|
-
if shutil.which(name):
|
|
101
|
-
return name
|
|
102
|
-
return "google-chrome"
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
def _terminal_cmd() -> str:
|
|
106
|
-
if shutil.which("xfce4-terminal"):
|
|
107
|
-
return "xfce4-terminal --geometry=105x24"
|
|
108
|
-
if shutil.which("xterm"):
|
|
109
|
-
return f"xterm -fa Monospace -fs 11 -geometry 105x24+60+{TOPBAR_HEIGHT + 16}"
|
|
110
|
-
return "x-terminal-emulator"
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
def _filemgr_cmd(target: str) -> str:
|
|
114
|
-
for name in ("pcmanfm", "thunar", "nautilus", "nemo"):
|
|
115
|
-
if shutil.which(name):
|
|
116
|
-
return f"{name} {target}"
|
|
117
|
-
return f"xdg-open {target}"
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
def _chrome_cmd(home: str) -> str:
|
|
121
|
-
chrome = _chrome_bin()
|
|
122
|
-
profile = os.path.join(home, ".config", "google-chrome")
|
|
123
|
-
win_w = max(800, SCREEN_WIDTH - 80)
|
|
124
|
-
win_h = max(360, SCREEN_HEIGHT - TOPBAR_HEIGHT - DOCK_MARGIN_BOTTOM - 20)
|
|
125
|
-
return (
|
|
126
|
-
f"{chrome} --no-sandbox --disable-gpu --no-first-run --disable-dev-shm-usage "
|
|
127
|
-
f"--user-data-dir={profile} --window-position=40,{TOPBAR_HEIGHT + 12} "
|
|
128
|
-
f"--window-size={win_w},{win_h}"
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
def _search_cmd(home: str, assets: str) -> str:
|
|
133
|
-
chrome = _chrome_bin()
|
|
134
|
-
profile = os.path.join(home, ".config", "google-chrome")
|
|
135
|
-
search_html = os.path.join(assets, "search.html")
|
|
136
|
-
win_h = max(360, min(560, SCREEN_HEIGHT - TOPBAR_HEIGHT - DOCK_MARGIN_BOTTOM - 24))
|
|
137
|
-
return (
|
|
138
|
-
f"{chrome} --no-sandbox --disable-gpu --no-first-run --disable-dev-shm-usage "
|
|
139
|
-
f"--user-data-dir={profile} --window-position=190,{TOPBAR_HEIGHT + 24} "
|
|
140
|
-
f"--window-size=900,{win_h} --app=file://{search_html}"
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
def desktop_items(home: str) -> List[dict]:
|
|
145
|
-
return [
|
|
146
|
-
{"label": "浏览器", "icon": "chrome.png", "cmd": _chrome_cmd(home)},
|
|
147
|
-
{"label": "终端", "icon": "terminal.png", "cmd": _terminal_cmd()},
|
|
148
|
-
{"label": "主文件夹", "icon": "folder.png", "cmd": _filemgr_cmd(home)},
|
|
149
|
-
{"label": "文件系统", "icon": "drive.png", "cmd": _filemgr_cmd("/")},
|
|
150
|
-
]
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
def topbar_launchers(home: str) -> List[dict]:
|
|
154
|
-
return [
|
|
155
|
-
{"id": "browser", "label": "浏览器", "icon": "chrome.png", "cmd": _chrome_cmd(home)},
|
|
156
|
-
{"id": "terminal", "label": "终端", "icon": "terminal.png", "cmd": _terminal_cmd()},
|
|
157
|
-
{"id": "files", "label": "文件", "icon": "folder.png", "cmd": _filemgr_cmd(home)},
|
|
158
|
-
]
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
def dock_items(home: str, assets: str) -> List[dict]:
|
|
162
|
-
return [
|
|
163
|
-
{"id": "browser", "label": "浏览器", "icon": "chrome.png", "cmd": _chrome_cmd(home)},
|
|
164
|
-
{"id": "search", "label": "搜索", "icon": "search.png", "cmd": _search_cmd(home, assets)},
|
|
165
|
-
{"id": "terminal", "label": "终端", "icon": "terminal.png", "cmd": _terminal_cmd()},
|
|
166
|
-
{"id": "files", "label": "文件", "icon": "folder.png", "cmd": _filemgr_cmd(home)},
|
|
167
|
-
]
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def _fallback_wallpaper(sw: int, sh: int) -> Image.Image:
|
|
171
|
-
"""无壁纸资源时生成统一的深蓝灰渐变背景。"""
|
|
172
|
-
img = Image.new("RGB", (sw, sh), (15, 22, 32))
|
|
173
|
-
draw = ImageDraw.Draw(img)
|
|
174
|
-
for y in range(sh):
|
|
175
|
-
t = y / max(1, sh - 1)
|
|
176
|
-
r = int(16 + 10 * t)
|
|
177
|
-
g = int(24 + 14 * t)
|
|
178
|
-
b = int(36 + 18 * t)
|
|
179
|
-
draw.line([(0, y), (sw, y)], fill=(r, g, b))
|
|
180
|
-
return img
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
def render_tile(wall: Image.Image, x: int, y: int, icon_path: str, label: str) -> Image.Image:
|
|
184
|
-
"""裁壁纸做底 + 叠加图标和带阴影文字,保证与桌面无缝融合。"""
|
|
185
|
-
tile = wall.crop((x, y, x + TILE_W, y + TILE_H)).convert("RGB")
|
|
186
|
-
if os.path.exists(icon_path):
|
|
187
|
-
try:
|
|
188
|
-
icon = Image.open(icon_path).convert("RGBA").resize((ICON_PX, ICON_PX), Image.LANCZOS)
|
|
189
|
-
tile.paste(icon, ((TILE_W - ICON_PX) // 2, ICON_TOP), icon)
|
|
190
|
-
except OSError:
|
|
191
|
-
pass
|
|
192
|
-
draw = ImageDraw.Draw(tile)
|
|
193
|
-
font = _font(13)
|
|
194
|
-
width = draw.textlength(label, font=font)
|
|
195
|
-
tx = (TILE_W - width) / 2
|
|
196
|
-
for dx, dy in ((-1, 0), (1, 0), (0, -1), (0, 1), (-1, -1), (1, 1)):
|
|
197
|
-
draw.text((tx + dx, TEXT_BASELINE + dy), label, font=font, fill=(0, 0, 0))
|
|
198
|
-
draw.text((tx, TEXT_BASELINE), label, font=font, fill=(245, 248, 250))
|
|
199
|
-
return tile
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
def render_dock(
|
|
203
|
-
wall: Image.Image,
|
|
204
|
-
dock_x: int,
|
|
205
|
-
dock_y: int,
|
|
206
|
-
items: List[dict],
|
|
207
|
-
assets: str,
|
|
208
|
-
) -> Tuple[Image.Image, List[dict]]:
|
|
209
|
-
"""渲染静态简洁底部圆角 Dock(零动画,用对应区域壁纸合成实现 24 位色深圆角透明效果)。"""
|
|
210
|
-
base = wall.crop((dock_x, dock_y, dock_x + DOCK_W, dock_y + DOCK_H)).convert("RGBA")
|
|
211
|
-
overlay = Image.new("RGBA", (DOCK_W, DOCK_H), (0, 0, 0, 0))
|
|
212
|
-
draw = ImageDraw.Draw(overlay)
|
|
213
|
-
draw.rounded_rectangle(
|
|
214
|
-
[0, 0, DOCK_W - 1, DOCK_H - 1],
|
|
215
|
-
radius=16,
|
|
216
|
-
fill=(11, 14, 19, 224),
|
|
217
|
-
outline=(55, 68, 84, 210),
|
|
218
|
-
width=1,
|
|
219
|
-
)
|
|
220
|
-
img = Image.alpha_composite(base, overlay)
|
|
221
|
-
|
|
222
|
-
count = max(1, len(items))
|
|
223
|
-
pad_x = 18
|
|
224
|
-
inner_w = DOCK_W - pad_x * 2
|
|
225
|
-
slot_w = inner_w / count
|
|
226
|
-
hits: List[dict] = []
|
|
227
|
-
for idx, item in enumerate(items):
|
|
228
|
-
sx0 = int(pad_x + idx * slot_w)
|
|
229
|
-
sx1 = int(pad_x + (idx + 1) * slot_w)
|
|
230
|
-
ix = sx0 + (sx1 - sx0 - DOCK_ICON_PX) // 2
|
|
231
|
-
iy = (DOCK_H - DOCK_ICON_PX) // 2
|
|
232
|
-
icon_path = os.path.join(assets, item["icon"])
|
|
233
|
-
if os.path.exists(icon_path):
|
|
234
|
-
try:
|
|
235
|
-
ic = Image.open(icon_path).convert("RGBA").resize((DOCK_ICON_PX, DOCK_ICON_PX), Image.LANCZOS)
|
|
236
|
-
img.paste(ic, (ix, iy), ic)
|
|
237
|
-
except OSError:
|
|
238
|
-
pass
|
|
239
|
-
hits.append({"x0": sx0, "x1": sx1, "cmd": item["cmd"], "label": item["label"]})
|
|
240
|
-
return img.convert("RGB"), hits
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
def _truncate_text(draw: ImageDraw.ImageDraw, text: str, font: ImageFont.ImageFont, max_w: float) -> str:
|
|
244
|
-
if draw.textlength(text, font=font) <= max_w:
|
|
245
|
-
return text
|
|
246
|
-
ell = "…"
|
|
247
|
-
out = text
|
|
248
|
-
while len(out) > 1 and draw.textlength(out + ell, font=font) > max_w:
|
|
249
|
-
out = out[:-1]
|
|
250
|
-
return out + ell
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
def _load_small_icon(path: str, size: int = 16) -> Optional[Image.Image]:
|
|
254
|
-
if not os.path.exists(path):
|
|
255
|
-
return None
|
|
256
|
-
try:
|
|
257
|
-
return Image.open(path).convert("RGBA").resize((size, size), Image.LANCZOS)
|
|
258
|
-
except OSError:
|
|
259
|
-
return None
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
def _create_new_desktop_folder(home: str) -> str:
|
|
263
|
-
desktop_dir = os.path.join(home, "Desktop")
|
|
264
|
-
os.makedirs(desktop_dir, exist_ok=True)
|
|
265
|
-
base = "新建文件夹"
|
|
266
|
-
target = os.path.join(desktop_dir, base)
|
|
267
|
-
idx = 2
|
|
268
|
-
while os.path.exists(target):
|
|
269
|
-
target = os.path.join(desktop_dir, f"{base} {idx}")
|
|
270
|
-
idx += 1
|
|
271
|
-
os.makedirs(target, exist_ok=True)
|
|
272
|
-
return desktop_dir
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
def main() -> int:
|
|
276
|
-
ap = argparse.ArgumentParser()
|
|
277
|
-
ap.add_argument("--display", default=os.environ.get("DISPLAY", ":0"))
|
|
278
|
-
ap.add_argument("--home", required=True)
|
|
279
|
-
ap.add_argument("--assets", required=True)
|
|
280
|
-
ap.add_argument("--double-click-ms", type=int, default=450)
|
|
281
|
-
args = ap.parse_args()
|
|
282
|
-
|
|
283
|
-
dpy = xdisplay.Display(args.display)
|
|
284
|
-
screen = dpy.screen()
|
|
285
|
-
root = screen.root
|
|
286
|
-
depth = screen.root_depth
|
|
287
|
-
sw, sh = screen.width_in_pixels, screen.height_in_pixels
|
|
288
|
-
|
|
289
|
-
def _atom(name: str):
|
|
290
|
-
try:
|
|
291
|
-
return dpy.get_atom(name)
|
|
292
|
-
except Exception: # noqa: BLE001
|
|
293
|
-
from Xlib.Xatom import Atom as _A
|
|
294
|
-
|
|
295
|
-
return _A(dpy.intern_atom(name))
|
|
296
|
-
|
|
297
|
-
a_wm_type = _atom("_NET_WM_WINDOW_TYPE")
|
|
298
|
-
a_desktop = _atom("_NET_WM_WINDOW_TYPE_DESKTOP")
|
|
299
|
-
a_dock = _atom("_NET_WM_WINDOW_TYPE_DOCK")
|
|
300
|
-
a_popup_menu = _atom("_NET_WM_WINDOW_TYPE_POPUP_MENU")
|
|
301
|
-
a_strut = _atom("_NET_WM_STRUT")
|
|
302
|
-
a_strut_partial = _atom("_NET_WM_STRUT_PARTIAL")
|
|
303
|
-
a_wm_state = _atom("_NET_WM_STATE")
|
|
304
|
-
a_state_above = _atom("_NET_WM_STATE_ABOVE")
|
|
305
|
-
a_state_below = _atom("_NET_WM_STATE_BELOW")
|
|
306
|
-
a_state_sticky = _atom("_NET_WM_STATE_STICKY")
|
|
307
|
-
a_state_skip_tb = _atom("_NET_WM_STATE_SKIP_TASKBAR")
|
|
308
|
-
a_state_skip_pg = _atom("_NET_WM_STATE_SKIP_PAGER")
|
|
309
|
-
a_state_hidden = _atom("_NET_WM_STATE_HIDDEN")
|
|
310
|
-
a_client_list = _atom("_NET_CLIENT_LIST")
|
|
311
|
-
a_active_win = _atom("_NET_ACTIVE_WINDOW")
|
|
312
|
-
a_net_wm_name = _atom("_NET_WM_NAME")
|
|
313
|
-
a_change_state = _atom("WM_CHANGE_STATE")
|
|
314
|
-
|
|
315
|
-
wall_path = os.path.join(args.assets, "wallpaper.png")
|
|
316
|
-
try:
|
|
317
|
-
wall = Image.open(wall_path).convert("RGB").resize((sw, sh), Image.LANCZOS)
|
|
318
|
-
except OSError:
|
|
319
|
-
wall = _fallback_wallpaper(sw, sh)
|
|
320
|
-
|
|
321
|
-
gc = root.create_gc()
|
|
322
|
-
|
|
323
|
-
# ---- 1. 桌面背景 + 图标窗口 (1280×720) --------------------------------
|
|
324
|
-
composite = wall.copy()
|
|
325
|
-
desktop_hits: List[dict] = []
|
|
326
|
-
for idx, item in enumerate(desktop_items(args.home)):
|
|
327
|
-
x = ORIGIN[0] + (idx // 5) * (TILE_W + COL_GAP)
|
|
328
|
-
y = ORIGIN[1] + (idx % 5) * (TILE_H + ROW_GAP)
|
|
329
|
-
tile = render_tile(wall, x, y, os.path.join(args.assets, item["icon"]), item["label"])
|
|
330
|
-
composite.paste(tile, (x, y))
|
|
331
|
-
desktop_hits.append({"x": x, "y": y, "w": TILE_W, "h": TILE_H, "item": item})
|
|
332
|
-
|
|
333
|
-
desktop_win = root.create_window(
|
|
334
|
-
0, 0, sw, sh, 0, depth, X.InputOutput, X.CopyFromParent,
|
|
335
|
-
background_pixel=screen.black_pixel,
|
|
336
|
-
event_mask=X.ExposureMask | X.ButtonPressMask,
|
|
337
|
-
)
|
|
338
|
-
desktop_win.set_wm_class("botscreen-desktop", "BotScreen")
|
|
339
|
-
desktop_win.set_wm_name("BotScreen Desktop")
|
|
340
|
-
desktop_win.change_property(a_wm_type, Xatom.ATOM, 32, [a_desktop])
|
|
341
|
-
desktop_win.change_property(
|
|
342
|
-
a_wm_state, Xatom.ATOM, 32, [a_state_below, a_state_sticky, a_state_skip_tb, a_state_skip_pg]
|
|
343
|
-
)
|
|
344
|
-
desktop_win.map()
|
|
345
|
-
|
|
346
|
-
# ---- 2. 顶部固定导航栏 + 任务栏窗口 (1280×34 固定在 (0,0)) --------------
|
|
347
|
-
bar_h = TOPBAR_HEIGHT
|
|
348
|
-
topbar_win = root.create_window(
|
|
349
|
-
0, 0, sw, bar_h, 0, depth, X.InputOutput, X.CopyFromParent,
|
|
350
|
-
background_pixel=screen.black_pixel,
|
|
351
|
-
event_mask=X.ExposureMask | X.ButtonPressMask,
|
|
352
|
-
)
|
|
353
|
-
topbar_win.set_wm_class("botscreen-topbar", "BotScreen")
|
|
354
|
-
topbar_win.set_wm_name("BotScreen Topbar")
|
|
355
|
-
topbar_win.change_property(a_wm_type, Xatom.ATOM, 32, [a_dock])
|
|
356
|
-
topbar_win.change_property(
|
|
357
|
-
a_wm_state, Xatom.ATOM, 32, [a_state_above, a_state_sticky, a_state_skip_tb, a_state_skip_pg]
|
|
358
|
-
)
|
|
359
|
-
topbar_win.change_property(a_strut, Xatom.CARDINAL, 32, [0, 0, bar_h, 0])
|
|
360
|
-
topbar_win.change_property(
|
|
361
|
-
a_strut_partial, Xatom.CARDINAL, 32,
|
|
362
|
-
[0, 0, bar_h, 0, 0, 0, 0, 0, 0, sw - 1, 0, 0],
|
|
363
|
-
)
|
|
364
|
-
topbar_win.map()
|
|
365
|
-
topbar_win.configure(x=0, y=0, width=sw, height=bar_h, stack_mode=X.Above)
|
|
366
|
-
|
|
367
|
-
# ---- 3. 底部简洁静态 Dock 栏 (284×60 固定底部居中,below 层 + 底边 STRUT) ---
|
|
368
|
-
# 底边预留 DOCK_MARGIN_BOTTOM (76px) 使最大化窗口底边严格停在 Dock 上方,绝不被遮挡;
|
|
369
|
-
# 同时处于 below 层,即使窗口手动拖拉或全屏也绝不盖住窗口内容。
|
|
370
|
-
dock_x = (sw - DOCK_W) // 2
|
|
371
|
-
dock_y = sh - DOCK_H - DOCK_BOTTOM_GAP
|
|
372
|
-
dock_img, dock_hits = render_dock(wall, dock_x, dock_y, dock_items(args.home, args.assets), args.assets)
|
|
373
|
-
dock_raw = dock_img.tobytes("raw", "BGRX")
|
|
374
|
-
|
|
375
|
-
dock_win = root.create_window(
|
|
376
|
-
dock_x, dock_y, DOCK_W, DOCK_H, 0, depth, X.InputOutput, X.CopyFromParent,
|
|
377
|
-
background_pixel=screen.black_pixel,
|
|
378
|
-
event_mask=X.ExposureMask | X.ButtonPressMask,
|
|
379
|
-
)
|
|
380
|
-
dock_win.set_wm_class("botscreen-dock", "BotScreen")
|
|
381
|
-
dock_win.set_wm_name("BotScreen Dock")
|
|
382
|
-
dock_win.change_property(a_wm_type, Xatom.ATOM, 32, [a_dock])
|
|
383
|
-
dock_win.change_property(
|
|
384
|
-
a_wm_state, Xatom.ATOM, 32, [a_state_below, a_state_sticky, a_state_skip_tb, a_state_skip_pg]
|
|
385
|
-
)
|
|
386
|
-
dock_win.change_property(a_strut, Xatom.CARDINAL, 32, [0, 0, 0, DOCK_MARGIN_BOTTOM])
|
|
387
|
-
dock_win.change_property(
|
|
388
|
-
a_strut_partial, Xatom.CARDINAL, 32,
|
|
389
|
-
[0, 0, 0, DOCK_MARGIN_BOTTOM, 0, 0, 0, 0, 0, 0, 0, sw - 1],
|
|
390
|
-
)
|
|
391
|
-
dock_win.map()
|
|
392
|
-
dock_win.configure(x=dock_x, y=dock_y, width=DOCK_W, height=DOCK_H)
|
|
393
|
-
|
|
394
|
-
# ---- 4. 桌面右键上下文菜单窗口(override_redirect,无动画即点即弹) -------
|
|
395
|
-
menu_entries = [
|
|
396
|
-
{"kind": "item", "id": "terminal", "label": "打开终端"},
|
|
397
|
-
{"kind": "item", "id": "browser", "label": "打开浏览器"},
|
|
398
|
-
{"kind": "item", "id": "files", "label": "打开文件管理器"},
|
|
399
|
-
{"kind": "item", "id": "search", "label": "网页搜索"},
|
|
400
|
-
{"kind": "sep"},
|
|
401
|
-
{"kind": "item", "id": "new_folder", "label": "新建文件夹"},
|
|
402
|
-
{"kind": "item", "id": "show_desktop", "label": "显示桌面"},
|
|
403
|
-
{"kind": "item", "id": "refresh", "label": "刷新桌面"},
|
|
404
|
-
]
|
|
405
|
-
menu_h = MENU_PAD_Y * 2 + sum(MENU_SEP_H if e["kind"] == "sep" else MENU_ROW_H for e in menu_entries)
|
|
406
|
-
menu_win = root.create_window(
|
|
407
|
-
0, 0, MENU_W, menu_h, 0, depth, X.InputOutput, X.CopyFromParent,
|
|
408
|
-
override_redirect=True,
|
|
409
|
-
background_pixel=screen.black_pixel,
|
|
410
|
-
event_mask=X.ExposureMask | X.ButtonPressMask | X.PointerMotionMask | X.LeaveWindowMask,
|
|
411
|
-
)
|
|
412
|
-
menu_win.set_wm_class("botscreen-menu", "BotScreen")
|
|
413
|
-
menu_win.change_property(a_wm_type, Xatom.ATOM, 32, [a_popup_menu])
|
|
414
|
-
menu_state = {"open": False, "hover": -1, "rows": []}
|
|
415
|
-
|
|
416
|
-
# 监听根窗口属性变更(窗口打开/关闭/焦点切换实时同步顶部任务栏)
|
|
417
|
-
try:
|
|
418
|
-
root.change_attributes(event_mask=X.PropertyChangeMask)
|
|
419
|
-
except Exception: # noqa: BLE001
|
|
420
|
-
pass
|
|
421
|
-
dpy.sync()
|
|
422
|
-
|
|
423
|
-
# 条带分批绘制桌面背景(避免 X11 PutImage 单包超限)
|
|
424
|
-
BAND = 8
|
|
425
|
-
desktop_bands = [
|
|
426
|
-
(y, composite.crop((0, y, sw, min(y + BAND, sh))).tobytes("raw", "BGRX"), min(BAND, sh - y))
|
|
427
|
-
for y in range(0, sh, BAND)
|
|
428
|
-
]
|
|
429
|
-
|
|
430
|
-
def paint_desktop() -> None:
|
|
431
|
-
for y, raw, h_band in desktop_bands:
|
|
432
|
-
desktop_win.put_image(gc, 0, y, sw, h_band, X.ZPixmap, depth, 0, raw)
|
|
433
|
-
dpy.sync()
|
|
434
|
-
|
|
435
|
-
def paint_dock() -> None:
|
|
436
|
-
dock_win.put_image(gc, 0, 0, DOCK_W, DOCK_H, X.ZPixmap, depth, 0, dock_raw)
|
|
437
|
-
dpy.sync()
|
|
438
|
-
|
|
439
|
-
def paint_menu() -> None:
|
|
440
|
-
if not menu_state["open"]:
|
|
441
|
-
return
|
|
442
|
-
img = Image.new("RGB", (MENU_W, menu_h), (20, 26, 35))
|
|
443
|
-
draw = ImageDraw.Draw(img)
|
|
444
|
-
draw.rectangle([0, 0, MENU_W - 1, menu_h - 1], outline=(56, 70, 88), width=1)
|
|
445
|
-
f_menu = _font(13)
|
|
446
|
-
cy = MENU_PAD_Y
|
|
447
|
-
rows: List[dict] = []
|
|
448
|
-
for idx, entry in enumerate(menu_entries):
|
|
449
|
-
if entry["kind"] == "sep":
|
|
450
|
-
my = cy + MENU_SEP_H // 2
|
|
451
|
-
draw.line([(10, my), (MENU_W - 10, my)], fill=(45, 56, 70))
|
|
452
|
-
cy += MENU_SEP_H
|
|
453
|
-
continue
|
|
454
|
-
y0, y1 = cy, cy + MENU_ROW_H
|
|
455
|
-
hovered = idx == menu_state["hover"]
|
|
456
|
-
if hovered:
|
|
457
|
-
draw.rounded_rectangle([5, y0 + 2, MENU_W - 6, y1 - 2], radius=5, fill=(40, 56, 74))
|
|
458
|
-
draw.text((14, y0 + 6), entry["label"], font=f_menu, fill=(242, 247, 252) if hovered else (215, 224, 234))
|
|
459
|
-
rows.append({"idx": idx, "id": entry["id"], "y0": y0, "y1": y1})
|
|
460
|
-
cy = y1
|
|
461
|
-
menu_state["rows"] = rows
|
|
462
|
-
menu_win.put_image(gc, 0, 0, MENU_W, menu_h, X.ZPixmap, depth, 0, img.tobytes("raw", "BGRX"))
|
|
463
|
-
dpy.sync()
|
|
464
|
-
|
|
465
|
-
def close_menu() -> None:
|
|
466
|
-
if not menu_state["open"]:
|
|
467
|
-
return
|
|
468
|
-
menu_state["open"] = False
|
|
469
|
-
menu_state["hover"] = -1
|
|
470
|
-
try:
|
|
471
|
-
menu_win.unmap()
|
|
472
|
-
dpy.sync()
|
|
473
|
-
except Exception: # noqa: BLE001
|
|
474
|
-
pass
|
|
475
|
-
|
|
476
|
-
def open_menu(px: int, py: int) -> None:
|
|
477
|
-
max_x = max(0, sw - MENU_W - 6)
|
|
478
|
-
max_y = max(TOPBAR_HEIGHT + 4, sh - DOCK_MARGIN_BOTTOM - menu_h - 4)
|
|
479
|
-
mx = max(6, min(max_x, int(px)))
|
|
480
|
-
my = max(TOPBAR_HEIGHT + 4, min(max_y, int(py)))
|
|
481
|
-
menu_state["open"] = True
|
|
482
|
-
menu_state["hover"] = -1
|
|
483
|
-
menu_win.configure(x=mx, y=my, width=MENU_W, height=menu_h, stack_mode=X.Above)
|
|
484
|
-
menu_win.map()
|
|
485
|
-
paint_menu()
|
|
486
|
-
|
|
487
|
-
launchers = topbar_launchers(args.home)
|
|
488
|
-
launcher_icons = {
|
|
489
|
-
item["id"]: _load_small_icon(os.path.join(args.assets, item["icon"]), 16)
|
|
490
|
-
for item in launchers
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
def query_tasks() -> Tuple[List[dict], int]:
|
|
494
|
-
tasks: List[dict] = []
|
|
495
|
-
active_id = 0
|
|
496
|
-
try:
|
|
497
|
-
act_prop = root.get_full_property(a_active_win, 0)
|
|
498
|
-
if act_prop and act_prop.value:
|
|
499
|
-
active_id = int(act_prop.value[0])
|
|
500
|
-
prop = root.get_full_property(a_client_list, 0)
|
|
501
|
-
wids = list(prop.value) if (prop and prop.value) else []
|
|
502
|
-
except Exception: # noqa: BLE001
|
|
503
|
-
return tasks, active_id
|
|
504
|
-
|
|
505
|
-
for wid in wids:
|
|
506
|
-
if int(wid) in (desktop_win.id, topbar_win.id, dock_win.id, menu_win.id):
|
|
507
|
-
continue
|
|
508
|
-
try:
|
|
509
|
-
w = dpy.create_resource_object("window", int(wid))
|
|
510
|
-
t_prop = w.get_full_property(a_wm_type, 0)
|
|
511
|
-
if t_prop and t_prop.value:
|
|
512
|
-
tnames = {dpy.get_atom_name(int(a)) for a in t_prop.value}
|
|
513
|
-
if tnames & SKIP_TASKBAR_TYPES:
|
|
514
|
-
continue
|
|
515
|
-
cls_raw = w.get_wm_class()
|
|
516
|
-
cls_lower = [str(c).lower() for c in cls_raw] if cls_raw else []
|
|
517
|
-
if any(c in SKIP_TASKBAR_CLASSES for c in cls_lower):
|
|
518
|
-
continue
|
|
519
|
-
s_prop = w.get_full_property(a_wm_state, 0)
|
|
520
|
-
states = set(int(a) for a in (s_prop.value if (s_prop and s_prop.value) else []))
|
|
521
|
-
if int(a_state_skip_tb) in states:
|
|
522
|
-
continue
|
|
523
|
-
minimized = int(a_state_hidden) in states
|
|
524
|
-
title = ""
|
|
525
|
-
np = w.get_full_property(a_net_wm_name, 0)
|
|
526
|
-
if np and np.value:
|
|
527
|
-
title = np.value.decode("utf-8", errors="ignore").strip() if isinstance(np.value, bytes) else str(np.value).strip()
|
|
528
|
-
if not title:
|
|
529
|
-
raw_n = w.get_wm_name()
|
|
530
|
-
if isinstance(raw_n, bytes):
|
|
531
|
-
title = raw_n.decode("utf-8", errors="ignore").strip()
|
|
532
|
-
elif raw_n:
|
|
533
|
-
title = str(raw_n).strip()
|
|
534
|
-
if not title:
|
|
535
|
-
title = cls_raw[1] if (cls_raw and len(cls_raw) > 1) else "Window"
|
|
536
|
-
tasks.append({
|
|
537
|
-
"wid": int(wid),
|
|
538
|
-
"title": title[:60],
|
|
539
|
-
"active": int(wid) == active_id and not minimized,
|
|
540
|
-
"minimized": minimized,
|
|
541
|
-
})
|
|
542
|
-
except Exception: # noqa: BLE001
|
|
543
|
-
continue
|
|
544
|
-
return tasks, active_id
|
|
545
|
-
|
|
546
|
-
topbar_hits: List[dict] = []
|
|
547
|
-
last_bar_sig = None
|
|
548
|
-
|
|
549
|
-
def paint_topbar(force: bool = False) -> None:
|
|
550
|
-
nonlocal topbar_hits, last_bar_sig
|
|
551
|
-
tasks, active_id = query_tasks()
|
|
552
|
-
clock_str = time.strftime("%m-%d %H:%M")
|
|
553
|
-
sig = (clock_str, active_id, tuple((t["wid"], t["title"], t["active"], t["minimized"]) for t in tasks))
|
|
554
|
-
if not force and sig == last_bar_sig:
|
|
555
|
-
return
|
|
556
|
-
last_bar_sig = sig
|
|
557
|
-
|
|
558
|
-
img = Image.new("RGB", (sw, bar_h), (16, 21, 29))
|
|
559
|
-
draw = ImageDraw.Draw(img)
|
|
560
|
-
draw.line([(0, bar_h - 1), (sw, bar_h - 1)], fill=(38, 48, 61))
|
|
561
|
-
|
|
562
|
-
f_btn = _font(12)
|
|
563
|
-
f_clk = _font(12)
|
|
564
|
-
hits: List[dict] = []
|
|
565
|
-
|
|
566
|
-
cx = 10
|
|
567
|
-
for item in launchers:
|
|
568
|
-
label = item["label"]
|
|
569
|
-
tw = int(draw.textlength(label, font=f_btn))
|
|
570
|
-
has_ic = launcher_icons.get(item["id"]) is not None
|
|
571
|
-
bw = tw + (34 if has_ic else 20)
|
|
572
|
-
by0, by1 = 5, bar_h - 6
|
|
573
|
-
draw.rounded_rectangle([cx, by0, cx + bw, by1], radius=6, fill=(28, 36, 48), outline=(49, 62, 78))
|
|
574
|
-
tx = cx + 10
|
|
575
|
-
if has_ic:
|
|
576
|
-
ic = launcher_icons[item["id"]]
|
|
577
|
-
assert ic is not None
|
|
578
|
-
img.paste(ic, (cx + 7, (bar_h - 16) // 2), ic)
|
|
579
|
-
tx = cx + 27
|
|
580
|
-
draw.text((tx, (bar_h - 15) // 2), label, font=f_btn, fill=(224, 232, 240))
|
|
581
|
-
hits.append({"kind": "launch", "x0": cx, "x1": cx + bw, "cmd": item["cmd"], "label": label})
|
|
582
|
-
cx += bw + 6
|
|
583
|
-
|
|
584
|
-
cx += 4
|
|
585
|
-
draw.line([(cx, 8), (cx, bar_h - 9)], fill=(45, 56, 70))
|
|
586
|
-
cx += 10
|
|
587
|
-
|
|
588
|
-
clk_w = int(draw.textlength(clock_str, font=f_clk)) + 20
|
|
589
|
-
right_limit = sw - clk_w - 8
|
|
590
|
-
|
|
591
|
-
if tasks and right_limit > cx + 60:
|
|
592
|
-
avail = right_limit - cx
|
|
593
|
-
max_tabs = min(len(tasks), 8)
|
|
594
|
-
tab_w = max(84, min(180, (avail - (max_tabs - 1) * 6) // max_tabs))
|
|
595
|
-
for task in tasks[:max_tabs]:
|
|
596
|
-
if cx + tab_w > right_limit:
|
|
597
|
-
break
|
|
598
|
-
by0, by1 = 5, bar_h - 6
|
|
599
|
-
if task["active"]:
|
|
600
|
-
fill = (35, 55, 76)
|
|
601
|
-
outline = (70, 179, 157)
|
|
602
|
-
fg = (242, 247, 252)
|
|
603
|
-
elif task["minimized"]:
|
|
604
|
-
fill = (21, 27, 36)
|
|
605
|
-
outline = (42, 52, 66)
|
|
606
|
-
fg = (130, 146, 164)
|
|
607
|
-
else:
|
|
608
|
-
fill = (26, 33, 44)
|
|
609
|
-
outline = (48, 60, 76)
|
|
610
|
-
fg = (202, 214, 226)
|
|
611
|
-
draw.rounded_rectangle([cx, by0, cx + tab_w, by1], radius=6, fill=fill, outline=outline)
|
|
612
|
-
if task["active"]:
|
|
613
|
-
draw.rectangle([cx + 8, by1 - 2, cx + tab_w - 8, by1], fill=(70, 179, 157))
|
|
614
|
-
dot_c = (70, 179, 157) if task["active"] else ((100, 116, 139) if task["minimized"] else (96, 165, 250))
|
|
615
|
-
draw.ellipse([cx + 8, (bar_h - 6) // 2, cx + 14, (bar_h + 6) // 2], fill=dot_c)
|
|
616
|
-
txt = _truncate_text(draw, task["title"], f_btn, tab_w - 26)
|
|
617
|
-
draw.text((cx + 20, (bar_h - 15) // 2), txt, font=f_btn, fill=fg)
|
|
618
|
-
hits.append({
|
|
619
|
-
"kind": "window",
|
|
620
|
-
"x0": cx,
|
|
621
|
-
"x1": cx + tab_w,
|
|
622
|
-
"wid": task["wid"],
|
|
623
|
-
"active": task["active"],
|
|
624
|
-
})
|
|
625
|
-
cx += tab_w + 6
|
|
626
|
-
|
|
627
|
-
draw.text((sw - clk_w + 8, (bar_h - 15) // 2), clock_str, font=f_clk, fill=(203, 213, 225))
|
|
628
|
-
topbar_hits = hits
|
|
629
|
-
|
|
630
|
-
raw = img.tobytes("raw", "BGRX")
|
|
631
|
-
topbar_win.put_image(gc, 0, 0, sw, bar_h, X.ZPixmap, depth, 0, raw)
|
|
632
|
-
dpy.sync()
|
|
633
|
-
|
|
634
|
-
def focus_or_toggle_window(wid: int, is_active: bool) -> None:
|
|
635
|
-
try:
|
|
636
|
-
target = dpy.create_resource_object("window", int(wid))
|
|
637
|
-
if is_active:
|
|
638
|
-
ev = protocol.event.ClientMessage(
|
|
639
|
-
window=target,
|
|
640
|
-
client_type=a_change_state,
|
|
641
|
-
data=(32, [3, 0, 0, 0, 0]),
|
|
642
|
-
)
|
|
643
|
-
else:
|
|
644
|
-
ev = protocol.event.ClientMessage(
|
|
645
|
-
window=target,
|
|
646
|
-
client_type=a_active_win,
|
|
647
|
-
data=(32, [2, X.CurrentTime, 0, 0, 0]),
|
|
648
|
-
)
|
|
649
|
-
root.send_event(ev, event_mask=X.SubstructureRedirectMask | X.SubstructureNotifyMask)
|
|
650
|
-
dpy.flush()
|
|
651
|
-
dpy.sync()
|
|
652
|
-
except Exception: # noqa: BLE001
|
|
653
|
-
pass
|
|
654
|
-
|
|
655
|
-
def minimize_all_windows() -> None:
|
|
656
|
-
tasks, _ = query_tasks()
|
|
657
|
-
for task in tasks:
|
|
658
|
-
if not task["minimized"]:
|
|
659
|
-
try:
|
|
660
|
-
target = dpy.create_resource_object("window", int(task["wid"]))
|
|
661
|
-
ev = protocol.event.ClientMessage(
|
|
662
|
-
window=target,
|
|
663
|
-
client_type=a_change_state,
|
|
664
|
-
data=(32, [3, 0, 0, 0, 0]),
|
|
665
|
-
)
|
|
666
|
-
root.send_event(ev, event_mask=X.SubstructureRedirectMask | X.SubstructureNotifyMask)
|
|
667
|
-
except Exception: # noqa: BLE001
|
|
668
|
-
continue
|
|
669
|
-
try:
|
|
670
|
-
dpy.flush()
|
|
671
|
-
dpy.sync()
|
|
672
|
-
except Exception: # noqa: BLE001
|
|
673
|
-
pass
|
|
674
|
-
|
|
675
|
-
env = dict(os.environ)
|
|
676
|
-
env["DISPLAY"] = args.display
|
|
677
|
-
env["HOME"] = args.home
|
|
678
|
-
|
|
679
|
-
def launch_cmd(cmd: str, label: str) -> None:
|
|
680
|
-
try:
|
|
681
|
-
subprocess.Popen(
|
|
682
|
-
cmd, shell=True, env=env, cwd=args.home,
|
|
683
|
-
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
|
684
|
-
start_new_session=True,
|
|
685
|
-
)
|
|
686
|
-
print(f"iconlayer: launch {label} -> {cmd}", flush=True)
|
|
687
|
-
except OSError as exc:
|
|
688
|
-
print(f"iconlayer: launch failed {exc}", file=sys.stderr, flush=True)
|
|
689
|
-
|
|
690
|
-
def run_menu_action(action_id: str) -> None:
|
|
691
|
-
close_menu()
|
|
692
|
-
if action_id == "terminal":
|
|
693
|
-
launch_cmd(_terminal_cmd(), "终端")
|
|
694
|
-
elif action_id == "browser":
|
|
695
|
-
launch_cmd(_chrome_cmd(args.home), "浏览器")
|
|
696
|
-
elif action_id == "files":
|
|
697
|
-
launch_cmd(_filemgr_cmd(args.home), "文件管理器")
|
|
698
|
-
elif action_id == "search":
|
|
699
|
-
launch_cmd(_search_cmd(args.home, args.assets), "搜索")
|
|
700
|
-
elif action_id == "new_folder":
|
|
701
|
-
folder_parent = _create_new_desktop_folder(args.home)
|
|
702
|
-
launch_cmd(_filemgr_cmd(folder_parent), "新建文件夹")
|
|
703
|
-
elif action_id == "show_desktop":
|
|
704
|
-
minimize_all_windows()
|
|
705
|
-
elif action_id == "refresh":
|
|
706
|
-
paint_desktop()
|
|
707
|
-
paint_topbar(force=True)
|
|
708
|
-
paint_dock()
|
|
709
|
-
|
|
710
|
-
paint_desktop()
|
|
711
|
-
paint_topbar(force=True)
|
|
712
|
-
paint_dock()
|
|
713
|
-
|
|
714
|
-
last_click: Dict[str, float] = {}
|
|
715
|
-
running = {"ok": True}
|
|
716
|
-
|
|
717
|
-
def _stop(*_a) -> None:
|
|
718
|
-
running["ok"] = False
|
|
719
|
-
|
|
720
|
-
signal.signal(signal.SIGTERM, _stop)
|
|
721
|
-
signal.signal(signal.SIGINT, _stop)
|
|
722
|
-
|
|
723
|
-
print(
|
|
724
|
-
f"iconlayer: unified desktop ({len(desktop_hits)} icons + {bar_h}px topbar + {DOCK_W}x{DOCK_H} dock + context menu) "
|
|
725
|
-
f"on {args.display} ({sw}x{sh})",
|
|
726
|
-
flush=True,
|
|
727
|
-
)
|
|
728
|
-
|
|
729
|
-
fd = dpy.fileno()
|
|
730
|
-
last_poll = time.monotonic()
|
|
731
|
-
|
|
732
|
-
while running["ok"]:
|
|
733
|
-
try:
|
|
734
|
-
if dpy.pending_events() == 0:
|
|
735
|
-
readable, _, _ = select.select([fd], [], [], 0.6)
|
|
736
|
-
now_m = time.monotonic()
|
|
737
|
-
if not readable:
|
|
738
|
-
if now_m - last_poll >= 1.0:
|
|
739
|
-
last_poll = now_m
|
|
740
|
-
paint_topbar(force=False)
|
|
741
|
-
continue
|
|
742
|
-
while dpy.pending_events() > 0 and running["ok"]:
|
|
743
|
-
ev = dpy.next_event()
|
|
744
|
-
if ev.type == X.Expose:
|
|
745
|
-
if ev.window.id == desktop_win.id and ev.count == 0:
|
|
746
|
-
paint_desktop()
|
|
747
|
-
elif ev.window.id == topbar_win.id and ev.count == 0:
|
|
748
|
-
paint_topbar(force=True)
|
|
749
|
-
elif ev.window.id == dock_win.id and ev.count == 0:
|
|
750
|
-
paint_dock()
|
|
751
|
-
elif ev.window.id == menu_win.id and ev.count == 0:
|
|
752
|
-
paint_menu()
|
|
753
|
-
elif ev.type == X.PropertyNotify:
|
|
754
|
-
if ev.atom in (a_client_list, a_active_win):
|
|
755
|
-
if ev.atom == a_active_win and menu_state["open"]:
|
|
756
|
-
close_menu()
|
|
757
|
-
paint_topbar(force=False)
|
|
758
|
-
elif ev.type == X.MotionNotify and ev.window.id == menu_win.id and menu_state["open"]:
|
|
759
|
-
py = ev.event_y
|
|
760
|
-
next_hover = -1
|
|
761
|
-
for row in menu_state["rows"]:
|
|
762
|
-
if row["y0"] <= py < row["y1"]:
|
|
763
|
-
next_hover = row["idx"]
|
|
764
|
-
break
|
|
765
|
-
if next_hover != menu_state["hover"]:
|
|
766
|
-
menu_state["hover"] = next_hover
|
|
767
|
-
paint_menu()
|
|
768
|
-
elif ev.type == X.LeaveNotify and ev.window.id == menu_win.id and menu_state["open"]:
|
|
769
|
-
if menu_state["hover"] != -1:
|
|
770
|
-
menu_state["hover"] = -1
|
|
771
|
-
paint_menu()
|
|
772
|
-
elif ev.type == X.ButtonPress:
|
|
773
|
-
if ev.window.id == menu_win.id:
|
|
774
|
-
if ev.detail == 1:
|
|
775
|
-
py = ev.event_y
|
|
776
|
-
for row in menu_state["rows"]:
|
|
777
|
-
if row["y0"] <= py < row["y1"]:
|
|
778
|
-
run_menu_action(row["id"])
|
|
779
|
-
break
|
|
780
|
-
else:
|
|
781
|
-
close_menu()
|
|
782
|
-
elif ev.window.id == desktop_win.id:
|
|
783
|
-
if ev.detail == 3:
|
|
784
|
-
open_menu(ev.root_x, ev.root_y)
|
|
785
|
-
elif ev.detail == 1:
|
|
786
|
-
if menu_state["open"]:
|
|
787
|
-
close_menu()
|
|
788
|
-
continue
|
|
789
|
-
px, py = ev.event_x, ev.event_y
|
|
790
|
-
for hit in desktop_hits:
|
|
791
|
-
if hit["x"] <= px < hit["x"] + hit["w"] and hit["y"] <= py < hit["y"] + hit["h"]:
|
|
792
|
-
key = hit["item"]["label"]
|
|
793
|
-
now_ms = time.time() * 1000.0
|
|
794
|
-
prev_ms = last_click.get(key, 0.0)
|
|
795
|
-
last_click[key] = now_ms
|
|
796
|
-
if now_ms - prev_ms <= args.double_click_ms:
|
|
797
|
-
last_click[key] = 0.0
|
|
798
|
-
launch_cmd(hit["item"]["cmd"], key)
|
|
799
|
-
break
|
|
800
|
-
else:
|
|
801
|
-
close_menu()
|
|
802
|
-
elif ev.window.id == topbar_win.id:
|
|
803
|
-
close_menu()
|
|
804
|
-
if ev.detail == 1:
|
|
805
|
-
px = ev.event_x
|
|
806
|
-
for hit in topbar_hits:
|
|
807
|
-
if hit["x0"] <= px <= hit["x1"]:
|
|
808
|
-
if hit["kind"] == "launch":
|
|
809
|
-
launch_cmd(hit["cmd"], hit["label"])
|
|
810
|
-
elif hit["kind"] == "window":
|
|
811
|
-
focus_or_toggle_window(hit["wid"], hit["active"])
|
|
812
|
-
break
|
|
813
|
-
elif ev.window.id == dock_win.id:
|
|
814
|
-
close_menu()
|
|
815
|
-
if ev.detail == 1:
|
|
816
|
-
px = ev.event_x
|
|
817
|
-
for hit in dock_hits:
|
|
818
|
-
if hit["x0"] <= px <= hit["x1"]:
|
|
819
|
-
launch_cmd(hit["cmd"], hit["label"])
|
|
820
|
-
break
|
|
821
|
-
now_m = time.monotonic()
|
|
822
|
-
if now_m - last_poll >= 1.0:
|
|
823
|
-
last_poll = now_m
|
|
824
|
-
paint_topbar(force=False)
|
|
825
|
-
except Exception: # noqa: BLE001
|
|
826
|
-
break
|
|
827
|
-
|
|
828
|
-
for w in (menu_win, dock_win, topbar_win, desktop_win):
|
|
829
|
-
try:
|
|
830
|
-
w.destroy()
|
|
831
|
-
except Exception: # noqa: BLE001
|
|
832
|
-
pass
|
|
833
|
-
try:
|
|
834
|
-
dpy.close()
|
|
835
|
-
except Exception: # noqa: BLE001
|
|
836
|
-
pass
|
|
837
|
-
return 0
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
if __name__ == "__main__":
|
|
841
|
-
sys.exit(main())
|