From 665d2289e2ce910326cacb2e6b8c35c5e241c279 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 8 Feb 2025 12:05:25 -0600 Subject: [PATCH] tiggers gocui on startup --- find.go | 34 +++++++++++++++++----------------- init.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++- treeAdd.go | 12 ------------ 3 files changed, 63 insertions(+), 30 deletions(-) diff --git a/find.go b/find.go index 795f7ee..189d84b 100644 --- a/find.go +++ b/find.go @@ -45,25 +45,25 @@ func (r rectType) inRect(w int, h int) bool { func (tk *guiWidget) findByXYreal(w int, h int) []*guiWidget { var widgets []*guiWidget - if !tk.Visible() { - // ignore widgets that are not visible - } else { + // if !tk.Visible() { + // ignore widgets that are not visible + // } else { - // check the location to see if this is under (W,H) - // if it is, return this widget - // if (tk.gocuiSize.w0 <= w) && (w <= tk.gocuiSize.w1) && - // (tk.gocuiSize.h0 <= h) && (h <= tk.gocuiSize.h1) { - if tk.gocuiSize.inRect(w, h) { - widgets = append(widgets, tk) - } else { - // if (tk.full.w0 <= w) && (w <= tk.full.w1) && - // (tk.full.h0 <= h) && (h <= tk.full.h1) { - if tk.full.inRect(w, h) { - widgets = append(widgets, tk) - } - // log.Log(GOCUI, "findByXY() found", widget.node.WidgetType, w, h) - } + // check the location to see if this is under (W,H) + // if it is, return this widget + // if (tk.gocuiSize.w0 <= w) && (w <= tk.gocuiSize.w1) && + // (tk.gocuiSize.h0 <= h) && (h <= tk.gocuiSize.h1) { + // if tk.gocuiSize.inRect(w, h) { + // widgets = append(widgets, tk) + // } else { + // if (tk.full.w0 <= w) && (w <= tk.full.w1) && + // (tk.full.h0 <= h) && (h <= tk.full.h1) { + if tk.full.inRect(w, h) { + widgets = append(widgets, tk) } + // log.Log(GOCUI, "findByXY() found", widget.node.WidgetType, w, h) + // } + // } // tk.verifyRect() // search through the children widgets in the binary tree diff --git a/init.go b/init.go index 3964ce0..d387d02 100644 --- a/init.go +++ b/init.go @@ -56,6 +56,7 @@ func init() { me.myTree = tree.New() me.myTree.PluginName = "gocui" + go refreshGocui() if val, err := me.myTree.ConfigFind("dark"); err == nil { if val == "true" { @@ -207,6 +208,47 @@ func gocuiMain() { } } +// this hack is to wait for the application to send something +// before trying to do anything. todo: rethink this someday +func waitOK() { + for { + if me.ok { + return + } + time.Sleep(10 * time.Millisecond) + } +} + +var lastRefresh time.Time + +func testRefresh(*gocui.Gui) error { + log.Info("in testRefresh") + return nil +} + +func refreshGocui() { + lastRefresh = time.Now() + for { + time.Sleep(10 * time.Millisecond) + // log.Info("refresh checking ok") + if !me.ok { + continue + } + if time.Since(lastRefresh) > 1*time.Second { + if me.mouse.mouseUp { + log.Info("refresh now on mouseUp") + me.baseGui.Update(testRefresh) + } else { + log.Info("refresh skip on mouseDown") + // me.baseGui.Update() + } + lastRefresh = time.Now() + } + } +} + +// set the widget start width & height + func newWindowTrigger() { log.Log(NOW, "newWindowTriggerl() START") for { @@ -222,7 +264,10 @@ func newWindowTrigger() { relocateStdoutOffscreen() } tk.makeWindowActive() - tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0) + // place the new window relative to the mouse + tk.redrawWindow(me.mouse.downW+8, me.mouse.downH-2) + // tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0) + setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn // log.Log(NOW, "newWindowTrigger() after sleep") } diff --git a/treeAdd.go b/treeAdd.go index 9b975ad..35f3514 100644 --- a/treeAdd.go +++ b/treeAdd.go @@ -4,8 +4,6 @@ package main import ( - "time" - log "go.wit.com/log" "go.wit.com/toolkits/tree" "go.wit.com/widget" @@ -30,16 +28,6 @@ func setFake(n *tree.Node) { } } -func waitOK() { - for { - if me.ok { - return - } - time.Sleep(10 * time.Millisecond) - } -} - -// set the widget start width & height // func (n *node) addWidget(n *tree.Node) { func addWidget(n *tree.Node) { if !me.ok {