MonitorBar

command module
v1.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 31 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

MonitorBar

macOS 菜单栏 / Windows 托盘里的显示器管理工具,一份 Go 代码,两端原生界面。
A menu bar (macOS) and tray (Windows) app to manage your monitor — English

Listed on Awesome MyGo

概览 分辨率 屏幕时间

为什么做这个

REDMI 显示器不支持 DDC/CI。

Mac 上常见的显示器工具(MonitorControl、BetterDisplay、Lunar 等)都靠 DDC/CI 控制显示器,所以在 REDMI 显示器上切换不了输入源,也调不了音量。

不过 REDMI 显示器内置澎湃 OS,开机时会在局域网提供一个遥控接口。MonitorBar 通过这个接口切换输入源(包括 DP 和 USB-C)、调节音量,不依赖 DDC/CI。软件调光、色温、分辨率、屏幕时间这些通用功能也一起做了进去,并且有 Mac 和 Windows 两个版本:两台电脑接在同一台显示器上时,在任意一台上都能一键切到另一台。

MonitorBar 只在 REDMI 显示器 G Pro 27U 2026 上测试过,不保证在你的显示器上能正常工作:不同型号的接口、信号源编号可能不一样。如果不能用,可以借助 AI 编程工具来适配:先运行 MonitorBar --probe 看看它识别到了什么,再让 AI 参照下面的适配其他显示器一节修改代码。

功能

分页 功能
概览 当前分辨率与刷新率、切换输入源、软件亮度、显示器音量、场景(日间 / 阅读 / 观影 / 夜间)
画面 场景、跟随 MacBook 内屏亮度、按时间自动切换白天 / 夜晚场景、色温(减少蓝光)、一键恢复、亮度与音量快捷键
分辨率 一键切换 4K 160Hz / 1080p 320Hz(澎湃 OS 双模显示器)、刷新率切换,HiDPI(仅 macOS)与标准分辨率列表
屏幕时间 今日亮屏与使用时长,最近 7 天柱状图
  • 切换输入源、调音量不需要 DDC/CI:澎湃 OS 显示器(如 REDMI 显示器 G Pro 27U 2026)在局域网提供遥控接口,MonitorBar 自动发现并使用它。Mac 和 Windows 接在同一台显示器的不同接口上时,两边都能一键切到对方。
  • 一键切换 320Hz 竞技模式:G Pro 27U 这类双模显示器在 4K 160Hz 和 1080p 320Hz 之间切换要换 EDID,原本只能在显示器菜单里操作。连上澎湃 OS 局域网接口时,「分辨率」页一键切换,不用碰显示器;切换后系统会在几秒内重新识别显示器。
  • 支持 DDC/CI 的显示器:自动用 DDC/CI 调硬件背光,切换输入源、调音量,并显示对比度、锐度、RGB 增益等显示器回应的设置。
  • 软件调光与色温通过显卡的 Gamma 表实现,任何连接线、任何显示器都能用。
  • 组合亮度(支持 DDC/CI 的显示器):一个滑块管到底,50% 以上调硬件背光,50% 以下背光停在最低、改用软件调光继续压暗,比显示器自身的最低亮度更暗。
  • 快捷键:默认 ⌃⌥↑ / ⌃⌥↓ 调亮度、⌃⌥⇧↑ / ⌃⌥⇧↓ 调音量(Windows 上是 Ctrl+Alt),在「画面」页点一下就能录制新的组合键,或按 Delete 清除;F1–F12 可以单独作为快捷键。显示器的每个输入源也可以录制一个快捷键(默认未设置),按下即切换。「静音 / 取消静音」同样可以录制(比如 F10),再按一次恢复静音前的音量。
  • 接管键盘亮度、音量键(macOS,高级选项):打开后不按 fn,直接用键盘上的亮度键调外接显示器;声音输出到显示器时,音量键调它的音量。需要在「隐私与安全性 → 辅助功能」中允许 MonitorBar;MacBook 内屏的亮度键照常生效,开启「跟随内屏亮度」时亮度键交给跟随功能。
  • 跟随内屏亮度(MacBook + 支持 DDC/CI 的外接显示器):内屏开启 macOS 自动亮度时,外接显示器的背光随之平滑调节,可设定外接亮度范围;手动调整会保留到内屏亮度下次变化。
  • 多显示器:接了两台及以上显示器时,面板顶部可以切换要管理的显示器,每台各自记住亮度、色温和局域网遥控;打开「同步」后,亮度、色温、场景、音量、静音和切换输入源(含快捷键)同时作用于所有显示器,适合两台显示器一起切到另一台电脑。两台同型号的澎湃 OS 显示器无法自动区分,配对不对时在「⋯ → 局域网遥控」里改。
  • 自定义场景:点「场景」卡片右上角的「+」,把当前亮度和色温保存成场景(最多 8 个),在「画面 → 我的场景」中重命名或删除;自动切换的白天、夜晚场景也可以选自定义场景。
  • 自动切换:在「画面」里打开后,到了设定的白天、夜晚开始时间就自动切换到对应场景(默认 07:00「日间」、19:00「夜间」,场景可选)。只在时段交替时切换,中途的手动调整会保留到下一次交替。
  • 自动更新:定期检查 GitHub 上的新版本,在面板底部提示,一键下载并重启;更新包经签名校验,只下载变化的部分。
  • 显示器不支持的功能不会出现在界面上。
  • 多语言:简体中文和英文,跟随系统语言,也可在「⋯ → 语言」中切换。文案在 locales/ 下(en.json 为源语言),改动后运行 go tool mygo generate 重新生成 catalog_gen.go。
  • 单个可执行文件,无 webview,空闲时不占 CPU;中文界面,深色主题。

普通显示器也能用

不是澎湃 OS、也不支持 DDC/CI 的显示器同样可以用 MonitorBar,只是功能少一些:

显示器 可用 不可用
澎湃 OS 显示器 输入源、音量、软件调光、色温、场景、分辨率、屏幕时间 硬件背光(除非同时支持 DDC/CI)
支持 DDC/CI 的显示器 全部功能,亮度调的是硬件背光 —
两者都不支持的普通显示器 软件调光、色温、场景与自动切换、分辨率与刷新率、屏幕时间 切换输入源、调音量、硬件背光、跟随内屏亮度

软件调光只是让画面变暗,背光亮度不变,所以调得很暗时对比度会下降。不确定显示器支持哪些通道时,运行 MonitorBar --probe 查看。

安装

从 Releases 或 CI 产物 下载:

  • macOS(Apple Silicon / Intel,macOS 12+):打开 .dmg,把 MonitorBar 拖进「应用程序」。应用未签名,首次打开需右键 → 打开。第一次连接显示器时允许「查找本地网络上的设备」。
  • Windows 10 / 11:把 MonitorBar.exe 和同目录的 icon.png 放到任意文件夹(推荐 %LOCALAPPDATA%\Programs\MonitorBar)后运行。托盘图标默认在 ^ 溢出区,可拖到任务栏常驻。

开机自启:默认关闭,由用户自己选择开启——面板右上角「⋯」→「登录时启动」,或命令行 MonitorBar --open-at-login on(off 关闭)。

命令行

MonitorBar --show                 # 启动并打开面板(程序已运行时,再次启动也会打开面板)
MonitorBar --probe                # 打印每台显示器的接口、分辨率、DDC/CI 读数,以及局域网上找到的所有澎湃 OS 显示器
MonitorBar --open-at-login on     # 开机自启(off 关闭)
MonitorBar --update               # 检查并安装新版本

工作原理

MonitorBar 有三条控制显示器的通道,启动时在后台探测,哪条可用就用哪条:

通道 能做什么 条件
局域网遥控 切换输入源、调音量 澎湃 OS 显示器,与电脑在同一网络
DDC/CI 硬件背光、输入源、音量、对比度等 显示器支持 DDC/CI(部分需在显示器菜单开启)
显卡 Gamma 表 软件调光、色温 任何显示器

输入源和音量优先走局域网,其次 DDC/CI;亮度有 DDC/CI 时调硬件背光,否则用软件调光。

  • 局域网遥控:澎湃 OS 的 6095 端口提供 getsources(信号源列表)、changesource2(按编号切换,能切到 DP / USB-C)、getvolume、keyevent(遥控按键,音量 ±1)。首次启动扫描所在 /24 网段找到显示器,之后记住地址。
  • DDC/CI:macOS 通过 IOAVService 读写显示器的 I2C 总线(Apple Silicon);Windows 通过系统的 Monitor Configuration API(dxva2)。输入源列表取自显示器的 MCCS 能力字符串。
  • macOS:通过 purego 调用 CoreGraphics、IOKit、AppKit(无 cgo)。
  • Windows:通过 syscall 调用 user32、gdi32、dxva2、powrprof。

平台差异

  • 软件调光:Windows 只接受离标准曲线不远的 Gamma(最暗约 50%),更暗时退到允许的最暗并保留色温比例,面板会提示。macOS 无此限制。退出时两端都会恢复原始曲线。
  • 跟随内屏亮度:仅 macOS(读取 DisplayServices 的内屏亮度),且需外接显示器支持 DDC/CI 背光;Windows 暂不支持。
  • 亮屏统计:macOS 读显示器休眠状态;Windows 以「空闲时长 ≥ 电源计划的关闭显示器时间」推断。
  • 面板位置:从溢出区打开时面板贴在图标上方;拿不到图标位置时(如再次启动程序打开)贴在屏幕右下角。
  • 数据保存在 ~/Library/Application Support/MonitorBar(macOS)或 %APPDATA%\MonitorBar(Windows)。

Windows 11 上的面板
Windows 11 上的面板

开发

基于 mygo,需要 Go 1.27+(go 会自动下载对应工具链)。

go tool mygo dev                                         # 开发,改动后自动重启
go test ./...                                            # 无窗口的界面测试与单元测试
MONITORBAR_SNAPSHOTS=docs/screenshots go test -run TestSnapshots .   # 重新生成截图
go tool mygo build -platform darwin/universal,windows/amd64          # 打包两端(可在 Mac 上交叉编译 Windows 版)

发布:先在 CHANGELOG.md 写好这个版本的说明(应用内的更新提示会显示它),再推送版本标签。CI 会用仓库 Secret MYGO_UPDATER_PRIVATE_KEY 签名,打包 macOS dmg、Windows zip 与更新包,并创建 GitHub Release。

git tag v1.0.0 && git push origin v1.0.0
路径 职责
main.go / app.go 入口、托盘图标、弹出面板的尺寸与位置
store.go 状态与动作:只在主线程读写,网络请求在 goroutine 中,结果经 post 回到主线程
panel.go / tabs.go / widgets.go / icons.go 界面
internal/mitv 澎湃 OS 局域网接口与发现
internal/display 平台层:显示器信息、分辨率、Gamma、DDC/CI、亮屏与空闲时间
internal/usage 屏幕时间,每 30 秒采样,保留 60 天
internal/schedule 自动切换:按设定时间判断白天或夜晚

适配其他显示器

先运行 MonitorBar --probe,它会打印显示器名称、原生分辨率、DDC/CI 的读数与能力字符串,以及局域网发现结果。再按情况修改:

  • 支持 DDC/CI,但某些设置不对:VCP 编码在 internal/display/ddc.go,输入源名称在 InputName(个别型号与 MCCS 不一致的,加到 inputOverrides),面板显示哪些设置在 store.go 的 controlCatalog。
  • DDC/CI 没有响应:先在显示器菜单里找 DDC/CI 开关。macOS 的读写协议在 internal/display/ddc_darwin.go,Windows 在 ddc_windows.go。注意部分 Mac 的 HDMI 口不传 DDC/CI,可改用 DP 或 USB-C 连接。
  • 其他品牌的局域网接口:参照 internal/mitv 写一个新的通道,在 store.go 里接入输入源和音量的路由(sources、selectInput、setVolume)。

致谢

English

REDMI monitors do not support DDC/CI, so the usual tools (MonitorControl, BetterDisplay, Lunar) cannot switch their inputs. They run HyperOS, though, whose LAN remote API can, DP and USB-C included. MonitorBar manages an external monitor from the macOS menu bar or the Windows notification area. It switches inputs and changes volume over the LAN remote API of Xiaomi HyperOS monitors, or over DDC/CI on monitors that support it (backlight and picture controls too), dims and warms the picture through the gamma table, switches resolutions and refresh rates, and tracks screen time. Monitors with neither HyperOS nor DDC/CI work too, with fewer features: dimming, color temperature, scenes, resolutions and screen time still work, while input switching, volume and hardware backlight do not. It is one Go codebase built with mygo, drawing native UI on both platforms; the Windows build cross-compiles from a Mac. See Development for build commands.

许可证

MIT

Documentation

Overview

MonitorBar manages an external monitor from the macOS menu bar or the Windows notification area: inputs and volume over the HyperOS LAN API, software brightness and warmth, resolutions and screen time.

MonitorBar           run, panel opens on first launch
MonitorBar --show    run and open the panel
MonitorBar --probe   print what it can see and control, then exit
MonitorBar --open-at-login on|off   start at login or not, then exit
MonitorBar --update  install a newer version if there is one, then exit

Directories

Path Synopsis
internal
display
Package display reads and changes the monitors through the operating system: their modes, gamma tables and whether they are lit.
Package display reads and changes the monitors through the operating system: their modes, gamma tables and whether they are lit.
keystate
Package keystate tells whether the keys of a shortcut are still held, for repeating it while they are, as the system repeats its own keys.
Package keystate tells whether the keys of a shortcut are still held, for repeating it while they are, as the system repeats its own keys.
mediakeys
Package mediakeys takes the keyboard's brightness and volume keys (F1, F2, F10, F11, F12 on a Mac without fn) from the system, for the external display.
Package mediakeys takes the keyboard's brightness and volume keys (F1, F2, F10, F11, F12 on a Mac without fn) from the system, for the external display.
mitv
Package mitv talks to the LAN remote API of Xiaomi HyperOS displays and TVs: the HTTP server on port 6095 that switches inputs and changes volume.
Package mitv talks to the LAN remote API of Xiaomi HyperOS displays and TVs: the HTTP server on port 6095 that switches inputs and changes volume.
schedule
Package schedule decides whether it is day or night by the times the user set, so the app can switch scenes on its own.
Package schedule decides whether it is day or night by the times the user set, so the app can switch scenes on its own.
usage
Package usage keeps daily screen time: how long the monitor was lit, and how long someone was using it.
Package usage keeps daily screen time: how long the monitor was lit, and how long someone was using it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL