# dwl **Repository Path**: guyuming76/dwl ## Basic Information - **Project Name**: dwl - **Description**: 基于DWL的PR235 (https://github.com/djpohly/dwl/pull/235),调通了使用 fcitx5 进行中文输入。 在 fcitx-handwrite 分支之后,加入了自定义的 handwrite-unstable-v1 wayland 协议。 考虑到 dwl 项目的特点是简短,加上中文输入支持后明显会多出许多代码, 我就没在原 dwl 网站上提新的 PR。 - **Primary Language**: C/C++ - **License**: GPL-3.0 - **Default Branch**: 0.9_guyuming - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 2 - **Created**: 2022-04-11 - **Last Updated**: 2026-12-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # dwl(guyuming 定制版,基于上游 0.9) 本仓库是 [dwl](https://codeberg.org/dwl/dwl) 的个人定制分支 `0.9_guyuming`:以上游 **0.9** 为基础,把作者 在 `0.7cn` 分支上积累的定制按功能重新实现并整理成一串独立提交。上游 0.9 本身 已经把拼音输入法(IME)和录屏/共享(screenshare)合并进去了,所以这部分不再 保留本地魔改。 ## 本分支相对上游 0.9 增加了什么 **1. `dwl -h`:编译内置的快捷键速查 + 当前状态实时查询** `dwl -h`(或 `--help`)打印的快捷键表不是写死的文档,而是运行时从 `config.h` 的 `keys[]` / `buttons[]` 反推出来的,所以改完键位重新编译就自动同步。末尾 还会把**当前状态**打出来:当前在第几个工作区(tag)、下次按哪个键能切回来、 焦点窗口的 app_id / 标题 / 平铺(主区还是堆叠区)/ 浮动 / 全屏、它属于哪些 标签、本屏窗口数和主区宽度。这些数据不是读文件,而是 `dwl -h` 作为 Wayland 客户端连上正在运行的 dwl 实时查出来的。 **2. 把 tag 暴露成标准工作区(`ext-workspace-v1`)** 每台显示器一个 workspace group,每个 tag 一个 workspace,视图里可见的 tag 标 `active`、有紧急窗口的标 `urgent`,并支持 `activate` / `deactivate` 请求 (状态栏/面板点一下就切标签)。 **3. 标签 0(查看全部标签)下按 Super+t 跳到焦点窗口所在的标签** 不用状态栏时:`Super+0` 看全部窗口 → 挑一个 → `Super+t` 直接跳进它所在的标签。 **4. Super+Tab 切回上次访问的标签,但标签 0 不参与** 上游用两个 tagset 槽位对调实现“来回切换”,进过“查看全部标签”后 Super+Tab 会退回标签 0。这里每个显示器额外记住最近一次真正的标签视图,所以「标签 0 → Super+t 跳走」之后再按 Super+Tab 会回到进入标签 0 之前的那个标签。 **5. MOD+方向键定向切换焦点窗口** 左右在 master / stack 之间跳,上下在同一区域内循环,monocle 布局下退化成 顺序切换(替代原来的 `MOD+j` / `MOD+k`)。 **6. 手写输入(私有协议 `zwp_handwrite_v1`)** 手写识别程序作为 Wayland 客户端 bind 这个 global,识别出的字直接送进当前 焦点窗口的 text-input,和拼音输入法互不依赖。编译开关在 `config.mk` 的 `HANDWRITE`。 **7. 截图:两个脚本的分工** `dwl_MOD_PrtSc.sh` 和 `dwl_PrtSc.sh` 都由 `make install` 装到 `/usr/bin` (见 `config.mk` 的 `SHOTDIR`),一个给日常框选截图,一个专门用来截那些 一碰输入就消失的弹层: - `dwl_MOD_PrtSc.sh` —— `MOD+PrtSc`(Super+PrtSc):`slurp` 框选 + `grim`; `slurp` 会 map 全屏表面并抓走指针,所以它会打断 tooltip。 - `dwl_PrtSc.sh` —— `PrtSc` **单键**(不带修饰键):`grim` 整屏直抓,全程不发 任何输入事件,所以 GTK 应用的 tooltip / popup 不会消失。原理是 dwl 对命中绑定的 键既不转发按下也不转发松开;一旦加了修饰键,那个修饰键的按下会先被转发给客户端, tooltip 立刻隐藏 —— 这正是原先 `Alt+PrtSc` 截不到 tooltip 的原因。 两个脚本都显式存到家目录(脚本里 `dir=` 一行可改),命名 `20261202_014443.png`, 并把最后一张的路径写到 `/tmp/lastshot`。`dwl_PrtSc.sh` 还会追加 `/tmp/dwl_PrtSc.log`(判断绑定有没有生效时很有用)。 关于 `PrtSc` 的 keysym(踩过的坑,别再踩):它在 xkb 里的键类型是 `PC_ALT_LEVEL2`,**level0 = `Print`、level1 = `Sys_Req`,只有按住 Alt 才会落到 level1**。所以老配置里写死的 `WLR_MODIFIER_ALT + XKB_KEY_Sys_Req` 实际只能被 Alt 触发——`MOD+PrtSc` 当时「不起作用」不是 dwl 的锅。现在 `keypress()` 按 level0/1 分别取 keysym 匹配,写 `Print` 或 `Sys_Req` 都能触发,框选截图已改成 `MOD+PrtSc`。 **8. Xwayland 用 rootful 模式 + 我的启动脚本** 不启用 wlroots 内建的 rootless Xwayland,而是用 `Xwayland.sh` 在 foot 窗口里 起一个 rootful Xwayland(自动找空闲的 X 显示号),整个 X 会话作为一个 Wayland 窗口管理;`dwl.sh` / `dwlstart.sh` / `xdg_run_user` 是我用 seatd 启动 dwl 的 入口(含 pipewire、xdg-desktop-portal、fcitx5 的启动)。 腾讯会议(`/opt/wemeet`)在这套 rootful Xwayland 下的屏幕共享问题(对方黑屏、 一开共享就闪退)及完整修复原理,见 [wemeet-screenshare.md](wemeet-screenshare.md)。 **共享内容选哪个来源**(整个 dwl 全屏,还是只有 Xwayland 桌面)也由下面这个开关决定。 ### 腾讯会议共享屏幕:两种抓屏来源 wemeet 3.26.10(401) 有两条抓屏路径,靠环境变量 `WEMEET_XWAYLAND` 切换 (`/opt/wemeet/wemeetapp.sh` 默认在 Wayland 会话下把它置 1): | 模式 | 共享出去的内容 | |------|----------------| | **portal**(`WEMEET_XWAYLAND=1`,默认) | **整个 dwl 输出**:当前 tag 的所有 Wayland 窗口 + Xwayland 窗口 | | **X11 抓屏**(不设该变量) | **只有 Xwayland 桌面**(那个 rootful 窗口里的内容),与 dwl 当前在哪个 tag 无关 | 想"只共享 Xwayland 里那套 X 会话"就用 X11 抓屏模式启动。 本仓库根目录的 `wemeet` 就是为此写的启动器,**不随 `make install` 安装**(与 dwl 主程序无关),自己拷进 PATH 即可: ```sh install -m755 wemeet ~/.local/bin/wemeet wemeet # portal 抓屏:共享整个 dwl 画面(跟随当前 tag) wemeet --x11 # X11 抓屏:只共享 Xwayland 桌面(-x11 单横线也认) DISPLAY=:5 wemeet --x11 # 指定用哪套 rootful Xwayland ``` 它替你做三件事: 1. `DISPLAY` 为空时自动取「最近启动的那个 dwm」的显示号 —— dwl 里的 foot/alacritty 没有 `DISPLAY`,而 `wemeetapp.sh` 把 wemeet 强制成 `QT_QPA_PLATFORM=xcb`, 直接跑那个脚本只会打印一行 `wemeet:WemeetSatrt` 然后 SIGABRT(退出码 134); 2. 按 `--x11` 决定抓屏来源(见上表); 3. 检测到已有实例时提示先 `pkill`(wemeet 单实例)。 手动启动等价于: ```sh # wemeet 是单实例的:不先杀掉旧实例,新进程只会打印 WemeetSatrt/WemeetStop 立刻退出 pkill -f 'wemeetap[p]' # :N 换成你的 rootful Xwayland 显示号(Xwayland.sh 从 :5 起找空号,启动时会打印) env -u WAYLAND_DISPLAY DISPLAY=:6 XDG_SESSION_TYPE=x11 /opt/wemeet/wemeetapp.sh & ``` `XDG_SESSION_TYPE=x11` 会让 `wemeetapp.sh` 里 `if [ "$XDG_SESSION_TYPE" = "wayland" ]` 那段不成立,于是**不导出** `WEMEET_XWAYLAND`。想长期固定为 X11 抓屏,也可以直接注释掉 脚本里那行 `export WEMEET_XWAYLAND=1`(改完要重启 wemeet)。 判断当前走哪条路: ```sh p=$(ps -o pid=,cmd= -p $(pgrep -f 'bin/wemeetap[p]') | awk '$2=="/opt/wemeet/bin/wemeetapp"{print $1}') tr '\0' '\n' < /proc/$p/environ | grep WEMEET_XWAYLAND # 有输出=portal,没输出=X11 抓屏 ``` 注意事项: - **`LD_PRELOAD=/usr/local/lib/wemeet/libhook.so` 在两种模式下都必须保留**, 它是 wemeet 二进制补丁(接受 `RGBx`、R/B 字节交换)的一部分,去掉会一开共享就 `SIGSEGV`。 - X11 抓屏模式下 wemeet 自己的浮动工具条会被拍进画面(portal 模式也一样, 因为它在 Xwayland 窗口内部)。 - 两种模式都依赖打过补丁的 `/opt/wemeet`;补丁脚本在 `~/wemeet-screenshare-patch/` (`apply-wemeet-fix.sh` 幂等,wemeet 升级后重跑;字节不匹配会安全中止)。 - **portal 模式弹"请安装最新版本的 xdg-desktop-portal,或切换系统显示协议至 x11"**: 这不是 wemeet 的锅,而是 `xdg-desktop-portal` 里没有 `org.freedesktop.portal.ScreenCast` 接口。最常见的原因是它被 D-Bus「按需激活」成了裸环境(缺 `XDG_CURRENT_DESKTOP`), 于是匹配不上 `wlr.portal` 的 `UseIn=sway`,ScreenCast 后端整个缺失。两种解法: ```sh # ① 一劳永逸:显式指定后端,不再依赖 XDG_CURRENT_DESKTOP mkdir -p ~/.config/xdg-desktop-portal printf '[preferred]\ndefault=*\norg.freedesktop.impl.portal.ScreenCast=wlr\norg.freedesktop.impl.portal.Screenshot=wlr\n' \ > ~/.config/xdg-desktop-portal/portals.conf # 然后重启 portal(或重新登录): XDG_CURRENT_DESKTOP=sway XDG_SESSION_TYPE=wayland WAYLAND_DISPLAY=wayland-0 \ /usr/libexec/xdg-desktop-portal --replace --verbose 2>&1 | tee /tmp/portal.log & # ② 急着用:直接走 X11 抓屏,完全不需要 portal wemeet --x11 ``` 自检:`gdbus introspect --session --dest org.freedesktop.portal.Desktop \ --object-path /org/freedesktop/portal/desktop | grep ScreenCast` 应有输出。 ## 本地行为改动:“查看全部标签”(`Super+0`)是个特殊视图 `Super+0`(tagset == TAGMASK)下有两条规则,开关是 `config.h` 的 `viewall_force_tile`(设 0 回到上游行为): 1. **全屏窗口在这个视图里按普通平铺窗口显示**。否则一个全屏窗口就把整屏盖住, “看全部”就没意义了。窗口自己的全屏状态不变(不给客户端发 configure), 切回它自己的标签后自动恢复真全屏。 2. **布局强制用平铺**。即使当前布局是单窗(monocle)或浮动,在这里也能看到 所有窗口的排布。 细节:浮动窗口在这个视图里仍然浮动(平铺布局本来就不接管浮动窗口);`dwl -h` 和状态输出报告的是“实际显示状态”,即在这个视图里全屏窗口显示为“非全屏”。 ## 本地修复(上游 0.9 存在的问题) **全屏窗口盖住屏幕时,焦点却留在了被盖住的窗口上** 复现:标签 3 里把窗口 A 全屏 → `Super+0` 看全部标签 → `Super+1` 切到标签 1 (焦点落到窗口 B)→ 再 `Super+0`。这时屏幕上是全屏的 A,但焦点在看不见的 B 上,于是 `Super+e`、`Super+q` 等统统作用在 B 上,看起来像“对 A 无效”,必须 先用鼠标点一下 A。纯净上游 0.9 也能复现。 修法:`focustop()` 先找当前可见的全屏窗口(一个显示器同时只有一个全屏窗口 真正显示,且必在最上层),找不到才退化为原来的“fstack 里第一个可见窗口”。 顺带修好了 `arrange()` 里全屏黑底(`fullscreen_bg`)的开关判断。 ## 与上游的差异速查 | 文件 | 内容 | |------|------| | `help.h` | `dwl -h` 的快捷键速查生成 + 当前状态输出 | | `dwlquery.c` / `dwlquery.h` | `dwl -h` 作为 Wayland 客户端查询状态的实现(只被 `help.h` 用) | | `protocols/dwl-status-v1.xml` | 私有协议:暴露标准协议里没有窗口细节(浮动/全屏/在主区/布局…) | | `handwrite.h` | 手写输入协议(`zwp_handwrite_v1`)的合成器端实现 | | `protocols/handwrite-unstable-v1.xml` | 手写输入协议定义 | | `test_handwrite_protocol_client.c` | 手写协议的最小测试客户端 | | `dwl.c` | `ext-workspace-v1` 服务端、`viewprevtag`、`focusdirection`、`setlayout` 的跳转、`focustop()` 全屏修复、`-n`、带修饰键的按键调试日志 | | `client.h` | `isinmaster()`(判断窗口在主区还是堆叠区) | | `config.def.h` | `MODKEY` 用 Super、截图键、终端用 alacritty、方向键切焦点 | | `config.mk` | `HANDWRITE` 编译开关 | | `Xwayland.sh` / `dwl.sh` / `dwlstart.sh` / `dwl_MOD_PrtSc.sh` / `dwl_PrtSc.sh` / `xdg_run_user` | 我的启动与截图脚本(截图的这两个由 `make install` 装到 `/usr/bin`) | | `wemeet` | 腾讯会议启动器(自动补 `DISPLAY`、切换 portal / X11 抓屏;**不在 `make install` 里**) | ## 构建 需要 **wlroots 0.20**(上游 0.9 的要求): ```sh cp config.def.h config.h # config.h 不被 git 跟踪 make sudo make install # dwl → /usr/local/bin,截图脚本 → /usr/bin(SHOTDIR) ``` 改完 `config.h`(尤其是 `keys[]`)要重新 `make` 并重启 dwl。`dwl -h` 里的快捷键 速查表是从 `keys[]` / `buttons[]` **自动生成**的(见 `help.h`),不用手工同步。 手写输入默认开启;不需要就把 `config.mk` 里的 `HANDWRITE` 注释掉。 --- # dwl - dwm for Wayland(以下是上游 README 原文,未改动) # dwl - dwm for Wayland Join us on our [Discord server] Or Matrix: [#dwl-official:matrix.org] Or on our IRC channel: [#dwl on Libera Chat] dwl is a compact, hackable compositor for [Wayland] based on [wlroots]. It is intended to fill the same space in the Wayland world that [dwm] does in X11, primarily in terms of functionality, and secondarily in terms of philosophy. Like [dwm], dwl is: - Easy to understand, hack on, and extend with patches - One C source file configurable via `config.h` - Tied to as few external dependencies as possible ## Getting Started: ### Latest semi-stable [release] This is probably where you want to start. This builds against the [wlroots] versions currently shipping in major distributions. If your distribution's `wlroots` version is older, use an earlier dwl [release]. The `wlroots` version against which a given `dwl` release builds is specified with each release on the [release] page ### Development branch [main] Active development progresses on the `main` branch. The `main` branch is built against the latest release of [wlroots]. PRs should target this branch unless they depend on functionality that is not in the current release of `wlroots`. ### Preview branch [wlroots-next] The `wlroots-next` branch is built against the git version of [wlroots], which is unstable and changes frequently. PRs requiring functionality from the git version of `wlroots` should target this branch. ### Building dwl dwl has the following dependencies: - libinput - wayland - wlroots (compiled with the libinput backend) - xkbcommon - wayland-protocols (compile-time only) - pkg-config (compile-time only) dwl has the following additional dependencies if XWayland support is enabled: - libxcb - libxcb-wm - wlroots (compiled with X11 support) - Xwayland (runtime only) Install these (and their `-devel` versions if your distro has separate development packages) and run `make`. If you wish to build against a released version of wlroots (*you probably do*), use a [release] or a [0.x branch]. If you want to use the unstable development `main` branch, you need to use the git version of [wlroots]. To enable XWayland, you should uncomment its flags in `config.mk`. ## Configuration All configuration is done by editing `config.h` and recompiling, in the same manner as [dwm]. There is no way to separately restart the window manager in Wayland without restarting the entire display server, so any changes will take effect the next time dwl is executed. As in the [dwm] community, we encourage users to share patches they have created. Check out the [dwl-patches] repository! ## Running dwl dwl can be run on any of the backends supported by wlroots. This means you can run it as a separate window inside either an X11 or Wayland session, as well as directly from a VT console. Depending on your distro's setup, you may need to add your user to the `video` and `input` groups before you can run dwl on a VT. If you are using `elogind` or `systemd-logind` you need to install polkit; otherwise you need to add yourself in the `seat` group and enable/start the seatd daemon. When dwl is run with no arguments, it will launch the server and begin handling any shortcuts configured in `config.h`. There is no status bar or other decoration initially; these are instead clients that can be run within the Wayland session. Do note that the default background color is grey. This can be modified in `config.h`. If you would like to run a script or command automatically at startup, you can specify the command using the `-s` option. This command will be executed as a shell command using `/bin/sh -c`. It serves a similar function to `.xinitrc`, but differs in that the display server will not shut down when this process terminates. Instead, dwl will send this process a SIGTERM at shutdown and wait for it to terminate (if it hasn't already). This makes it ideal for execing into a user service manager like [s6], [anopa], [runit], [dinit], or [`systemd --user`]. Note: The `-s` command is run as a *child process* of dwl, which means that it does not have the ability to affect the environment of dwl or of any processes that it spawns. If you need to set environment variables that affect the entire dwl session, these must be set prior to running dwl. For example, Wayland requires a valid `XDG_RUNTIME_DIR`, which is usually set up by a session manager such as `elogind` or `systemd-logind`. If your system doesn't do this automatically, you will need to configure it prior to launching `dwl`, e.g.: export XDG_RUNTIME_DIR=/tmp/xdg-runtime-$(id -u) mkdir -p $XDG_RUNTIME_DIR dwl ### Status information Information about selected layouts, current window title, app-id, and selected/occupied/urgent tags is written to the stdin of the `-s` command (see the `STATUS INFORMATION` section in `_dwl_(1)`). This information can be used to populate an external status bar with a script that parses the information. Failing to read this information will cause dwl to block, so if you do want to run a startup command that does not consume the status information, you can close standard input with the `<&-` shell redirection, for example: dwl -s 'foot --server <&-' If your startup command is a shell script, you can achieve the same inside the script with the line exec <&- To get a list of status bars that work with dwl consult our [wiki]. ### (Known) Java nonreparenting WM issue Certain IDEs don't display correctly unless an environmental variable for Java AWT indicates that the WM is nonreparenting. For some Java AWT-based IDEs, such as Xilinx Vivado and Microchip MPLAB X, the following environment variable needs to be set before running the IDE or dwl: export _JAVA_AWT_WM_NONREPARENTING=1 ## Replacements for X applications You can find a [list of useful resources on our wiki]. ## Background dwl is not meant to provide every feature under the sun. Instead, like [dwm], it sticks to features which are necessary, simple, and straightforward to implement given the base on which it is built. Implemented default features are: - Any features provided by [dwm]/Xlib: simple window borders, tags, keybindings, client rules, mouse move/resize. Providing a built-in status bar is an exception to this goal, to avoid dependencies on font rendering and/or drawing libraries when an external bar could work well. - Configurable multi-monitor layout support, including position and rotation - Configurable HiDPI/multi-DPI support - Idle-inhibit protocol which lets applications such as mpv disable idle monitoring - Provide information to external status bars via stdout/stdin - Urgency hints via xdg-activate protocol - Support screen lockers via ext-session-lock-v1 protocol - Various Wayland protocols - XWayland support as provided by wlroots (can be enabled in `config.mk`) - Layer shell popups (used by Waybar) - Damage tracking provided by scenegraph API Given the Wayland architecture, dwl has to implement features from [dwm] **and** the xorg-server. Because of this, it is impossible to maintain the original project goal of 2000 SLOC and have a reasonably complete compositor with features comparable to [dwm]. However, this does not mean that the code will grow indiscriminately. We will try to keep the code as small as possible. Features under consideration (possibly as patches) are: - Protocols made trivial by wlroots Feature *non-goals* for the main codebase include: - Client-side decoration (any more than is necessary to tell the clients not to) - Client-initiated window management, such as move, resize, and close, which can be done through the compositor - Animations and visual effects ## Acknowledgements dwl began by extending the TinyWL example provided (CC0) by the sway/wlroots developers. This was made possible in many cases by looking at how sway accomplished something, then trying to do the same in as suckless a way as possible. Many thanks to suckless.org and the [dwm] developers and community for the inspiration, and to the various contributors to the project, including: - **Devin J. Pohly for creating and nurturing the fledgling project** - Alexander Courtis for the XWayland implementation - Guido Cella for the layer-shell protocol implementation, patch maintenance, and for helping to keep the project running - Stivvo for output management and fullscreen support, and patch maintenance Also, thanks to our current lead developers: - @thanatos - @guidocella [wlroots]: https://gitlab.freedesktop.org/wlroots [dwm]: https://dwm.suckless.org/ [`systemd --user`]: https://wiki.archlinux.org/title/Systemd/User [#dwl on Libera Chat]: https://web.libera.chat/?channels=#dwl [0.7-rc1]: https://codeberg.org/dwl/dwl/releases/tag/v0.7-rc1 [0.x branch]: https://codeberg.org/dwl/dwl/branches [anopa]: https://jjacky.com/anopa/ [dinit]: https://davmac.org/projects/dinit/ [dwl-patches]: https://codeberg.org/dwl/dwl-patches [list of useful resources on our wiki]: https://codeberg.org/dwl/dwl/wiki/Home#migrating-from-x [main]: https://codeberg.org/dwl/dwl/src/branch/main [wlroots-next]: https://codeberg.org/dwl/dwl/src/branch/wlroots-next [release]: https://codeberg.org/dwl/dwl/releases [runit]: http://smarden.org/runit/faq.html#userservices [s6]: https://skarnet.org/software/s6/ [wlroots]: https://gitlab.freedesktop.org/wlroots/wlroots/ [wiki]: https://codeberg.org/dwl/dwl/wiki/Home#compatible-status-bars [Discord server]: https://discord.gg/jJxZnrGPWN [Wayland]: https://wayland.freedesktop.org/ [#dwl-official:matrix.org]: https://matrix.to/#/#dwl-official:matrix.org