Something went wrong. Try again.
tui monitor configuration tool for niri with visual layout, drag-and-drop, and profile management
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148package main
import ( "fmt" "sort" "strings")
// buildHardwareID creates a stable hardware identifier from EDID data.// Format: "make/model/serial" or "make/model" when serial is empty.// Returns "" when both make and model are empty.func buildHardwareID(make_, model, serial string) string { make_ = strings.TrimSpace(make_) model = strings.TrimSpace(model) serial = strings.TrimSpace(serial)
if make_ == "" && model == "" { return "" }
if serial == "" { return fmt.Sprintf("%s/%s", make_, model) } return fmt.Sprintf("%s/%s/%s", make_, model, serial)}
// disambiguateHardwareIDs appends /#N suffixes to monitors that share// the same HardwareID. Numbering is deterministic: sorted by connector Name.func disambiguateHardwareIDs(monitors []Monitor) { counts := make(map[string]int) for _, m := range monitors { if m.HardwareID != "" { counts[m.HardwareID]++ } }
groups := make(map[string][]int) for i, m := range monitors { if m.HardwareID != "" && counts[m.HardwareID] > 1 { groups[m.HardwareID] = append(groups[m.HardwareID], i) } }
for _, indices := range groups { sort.Slice(indices, func(a, b int) bool { return monitors[indices[a]].Name < monitors[indices[b]].Name }) for n, idx := range indices { monitors[idx].HardwareID = fmt.Sprintf("%s/#%d", monitors[idx].HardwareID, n+1) } }}
// resolveProfileMonitors takes saved profile monitors and maps them to// currently connected monitors by HardwareID. Returns only monitors that// are currently connected, with their connector Name updated to the current value.func resolveProfileMonitors(saved, current []Monitor) []Monitor { currentByHWID := make(map[string]Monitor) currentByName := make(map[string]Monitor) for _, m := range current { if m.HardwareID != "" { currentByHWID[m.HardwareID] = m } currentByName[m.Name] = m }
var resolved []Monitor for _, savedMon := range saved { var currentMon Monitor var found bool
if savedMon.HardwareID != "" { currentMon, found = currentByHWID[savedMon.HardwareID] } else { // Fallback to Name only for legacy profiles (no HardwareID) currentMon, found = currentByName[savedMon.Name] }
if !found { continue }
resolvedMon := savedMon resolvedMon.Name = currentMon.Name if resolvedMon.HardwareID == "" { resolvedMon.HardwareID = currentMon.HardwareID } // refresh the EDID-derived identifier so apply-time `niri msg output` // commands speak niri's literal name even when the saved profile was // written by an older hyprmon version that omitted the "Unknown" // serial sentinel if currentMon.EDIDName != "" { resolvedMon.EDIDName = currentMon.EDIDName } resolved = append(resolved, resolvedMon) }
return resolved}
// migrateProfileMonitors backfills HardwareID on legacy profile monitors// by matching their Name against currently connected monitors.func migrateProfileMonitors(saved, current []Monitor) []Monitor { currentByName := make(map[string]Monitor) for _, m := range current { currentByName[m.Name] = m }
migrated := make([]Monitor, len(saved)) copy(migrated, saved)
for i, m := range migrated { if m.HardwareID != "" { continue // Already has a HardwareID } if currentMon, ok := currentByName[m.Name]; ok { migrated[i].HardwareID = currentMon.HardwareID migrated[i].Make = currentMon.Make migrated[i].Model = currentMon.Model migrated[i].Serial = currentMon.Serial } }
return migrated}
// needsMigration checks if any monitor in the profile lacks a HardwareID.func needsMigration(monitors []Monitor) bool { for _, m := range monitors { if m.HardwareID == "" { return true } } return false}
// DisplayLabel returns the best human-readable label for a monitor.// Priority: Alias > Model > Name.func (m Monitor) DisplayLabel() string { if m.Alias != "" { return m.Alias } if m.Model != "" { return m.Model } return m.Name}