MonitorBar

command module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 23 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

概览 分辨率 屏幕时间

为什么做这个

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 参照 internal/mitv(局域网接口)和 internal/display(系统显示 API)修改代码。项目结构见下面的开发一节。

功能

分页 功能
概览 当前分辨率与刷新率、切换输入源、软件亮度、显示器音量、场景(日间 / 阅读 / 观影 / 夜间)
画面 场景、软件调光、色温(减少蓝光)、一键恢复
分辨率 刷新率切换,HiDPI(仅 macOS)与标准分辨率列表
屏幕时间 今日亮屏与使用时长,最近 7 天柱状图
  • 切换输入源、调音量不需要 DDC/CI:澎湃 OS 显示器(如 REDMI 显示器 G Pro 27U 2026)在局域网提供遥控接口,MonitorBar 自动发现并使用它。Mac 和 Windows 接在同一台显示器的不同接口上时,两边都能一键切到对方。
  • 软件调光与色温通过显卡的 Gamma 表实现,任何连接线、任何显示器都能用。
  • 单个可执行文件,无 webview,空闲时不占 CPU;中文界面,深色主题。

安装

从 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                # 打印显示器、接口、模式和局域网发现结果
MonitorBar --open-at-login on     # 开机自启(off 关闭)

工作原理

  • 局域网遥控:澎湃 OS 的 6095 端口提供 getsources(信号源列表)、changesource2(按编号切换,能切到 DP / USB-C)、getvolume、keyevent(遥控按键,音量 ±1)。首次启动扫描所在 /24 网段找到显示器,之后记住地址。
  • macOS:通过 purego 调用 CoreGraphics、IOKit、AppKit(无 cgo)。
  • Windows:通过 syscall 调用 user32、gdi32、powrprof。

平台差异

  • 软件调光:Windows 只接受离标准曲线不远的 Gamma(最暗约 50%),更暗时退到允许的最暗并保留色温比例,面板会提示。macOS 无此限制。退出时两端都会恢复原始曲线。
  • 亮屏统计: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 版)

发布:推送版本标签,CI 会打包 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、亮屏与空闲时间
internal/usage 屏幕时间,每 30 秒采样,保留 60 天

致谢

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 (no DDC/CI needed), dims and warms the picture through the gamma table, switches resolutions and refresh rates, and tracks screen time. 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

Directories

Path Synopsis
internal
display
Package display reads and changes the target monitor through the operating system: its modes, its gamma table and whether it is lit.
Package display reads and changes the target monitor through the operating system: its modes, its gamma table and whether it is lit.
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.
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