detect an attempt to close a window

This commit is contained in:
Jeff Carr 2025-02-09 03:00:10 -06:00
parent eba5ea8cc0
commit 8d8fc22745
5 changed files with 38 additions and 13 deletions

View File

@ -61,7 +61,7 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
offH := win.gocuiSize.h1 - h
s += fmt.Sprintf("corner(%d,%d)", offW, offH)
if (offW < 3) && (offH < 3) {
// log.Info("mouse down resize on ", s)
log.Info("attempting resize on ", s, win.cuiName)
me.mouse.resize = true
// store the stdout corner for computing the drag size
me.stdout.lastW = me.stdout.tk.gocuiSize.w0

View File

@ -166,7 +166,10 @@ func doMouseClick(w int, h int) {
// tk.dumpWidget("undef click()") // enable this to debug widget clicks
}
}
log.Info("you clicked on a window, but not any widgets", win.cuiName)
if win.checkWindowClose(w, h) {
return
}
log.Info("you clicked on a window, but not any widgets. check for title / close window here", win.cuiName)
win.redrawWindow(win.gocuiSize.w0, win.gocuiSize.h0)
me.stdout.outputOnTop = false
setThingsOnTop()

21
init.go
View File

@ -9,6 +9,7 @@ package main
import (
"errors"
"fmt"
"os"
"runtime"
"runtime/debug"
@ -51,6 +52,10 @@ func init() {
me.stdout.wId = -4
me.clock.wId = -5
Set(&me.dropdown, "default")
s := fmt.Sprintln("fake default check =", me.FakeW, "dropdown.Id", me.dropdown.Id)
me.stdout.Write([]byte(s))
me.mouse.mouseUp = true
me.mouse.clicktime = time.Millisecond * 200
me.mouse.doubletime = time.Millisecond * 400
@ -101,7 +106,7 @@ func standardExit() {
log.Log(NOW, "standardExit() doing baseGui.Close()")
me.baseGui.Close()
log.Log(NOW, "standardExit() doing outf.Close()")
outf.Close()
me.outf.Close()
// log(true, "standardExit() setOutput(os.Stdout)")
// setOutput(os.Stdout)
log.Log(NOW, "standardExit() send back Quit()")
@ -116,15 +121,13 @@ func standardClose() {
log.Log(NOW, "standardExit() doing baseGui.Close()")
me.baseGui.Close()
log.Log(NOW, "standardExit() doing outf.Close()")
outf.Close()
me.outf.Close()
// os.Stdin = os.Stdin
// os.Stdout = os.Stdout
// os.Stderr = os.Stderr
log.Log(NOW, "standardExit() send back Quit()")
}
var outf *os.File
func main() {
}
@ -148,16 +151,16 @@ func mainGogui() {
var err error
outf, err = os.OpenFile("/tmp/captureMode.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
me.outf, err = os.OpenFile("/tmp/captureMode.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Info("error opening file:", err)
os.Exit(0)
}
origStdout = os.Stdout
os.Stdout = outf
defer outf.Close()
os.Stdout = me.outf
defer me.outf.Close()
log.CaptureMode(outf)
log.CaptureMode(me.outf)
gocuiMain()
}
@ -293,7 +296,7 @@ func newWindowTrigger() {
// log.Log(NOW, "newWindowTrigger() got new window", tk.cuiName)
time.Sleep(200 * time.Millisecond)
waitOK()
redoWindows(1, -1)
redoWindows(3, 3)
if !me.stdout.init {
me.stdout.init = true
relocateStdoutOffscreen()

View File

@ -10,6 +10,7 @@ package main
import (
"fmt"
"os"
"reflect"
"strconv"
"sync"
@ -53,6 +54,7 @@ type config struct {
RawW int `default:"1"` // the raw beginning of each window (or tab)
RawH int `default:"5"` // the raw beginning of each window (or tab)
FakeW int `default:"20"` // offset for the hidden widgets
DropdownId int `default:"-78"` // the widget id to use
padded bool // add space between things like buttons
bookshelf bool // do you want things arranged in the box like a bookshelf or a stack?
canvas bool // if set to true, the windows are a raw canvas
@ -72,6 +74,8 @@ type config struct {
dark bool // use a 'dark' color palette
mouse mouse // mouse settings
showDebug bool // todo: move this into config struct
outf *os.File // hacks for capturing stdout
}
// stuff controlling how the mouse works
@ -115,8 +119,8 @@ type dropdown struct {
h int // the height
active bool // is the dropdown menu currently in use?
init bool // moves the window offscreen on startup
wId int // the widget id to use
// dtoggle bool // is a dropdown or combobox currently active?
Id int `default:"-78"` // the widget id to use
wId int `default:"-78"` // the widget id to use
}
// this is the gocui way

View File

@ -7,6 +7,7 @@ import (
"fmt"
"strings"
log "go.wit.com/log"
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
@ -237,3 +238,17 @@ func (tk *guiWidget) makeTK(ddItems []string) {
*/
tk.Show()
}
func (win *guiWidget) checkWindowClose(w int, h int) bool {
s := fmt.Sprintf("mouse(%d,%d) ", w, h)
offW := win.full.w1 - w
offH := h - win.full.h0
s += fmt.Sprintf("offset(%d,%d)", offW, offH)
if (offW < 2) && (offH < 2) {
log.Info("attempting close on ", s, win.cuiName)
// store the stdout corner for computing the drag size
return true
}
log.Info("not attempting close on ", s, win.cuiName)
return false
}