From 170d4e34841b53e146039bf1fddd8256a80c2236 Mon Sep 17 00:00:00 2001 From: frosty Date: Fri, 6 Sep 2024 06:48:40 -0400 Subject: [PATCH] pass update function to monitorUpdates --- main.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 641b4a8..4ceb2f8 100644 --- a/main.go +++ b/main.go @@ -140,7 +140,7 @@ func createOutput(b *bytes.Buffer) { b.Write(suffix) } -func monitorUpdates(setXRootName bool) { +func monitorUpdates(outputHandler func([]byte)) { var lastOutput []byte var combinedOutput bytes.Buffer @@ -150,11 +150,7 @@ func monitorUpdates(setXRootName bool) { combinedOutputBytes := combinedOutput.Bytes() if !bytes.Equal(combinedOutputBytes, lastOutput) { - if setXRootName { - xproto.ChangeProperty(x, xproto.PropModeReplace, root, xproto.AtomWmName, xproto.AtomString, 8, uint32(len(combinedOutputBytes)), combinedOutputBytes) - } else { - fmt.Printf("%s\n", combinedOutputBytes) - } + outputHandler(combinedOutputBytes) lastOutput = append([]byte(nil), combinedOutputBytes...) } } @@ -185,7 +181,13 @@ func main() { go modules[i].Init(i) } - go monitorUpdates(flags.SetXRootName) + go monitorUpdates(func(combinedOutputBytes []byte) { + if flags.SetXRootName { + xproto.ChangeProperty(x, xproto.PropModeReplace, root, xproto.AtomWmName, xproto.AtomString, 8, uint32(len(combinedOutputBytes)), combinedOutputBytes) + } else { + fmt.Printf("%s\n", combinedOutputBytes) + } + }) for sig := range sigChan { go handleSignal(sig)