mirror of
https://codeberg.org/frosty/modbot.git
synced 2024-09-19 03:36:35 -04:00
allow setting the x root window name
not perfect, still need to switch to byte arrays internally instead of strings
This commit is contained in:
parent
4653550119
commit
7a9ed4984d
2
go.mod
2
go.mod
|
@ -1,3 +1,5 @@
|
||||||
module codeberg.org/frosty/modbot
|
module codeberg.org/frosty/modbot
|
||||||
|
|
||||||
go 1.22.4
|
go 1.22.4
|
||||||
|
|
||||||
|
require github.com/jezek/xgb v1.1.1 // indirect
|
||||||
|
|
2
go.sum
Normal file
2
go.sum
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/jezek/xgb v1.1.1 h1:bE/r8ZZtSv7l9gk6nU0mYx51aXrvnyb44892TwSaqS4=
|
||||||
|
github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
|
41
main.go
41
main.go
|
@ -18,6 +18,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
|
@ -26,6 +27,9 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/jezek/xgb"
|
||||||
|
"github.com/jezek/xgb/xproto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -34,8 +38,16 @@ var (
|
||||||
|
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
lastOutput string
|
lastOutput string
|
||||||
|
|
||||||
|
// X connection data
|
||||||
|
x *xgb.Conn
|
||||||
|
root xproto.Window
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Flags struct {
|
||||||
|
SetXRootName bool
|
||||||
|
}
|
||||||
|
|
||||||
type Module struct {
|
type Module struct {
|
||||||
Func func() (interface{}, error)
|
Func func() (interface{}, error)
|
||||||
Interval time.Duration
|
Interval time.Duration
|
||||||
|
@ -85,7 +97,28 @@ func (m *Module) Run() {
|
||||||
mutex.Unlock()
|
mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseFlags() Flags {
|
||||||
|
var flags Flags
|
||||||
|
flag.BoolVar(&flags.SetXRootName, "x", false, "set x root window name")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flags := parseFlags()
|
||||||
|
|
||||||
|
// Connect to X and get the root window if requested
|
||||||
|
if flags.SetXRootName {
|
||||||
|
var err error
|
||||||
|
x, err = xgb.NewConn()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("X connection failed: %s\n", err.Error())
|
||||||
|
}
|
||||||
|
root = xproto.Setup(x).DefaultScreen(x).Root
|
||||||
|
}
|
||||||
|
|
||||||
sigChan := make(chan os.Signal, 1024)
|
sigChan := make(chan os.Signal, 1024)
|
||||||
signalMap := make(map[os.Signal][]*Module)
|
signalMap := make(map[os.Signal][]*Module)
|
||||||
|
|
||||||
|
@ -126,8 +159,16 @@ func main() {
|
||||||
combinedOutput = prefix + combinedOutput + suffix
|
combinedOutput = prefix + combinedOutput + suffix
|
||||||
mutex.Unlock()
|
mutex.Unlock()
|
||||||
|
|
||||||
|
// Output to either X root window name or stdout based on flags
|
||||||
if combinedOutput != lastOutput {
|
if combinedOutput != lastOutput {
|
||||||
|
if flags.SetXRootName {
|
||||||
|
// Set the X root window name
|
||||||
|
outputBytes := []byte(combinedOutput)
|
||||||
|
xproto.ChangeProperty(x, xproto.PropModeReplace, root, xproto.AtomWmName, xproto.AtomString, 8, uint32(len(outputBytes)), outputBytes)
|
||||||
|
} else {
|
||||||
|
// Print to stdout
|
||||||
fmt.Printf("%v\n", combinedOutput)
|
fmt.Printf("%v\n", combinedOutput)
|
||||||
|
}
|
||||||
lastOutput = combinedOutput
|
lastOutput = combinedOutput
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue