Skip to content

feat(window): delegate interactive move and resize to the compositor - #91

Merged
sudoevolve merged 2 commits into
sudoevolve:devfrom
Linductor-alkaid:feat/window-native-move
Oct 10, 2026
Merged

sudoevolve merged 2 commits into
sudoevolve:devfrom
Linductor-alkaid:feat/window-native-move

Conversation

@Linductor-alkaid

Copy link
Copy Markdown
Contributor

问题

  • 复现方式或用户需求:见 X11:无边框窗口逐帧 glfwSetWindowPos 拖动被 WM 钳制在屏幕内;Wayland 构建无法拖动 #89(Ubuntu 24.04 / GNOME 46 Wayland + XWayland 实测)。.decorated(false) 应用按常规方式实现标题栏拖动(按下记录原点、拖动中每帧 glfwSetWindowPos),窗口跟随指针但到达任意屏幕边缘就被卡住,永远无法像原生标题栏拖动那样拖出屏幕;同样的循环在原生 Wayland GLFW 构建下完全无效。
  • 根因:每帧 XMoveWindow 以客户端 ConfigureRequest 到达 WM,Mutter 的 constrain_fully_onscreen(PRIORITY_ENTIRELY_VISIBLE_ON_WORKAREA)只豁免 is_user_action 的交互式移动,把程序化定位推回工作区;Wayland 下客户端定位被协议禁止(_glfwSetWindowPosWayland 是 no-op)。缺失的是把交互式拖动交给合成器的能力。

修改

  • 实现方案:core::window 新增 beginWindowMove(Handle) / beginWindowResize(Handle, WindowResizeEdge),经 include/eui/window.h 暴露。X11 上发送 EWMH _NET_WM_MOVERESIZE(direction 8 = MOVE;WindowResizeEdge 枚举值与 EWMH SIZE_* 0-7 一致;source indication 1 = application;指针根坐标用 XQueryPointer 获取,发送前按规范 XUngrabPointer 释放隐式 grab)。libX11 经 dlopen 加载(函数级静态缓存),与后端既有 X11 探测方式一致,所有构建配置不新增链接依赖。GLFW 分支仅在运行平台为 X11 时启用(GLFW 3.4 的 glfwGetPlatform();3.3 头缺失该 API 时按编译期平台假定 X11);SDL2 分支经 SDL_SysWMinfo 取 display/window。其余平台/后端返回 false,调用方保留原有程序化回退。
  • 为什么符合简单、快速、易上手:两个无状态函数 + 一个 header-only dlopen helper;不改变任何默认行为(不调用即无差异);应用侧一行接入,window_controls_viewer fixture 新增 "Compositor move / Resize left / Resize bottom right" 按钮即可交互验证。

影响

  • 修改/新增/删除文件数:6 修改、1 新增(core/window/x11_moveresize.h)
  • 代码净增行数:+256,-0
  • 仓库追踪内容净增体积:约 8 KiB
  • 新增依赖或资源:无(运行时 dlopen libX11,无构建期链接变化)

本机环境

  • OS:Ubuntu 24.04(GNOME 46 Wayland 会话 + XWayland,Mutter 46.2)
  • CPU:Intel Core Ultra 5 225H
  • GPU:Intel Arrow Lake-P 核显
  • 编译器:g++ 13.3.0(库以 -std=gnu++17 -Os -fno-exceptions -fno-rtti 消费者配置编译)

验证

  • GLFW + OpenGL:Release 构建和测试通过(独立构建目录;ctest -L unit 25/25,DISPLAY=:0 ctest -L probe 8/8)
  • SDL2 + OpenGL:本机未执行(缺 libsdl2-dev,环境无法安装;SDL2 分支改动仅 SDL_SysWMinfo 取句柄 + 同一 helper,待 CI 覆盖)
  • GLFW + Vulkan:本机未执行(缺 libvulkan-dev / glslang-tools;本 PR 不触碰渲染路径)
  • SDL2 + Vulkan:本机未执行(同上)
  • 已运行与改动相关的示例或 fixture(window_controls_viewer 新增按钮;真机 GNOME 会话手动点击验证按钮反馈与状态文案)
  • Bug 修复包含回归测试,或已解释无法添加的原因:WM 交互式拖动无法在 headless 单测中复现(需要真实 X server + 窗口管理器 + 真实输入设备),以 fixture 按钮 + 真机会话验收;自动化覆盖需 xvfb + WM harness,超出本 PR 范围
  • 性能声明包含修改前后数据和复现方法:不涉及

备注

  • 本机 GNOME Wayland 会话的合成输入(XTEST)无法触发 mutter 的窗口拖动机制(对照实验:同一序列对系统内 Chromium CSD 窗口同样无效,而 _NET_WM_STATE 等根窗口消息生效),因此 _NET_WM_MOVERESIZE 的真实鼠标端到端行为请维护者以真机拖动自绘标题栏验收;该协议路径即 GTK/Chromium CSD 的标准做法。
  • glfwGetX11Display() 为无参 API(bundled GLFW 3.4),返回库全局 display。

Undecorated-window drags built on per-frame glfwSetWindowPos arrive at the
window manager as ConfigureRequests and get clamped into the workarea (Mutter
constrain_fully_onscreen), and cannot work at all on native Wayland. Expose
beginWindowMove/beginWindowResize, which send the EWMH _NET_WM_MOVERESIZE
message (libX11 via dlopen) so the WM runs the interactive move: partial
off-screen placement and native snapping included. Platforms without support
return false so callers keep their programmatic fallback.

Issue: sudoevolve#89
The helper lives in core::window::detail; unqualified calls only resolved by
accident of branch layout and broke consumer builds that compile the library
with stricter flags (gnu++17, -fno-exceptions).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants