From 6127fa1cbb8a68f0b125f50b760822828c7f20e5 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 3 Mar 2025 23:50:11 -0600 Subject: [PATCH] try out sync.Once --- init.go | 6 +++--- libnotify.go | 14 ++++++-------- structs.go | 1 + 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/init.go b/init.go index 3580116..e549b18 100644 --- a/init.go +++ b/init.go @@ -73,9 +73,9 @@ func toolkitInit() { me.BG.tk = makeNewInternalWidget(me.BG.wId) } - // SETUP libnotify - makeNotifyClock(me.notify.clock.wId) - makeNotifyMenu(me.notify.menu.wId) + // SETUP libnotify clock and menu + me.notify.clock.once.Do(makeNotifyClock) + me.notify.menu.once.Do(makeNotifyMenu) // PUT INIT DEBUG COOE HERE var toggle bool diff --git a/libnotify.go b/libnotify.go index 487c429..5bfa077 100644 --- a/libnotify.go +++ b/libnotify.go @@ -1,10 +1,8 @@ -// Copyright 2014 The gocui Authors. All rights reserved. // Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - +// this file implements a libnotify-like menu +// also there is SIGWINCH resizing package main import ( @@ -52,12 +50,12 @@ func makeNewInternalWidget(wId int) *guiWidget { return tk } -func makeNotifyClock(wId int) { +func makeNotifyClock() { if me.treeRoot == nil { log.Info("gogui makeClock() error. treeRoot == nil") return } - me.notify.clock.tk = makeNewInternalWidget(wId) + me.notify.clock.tk = makeNewInternalWidget(me.notify.clock.wId) me.notify.clock.tk.dumpWidget("init() clock") me.notify.clock.tk.MoveToOffset(0, 0) me.notify.clock.tk.labelN = time.Now().Format("15:04:05") @@ -69,12 +67,12 @@ func makeNotifyClock(wId int) { } -func makeNotifyMenu(wId int) { +func makeNotifyMenu() { if me.treeRoot == nil { log.Info("gogui makeClock() error. treeRoot == nil") return } - me.notify.menu.tk = makeNewInternalWidget(wId) + me.notify.menu.tk = makeNewInternalWidget(me.notify.menu.wId) me.notify.menu.tk.dumpWidget("init() menu") w, _ := me.baseGui.Size() me.notify.menu.tk.MoveToOffset(w-5, me.notify.menu.offsetH) diff --git a/structs.go b/structs.go index dd9ed14..4e72e80 100644 --- a/structs.go +++ b/structs.go @@ -138,6 +138,7 @@ type dropdown struct { // settings for the dropdown window type internalTK struct { + once sync.Once // for init tk *guiWidget // where to show STDOUT callerTK *guiWidget // which widget called the dropdown menu wId int // the widget id to use