LGUG2Z/komorebi

GitHub: LGUG2Z/komorebi

一款运行于 Windows 10+ 的平铺窗口管理器,通过 CLI 和键盘快捷键实现自动化的窗口布局与多工作空间管理。

Stars: 14168 | Forks: 312

# komorebi Windows 的平铺窗口管理。

Tech for Palestine GitHub Workflow Status GitHub all releases GitHub commits since latest release (by date) for a branch Active Individual Commercial Use Licenses Discord GitHub Sponsors Ko-fi Notado Feed YouTube

![screenshot](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/0bdbdb43eb060245.png) ## 注意:使用注册于移动设备管理 (MDM) 设备的学生 您的使用仍受 [Komorebi 许可证 2.0.0](./LICENSE.md) 约束。 您可以使用与我提交签名相同的邮箱地址(在 GitHub 上的任何提交 URL 后添加 `.patch` 即可找到),从您所属机构的邮箱向我发送邮件,主题为“komorebi - student with an MDM device”,我将能够移除面向企业用户的启动画面,这些用户的使用受[个人商业使用许可证](https://lgug2z.com/software/komorebi)约束。 目前这是一个手动过程——大多数情况下这不会超过 12 小时,过程完成后您将收到我的邮件回复。 如果您在 24 小时内没有收到回复,可以在 Discord 上联系我。 ## 注意:意外的移动设备管理 (MDM) 检测提示 您很可能无意中将设备注册到了“自带设备”(BYOD) MDM 中。您可以通过运行 `dsregcmd /status` 来确认是否属于这种情况,然后采取适当的步骤移除 MDM 配置文件并重新获得系统的完全控制权。 如果您需要帮助,可以在 Discord 上提问。 ## 注意:komorebi for Mac komorebi for Mac 位于[这里](https://github.com/LGUG2Z/komorebi-for-mac) :) ## 概述 _komorebi_ 是一个平铺窗口管理器,作为 Microsoft Windows 10 及以上版本中 [Desktop Window Manager](https://docs.microsoft.com/en-us/windows/win32/dwm/dwm-overview) 的扩展运行。 _komorebi_ 允许您通过 CLI 控制应用程序窗口、虚拟工作空间和显示器,该 CLI 可与 [`whkd`](https://github.com/LGUG2Z/whkd) 和 [AutoHotKey](https://github.com/Lexikos/AutoHotkey_L) 等第三方软件配合使用,以设置用户自定义的键盘快捷键。 _komorebi_ 旨在默认情况下对操作系统和桌面环境进行*尽可能少的修改*。用户可以在自己的 _komorebi_ 配置文件中自由进行此类修改,但在可预见的未来,这些修改将保持选择加入且默认关闭的状态。 请参阅[文档](https://lgug2z.github.io/komorebi)以获取有关如何[安装](https://lgug2z.github.io/komorebi/installation.html)和[配置](https://lgug2z.github.io/komorebi/example-configurations.html) _komorebi_、[常用工作流](https://lgug2z.github.io/komorebi/common-workflows/komorebi-config-home.html)、完整的[配置模式参考](https://komorebi.lgug2z.com/schema)以及完整的 [CLI 参考](https://lgug2z.github.io/komorebi/cli/quickstart.html)的说明。 ## 个人使用许可 `komorebi` 是[教育源代码软件](https://lgug2z.com/articles/educational-source-software/)。 `komorebi` 根据 [Komorebi 2.0.0 许可证](https://github.com/LGUG2Z/komorebi-license)授权,该许可证是 [PolyForm Strict 1.0.0 许可证](https://polyformproject.org/licenses/strict/1.0.0)的一个分支。总的来说,这意味着除了重新分发或分发基于该软件的新作品(即硬分叉)外,您可以出于个人目的自由地对 `komorebi` 做任何想做的事。 任何人都可以自由地对 `komorebi` 进行分叉,进行旨在个人使用或通过 pull request 整合回上游的更改。 [Komorebi 2.0.0 许可证](https://github.com/LGUG2Z/komorebi-license)不允许任何形式的商业使用(即在工作中使用 `komorebi`)。 ## 商业使用许可 对于那些希望在工作中使用 `komorebi` 的用户,提供专门的个人商业使用许可证。 个人商业使用许可证仅在有效的付费许可证订阅期限内,为获得许可的个人增加“商业使用”作为“允许用途”。[Komorebi 许可证](https://github.com/LGUG2Z/komorebi-license)中的所有条款和限制继续适用。 有关个人商业使用许可证的更多信息、定价和购买链接[可以在这里找到](https://lgug2z.com/software/komorebi)。 # 安装 我们提供了一份[详细的安装和快速入门指南](./LICENSE.md),展示了如何使用 `scoop`、`winget` 或从源代码构建开始使用。 [![观看快速入门演示视频](https://img.youtube.com/vi/MMZUAtHbTYY/hqdefault.jpg)](https://www.youtube.com/watch?v=MMZUAtHbTYY) # 与 Fancy Zones 的比较 社区成员 [Olge](https://www.youtube.com/@polle5555) 制作了一个精彩的视频,比较了 Windows 11 的默认窗口管理功能、Fancy Zones 和 komorebi。 如果您不熟悉平铺窗口管理器,或者您正在了解 komorebi 并想知道“这与 Fancy Zones 有什么不同?🤔”,这个短视频将回答您的大部分问题。 [![观看比较视频](https://img.youtube.com/vi/0LCbS_gm0RA/hqdefault.jpg)](https://www.youtube.com/watch?v=0LCbS_gm0RA) # 演示 [@amnweb](https://github.com/amnweb) 展示了在 Windows 11 上运行的 _komorebi_ `v0.1.28`,启用了窗口边框、非活动窗口透明度和动画,并使用了通过 _komorebi_ 的[窗口管理器事件订阅](https://github.com/LGUG2Z/komorebi?tab=readme-ov-file#window-manager-event-subscriptions)集成的自定义状态栏。 https://github.com/LGUG2Z/komorebi/assets/13164844/21be8dc4-fa76-4f70-9b37-1d316f4b40c2 [@haxibami](https://github.com/haxibami) 展示了在 Windows 11 上运行的 _komorebi_,其中包含终端模拟器、Web 浏览器和代码编辑器。原视频可以在[这里](https://twitter.com/haxibami/status/1501560766578659332)查看。 https://user-images.githubusercontent.com/13164844/163496447-20c3ff0a-c5d8-40d1-9cc8-156c4cebf12e.mp4 [@aik2mlj](https://github.com/aik2mlj) 展示了在 Windows 11 上运行的 _komorebi_,包含多个工作空间、终端模拟器、Web 浏览器,以及启用了 _komorebi_ 工作空间小部件的 [yasb](https://github.com/DenBot/yasb) 状态栏。原视频可以在[这里](https://zhuanlan.zhihu.com/p/455064481)查看。 https://user-images.githubusercontent.com/13164844/163496414-a9cde3d1-b8a7-4a7a-96fb-a8985380bc70.mp4 ## 提交规范 - 展平所有 `use` 语句 - 在提交之前运行 `cargo +stable clippy` 并确保已解决所有 lints 和建议 - 在提交之前运行 `cargo +nightly fmt --all` 以确保格式一致 - 配合 [Commitizen CLI](https://github.com/commitizen/cz-cli#conventional-commit-messages-as-a-global-utility) 使用 `git cz` 来准备提交消息 - 在您的提交消息正文中**至少**提供一两句话或段落,描述您对所提交更改的思考过程 ## PR 应仅包含单个功能或错误修复 审查涉及多个不相关功能和代码库部分的 pull request 是非常困难的。 请不要提交这样的 pull request;您将被要求将它们拆分为更小的 PR,每次只处理一个功能或错误修复。 如果您正在处理多个功能和错误修复,我建议您从 `master` 切出一个名为 `local-trunk` 的分支,并保持该分支更新,然后将您正在处理的各个独立分支变基到该分支上,如果您想一起测试它们或创建一个集成了所有内容的构建。 ## 对代码库的重构必须事先获得批准 `komorebi` 是一个成熟的代码库,具有在近五年中有机发展起来的内部一致性和结构。 有[无数小时的现场编程视频](https://youtube.com/@LGUG2Z)展示了在这个项目上的工作,并向新贡献者展示了如何完成从实现新的 `komorebic` 命令等基本任务到通过制造商硬件标识符和显卡端口区分显示器等所有工作。 对代码库结构的重构不会掉以轻心,需要事先讨论和批准。 在收到明确批准或请求之前,请不要开始重构代码库并期望您的更改会被整合。 同样,在实现功能和修复错误时,请尽可能遵守代码库的结构,不要将其作为顺便进行一些“重构”的机会。 如果功能请求和错误修复淹没在对代码库结构的大规模更改中,那么审查 PR 将变得极其困难。 ## 对面向用户界面的破坏性更改是不可接受的 这包括但不限于: - 所有 `komorebic` 命令 - `komorebi.json` 模式 - [`komorebi-application-specific-configuration`](https://github.com/LGUG2Z/komorebi-application-specific-configuration) 模式 任何用户都不应发现在升级到新版本的 `komorebi` 后,他们的配置文件已停止工作。 通常情况下,有一些方法可以将最初看起来需要破坏面向用户界面的更改重新表述为增量更改。 为了获得一些灵感,请查看[这次提交](https://github.com/LGUG2Z/komorebi/commit/e7d928a065eb63bb4ea1fb864c69c1cae8cc763b),它增加了用户在 `komorebi.json` 中以 Hex 格式指定颜色(与 RGB 并存)的能力。 还有一个适当的流程,用于优雅、非破坏性地弃用不再需要的配置选项。 # 开发 如果您使用 IntelliJ,您应该启用以下设置,以确保 IDE 能够识别宏生成的代码以进行补全和导航: - 在 "Settings > Langauges & Frameworks > Rust" 下将 `Expand declarative macros` 设置为 `Use new engine` - 启用以下实验性功能: - `org.rust.cargo.evaluate.build.scripts` - `org.rust.macros.proc` # 日志和调试 来自 `komorebi` 的日志将附加到 `%LOCALAPPDATA%/komorebi/komorebi.log`;该文件永远不会轮换或覆盖,因此它会不断增长,直到用户将其删除。 每当运行 `komorebic stop` 命令或直接向 `komorebi` 发送 Ctrl-C 信号时,`komorebi` 进程都会确保在终止前恢复所有隐藏的窗口。 但是,如果您曾经遇到窗口被隐藏且无法恢复的情况,`komorebi` 已知的窗口句柄列表会存储在 `%LOCALAPPDATA%/komorebi//komorebi.hwnd.json` 中并持续更新。 ## 恢复窗口 运行 `komorebic restore-windows` 将读取窗口句柄列表并强制恢复它们,无论主 `komorebi` 进程是否正在运行。 ## Panic 和死锁 如果 `komorebi` 曾经停止响应,这很可能是由于 panic 或死锁造成的。如果是 panic,这将记录在日志中。如果是死锁,日志中不会有任何错误,但进程和日志将显示为冻结状态。 如果您认为自己遇到了死锁,可以使用 `--features deadlock_detection` 编译 `komorebi` 并尝试再次重现死锁。这将每 5 秒在后台检查一次死锁,如果发现死锁,相关信息将出现在日志中,可以在提交 issue 时分享。 # 窗口管理器状态和集成 可以使用 `komorebic state` 命令查询窗口管理器的当前状态,该命令返回 `State` 结构体的 JSON 表示。 这也可以被轮询以在其之上构建进一步的集成和小部件。 # 窗口管理器事件订阅 ## 命名管道 (Named Pipes) 可以使用 [Named Pipes](https://docs.microsoft.com/en-us/windows/win32/ipc/named-pipes) 订阅 `komorebi` 处理的每个 `WindowManagerEvent` 和 `SocketMessage` 的通知。 首先,您的应用程序必须创建一个命名管道。创建命名管道后,运行以下命令: ``` komorebic.exe subscribe-pipe ``` 请注意,您不必包含命名管道的完整路径,只需包含名称。 如果命名管道存在,`komorebi` 将开始推送已成功处理的事件和消息的 JSON 数据: ``` {"event":{"type":"AddSubscriber","content":"yasb"},"state":{}} {"event":{"type":"FocusWindow","content":"Left"},"state":{}} {"event":{"type":"FocusChange","content":["SystemForeground",{"hwnd":131444,"title":"komorebi – README.md","exe":"idea64.exe","class":"SunAwtFrame","rect":{"left":13,"top":60,"right":1520,"bottom":1655}}]},"state":{}} {"event":{"type":"MonitorPoll","content":["ObjectCreate",{"hwnd":5572450,"title":"OLEChannelWnd","exe":"explorer.exe","class":"OleMainThreadWndClass","rect":{"left":0,"top":0,"right":0,"bottom":0}}]},"state":{}} {"event":{"type":"FocusWindow","content":"Right"},"state":{}} {"event":{"type":"FocusChange","content":["SystemForeground",{"hwnd":132968,"title":"Windows PowerShell","exe":"WindowsTerminal.exe","class":"CASCADIA_HOSTING_WINDOW_CLASS","rect":{"left":1539,"top":60,"right":1520,"bottom":821}}]},"state":{}} {"event":{"type":"FocusWindow","content":"Down"},"state":{}} {"event":{"type":"FocusChange","content":["SystemForeground",{"hwnd":329264,"title":"den — Mozilla Firefox","exe":"firefox.exe","class":"MozillaWindowClass","rect":{"left":1539,"top":894,"right":1520,"bottom":821}}]},"state":{}} {"event":{"type":"FocusWindow","content":"Up"},"state":{}} {"event":{"type":"FocusChange","content":["SystemForeground",{"hwnd":132968,"title":"Windows PowerShell","exe":"WindowsTerminal.exe","class":"CASCADIA_HOSTING_WINDOW_CLASS","rect":{"left":1539,"top":60,"right":1520,"bottom":821}}]},"state":{}} ``` 然后,您可以过滤 `type` 键以侦听您感兴趣的事件。有关可能的通知类型的完整列表,请参阅 `komorebi` 中的 `WindowManagerEvent` 和 `komorebi::core` 中的 `SocketMessage` 的枚举变体。 以下是如何在 `nodejs` 中使用命名管道订阅和过滤事件的示例。 ``` const { exec } = require("child_process"); const net = require("net"); const pipeName = "\\\\.\\pipe\\komorebi-js"; const server = net.createServer((stream) => { console.log("Client connected"); // Every time there is a workspace-related event, let's log the names of all // workspaces on the currently focused monitor, and then log the name of the // currently focused workspace on that monitor stream.on("data", (data) => { let json = JSON.parse(data.toString()); let event = json.event; if (event.type.includes("Workspace")) { let monitors = json.state.monitors; let current_monitor = monitors.elements[monitors.focused]; let workspaces = monitors.elements[monitors.focused].workspaces; let current_workspace = workspaces.elements[workspaces.focused]; console.log( workspaces.elements .map((workspace) => workspace.name) .filter((name) => name !== null) ); console.log(current_workspace.name); } }); stream.on("end", () => { console.log("Client disconnected"); }); }); server.listen(pipeName, () => { console.log("Named pipe server listening"); }); const command = "komorebic subscribe-pipe komorebi-js"; exec(command, (error, stdout, stderr) => { if (error) { console.error(`Error executing command: ${error}`); return; } }); ``` ## Unix Domain Sockets 可以使用 [Unix Domain Sockets](https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/) 订阅 `komorebi` 处理的每个 `WindowManagerEvent` 和 `SocketMessage` 的通知。 UDS 也是 `komorebi` 和 `komorebic` 之间唯一的通信模式。 首先,您的应用程序必须在 `$ENV:LocalAppData\komorebi` 中创建一个套接字。创建套接字后,运行以下命令: ``` komorebic.exe subscribe-socket ``` 如果套接字存在,komorebi 将开始推送已成功处理的事件和消息的 JSON 数据,如上面的命名管道部分中的示例所示。 ## Rust 客户端 从 `v0.1.22` 开始,可以使用 `komorebi-client` crate 在 Rust 代码库中订阅 `komorebi` 处理的每个 `WindowManagerEvent` 和 `SocketMessage` 的通知。 以下是如何在基本 Rust 应用程序中使用 `komorebi-client` 的简单示例。 ``` // komorebi-client = { git = "https://github.com/LGUG2Z/komorebi" } use anyhow::Result; use komorebi_client::Notification; use komorebi_client::NotificationEvent; use komorebi_client::UnixListener; use komorebi_client::WindowManagerEvent; use std::io::BufRead; use std::io::BufReader; use std::io::Read; pub fn main() -> anyhow::Result<()> { let socket = komorebi_client::subscribe(NAME)?; for incoming in socket.incoming() { match incoming { Ok(data) => { let reader = BufReader::new(data.try_clone()?); for line in reader.lines().flatten() { let notification: Notification = match serde_json::from_str(&line) { Ok(notification) => notification, Err(error) => { log::debug!("discarding malformed komorebi notification: {error}"); continue; } }; // match and filter on desired notifications } } Err(error) => { log::debug!("{error}"); } } } } ``` 一个实际案例可以在 [komokana](https://github.com/LGUG2Z/komokana/blob/feature/komorebi-uds/src/main.rs) 中找到。 ## 订阅事件通知模式 可以使用 `komorebic notification-schema` 命令生成发送给订阅者的事件通知的 [JSON Schema](https://json-schema.org/)。此命令的输出可以重定向到剪贴板或文件,可与 [Quicktype](https://app.quicktype.io/) 等服务一起使用,以生成不同编程语言的类型定义。 ## 通过 TCP 通信 可以选择使用 `--tcp-port=N` 志在您选择的端口上公开 TCP 监听器。如果未向 `komorebi` 或 `komorebic start` 提供此标志,则不会创建任何 TCP 监听器。 创建后,您的客户端可以像 `komorebic` 那样向 `komorebi` 发送任何 [SocketMessage](https://github.com/LGUG2Z/komorebi/blob/master/komorebi/src/core/mod.rs#L37)。 如果您想创建自己的 `komorebic` 替代品,其中包含脚本和各种中间件层,或者如果您想将 `komorebi` 与[自定义输入处理程序](https://github.com/LGUG2Z/komorebi/issues/176#issue-1302643961)集成,则可以使用此功能。 如果客户端发送无法识别的消息,它将被断开连接,并且必须在尝试再次通信之前重新连接。 ## Socket 消息模式 可以使用 `komorebic socket-schema` 命令生成用于向 `komorebi` 发送指令的 socket 消息的 [JSON Schema](https://json-schema.org/)。此命令的输出可以重定向到剪贴板或文件,可与 [Quicktype](https://app.quicktype.io/) 等服务一起使用,以生成不同编程语言的类型定义。 # 致谢 - 首先,感谢我的妻子,既为这个项目命名,也感谢她在其永无止境的开发过程中的耐心 - 感谢 [@sitiom](https://github.com/sitiom) [成为模范的开源社区领导者](https://jeezy.substack.com/p/the-open-source-contributions-i-appreciate) - 感谢在我之前开发的 [nog](https://github.com/TimUntersberger/nog) 开发者,他们的工作教会了我无法报答的一切 - 感谢 [GlazeWM](https://github.com/lars-berger/GlazeWM) 的开发者,与我一起推动 Windows 上平铺窗口管理的边界,并拥有极佳的合作精神 - 感谢 [@Ciantic](https://github.com/Ciantic) 帮助我将[隐藏的虚拟桌面隐藏功能](https://github.com/Ciantic/AltTabAccessor/issues/1)带到 `komorebi`
标签:GUI, Homebrew安装, Rust, Windows桌面增强, WM, 可视化界面, 工作流优化, 平铺式窗口, 效率工具, 桌面布局, 桌面环境, 桌面自动化, 窗口管理器, 端点可见性, 网络流量审计, 通知系统, 键盘操作