cleaner libnotifyUpdate()

This commit is contained in:
Jeff Carr 2025-03-03 01:51:16 -06:00
parent caf7428ba3
commit 65cf744a86
3 changed files with 44 additions and 27 deletions

21
init.go
View File

@ -338,28 +338,11 @@ func refreshGocui() {
if me.mouse.mouseUp {
// log.Info("refresh now on mouseUp")
// todo: add logic here to see if the application has changed anything
// me.baseGui.UpdateAsync(testRefresh) // probably don't need this
me.baseGui.Update(testRefresh)
if me.notify.clock.tk != nil {
// also double check the gocui view exists
if me.notify.clock.tk.v != nil {
me.notify.clock.tk.v.Clear()
me.notify.clock.tk.labelN = time.Now().Format("15:04:05")
me.notify.clock.tk.v.WriteString(me.notify.clock.tk.labelN)
}
}
libNotifyUpdate()
lastRefresh = time.Now()
} else {
me.baseGui.Update(testRefresh)
if time.Since(lastRefresh) > 3*time.Second {
if me.notify.clock.tk != nil && !me.showHelp {
// also double check the gocui view exists
if me.notify.clock.tk.v != nil {
me.notify.clock.tk.v.Clear()
me.notify.clock.tk.labelN = time.Now().Format("15:04:05")
me.notify.clock.tk.v.WriteString(me.notify.clock.tk.labelN)
}
}
libNotifyUpdate()
lastRefresh = time.Now()
}
}

View File

@ -67,6 +67,39 @@ func makeClock(wId int) {
me.notify.clock.tk.Show()
me.notify.clock.active = true
me.notify.clock.tk.dumpWidget("showClock()")
}
func libNotifyUpdate() {
if me.baseGui == nil {
log.Info("libNotifyUpdate error baseGui == nil")
return
}
// refresh GOCUI
me.baseGui.Update(testRefresh)
// me.baseGui.UpdateAsync(testRefresh) // Async option. probably don't need this?
if me.notify.clock.tk == nil {
log.Info("libNotifyUpdate error clock.tk == nil")
return
}
// check for SIGWINCH. If so, move the libnotify clock
w, h := me.baseGui.Size()
if me.winchW != w || me.winchH != h {
log.Info("handle SIGWINCH!", w, h)
me.notify.clock.tk.MoveToOffset(w-15, 1)
me.notify.clock.tk.Hide()
me.notify.clock.tk.Show()
me.winchW = w
me.winchH = h
}
// update the time
me.notify.clock.tk.v.Clear()
me.notify.clock.tk.labelN = time.Now().Format("15:04:05")
me.notify.clock.tk.v.WriteString(me.notify.clock.tk.labelN)
}
// in the very end of redrawing things, this will place the help and stdout on the top or botton

View File

@ -78,14 +78,15 @@ type config struct {
stdout stdout // information for the STDOUT window
dropdown dropdown // the dropdown menu
textbox dropdown // the textbox popup window
// clock dropdown // the textbox popup window
notify libnotify // emulates the desktop libnotify menu
allwin []*guiWidget // for tracking which window is next
dark bool // use a 'dark' color palette
mouse mouse // mouse settings
showDebug bool // todo: move this into config struct
debug bool // todo: move this into config struct
starttime time.Time // checks how long it takes on startup
notify libnotify // emulates the desktop libnotify menu
allwin []*guiWidget // for tracking which window is next
dark bool // use a 'dark' color palette
mouse mouse // mouse settings
showDebug bool // todo: move this into config struct
debug bool // todo: move this into config struct
starttime time.Time // checks how long it takes on startup
winchW int // used to detect SIGWINCH
winchH int // used to detect SIGWINCH
}
// stuff controlling how the mouse works