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 { if me.mouse.mouseUp {
// log.Info("refresh now on mouseUp") // log.Info("refresh now on mouseUp")
// todo: add logic here to see if the application has changed anything // todo: add logic here to see if the application has changed anything
// me.baseGui.UpdateAsync(testRefresh) // probably don't need this libNotifyUpdate()
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)
}
}
lastRefresh = time.Now() lastRefresh = time.Now()
} else { } else {
me.baseGui.Update(testRefresh)
if time.Since(lastRefresh) > 3*time.Second { if time.Since(lastRefresh) > 3*time.Second {
if me.notify.clock.tk != nil && !me.showHelp { libNotifyUpdate()
// 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)
}
}
lastRefresh = time.Now() lastRefresh = time.Now()
} }
} }

View File

@ -67,6 +67,39 @@ func makeClock(wId int) {
me.notify.clock.tk.Show() me.notify.clock.tk.Show()
me.notify.clock.active = true me.notify.clock.active = true
me.notify.clock.tk.dumpWidget("showClock()") 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 // in the very end of redrawing things, this will place the help and stdout on the top or botton

View File

@ -78,7 +78,6 @@ type config struct {
stdout stdout // information for the STDOUT window stdout stdout // information for the STDOUT window
dropdown dropdown // the dropdown menu dropdown dropdown // the dropdown menu
textbox dropdown // the textbox popup window textbox dropdown // the textbox popup window
// clock dropdown // the textbox popup window
notify libnotify // emulates the desktop libnotify menu notify libnotify // emulates the desktop libnotify menu
allwin []*guiWidget // for tracking which window is next allwin []*guiWidget // for tracking which window is next
dark bool // use a 'dark' color palette dark bool // use a 'dark' color palette
@ -86,6 +85,8 @@ type config struct {
showDebug bool // todo: move this into config struct showDebug bool // todo: move this into config struct
debug 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 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 // stuff controlling how the mouse works