75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
|
// Use of this source code is governed by the GPL 3.0
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/awesome-gocui/gocui"
|
|
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
func mouseUp(g *gocui.Gui, v *gocui.View) error {
|
|
// useful to debug everything that is being clicked on
|
|
/*
|
|
for _, tk := range findByXY(w, h) {
|
|
tk.dumpWidget("mouseUp()")
|
|
}
|
|
*/
|
|
|
|
me.mouse.mouseUp = true
|
|
me.mouse.currentDrag = nil
|
|
|
|
if me.mouse.double && (time.Since(me.mouse.down) < me.mouse.doubletime) {
|
|
me.mouse.double = false
|
|
doMouseDoubleClick(me.mouse.downW, me.mouse.downH)
|
|
return nil
|
|
}
|
|
me.mouse.double = false
|
|
|
|
if time.Since(me.mouse.down) < me.mouse.clicktime {
|
|
doMouseClick(me.mouse.downW, me.mouse.downH)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// this is where you have to figure out what
|
|
// widget was underneath so you can active
|
|
// the right response for the toolkit user's app
|
|
func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
|
if me.mouse.mouseUp {
|
|
if time.Since(me.mouse.down) < me.mouse.doubletime {
|
|
me.mouse.double = true
|
|
}
|
|
me.mouse.mouseUp = false
|
|
me.mouse.down = time.Now()
|
|
w, h := g.MousePosition()
|
|
me.mouse.downW = w
|
|
me.mouse.downH = h
|
|
|
|
win := findWindowUnderMouse()
|
|
if win != nil {
|
|
w, h := g.MousePosition()
|
|
s := fmt.Sprintf("mouse(%d,%d) ", w, h)
|
|
offW := win.full.w1 - w
|
|
offH := win.full.h1 - h
|
|
s += fmt.Sprintf("corner(%d,%d)", offW, offH)
|
|
if (offW < 3) && (offH < 3) {
|
|
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
|
|
me.stdout.lastH = me.stdout.tk.gocuiSize.h0
|
|
} else {
|
|
// log.Info("mouse down resize off", s)
|
|
me.mouse.resize = false
|
|
}
|
|
win.setAsDragging()
|
|
}
|
|
}
|
|
return nil
|
|
}
|