gocui/eventMouse.go

75 lines
1.8 KiB
Go
Raw Normal View History

// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
2025-02-08 17:19:41 -06:00
"fmt"
2025-02-08 08:07:03 -06:00
"time"
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
)
func mouseUp(g *gocui.Gui, v *gocui.View) error {
2025-01-31 12:36:46 -06:00
// useful to debug everything that is being clicked on
/*
for _, tk := range findByXY(w, h) {
2025-02-01 13:58:53 -06:00
tk.dumpWidget("mouseUp()")
}
*/
2025-02-08 08:07:03 -06:00
me.mouse.mouseUp = true
2025-02-08 08:36:08 -06:00
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
2025-02-08 08:36:08 -06:00
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 {
2025-02-08 08:07:03 -06:00
if me.mouse.mouseUp {
2025-02-08 08:36:08 -06:00
if time.Since(me.mouse.down) < me.mouse.doubletime {
me.mouse.double = true
2025-02-08 08:36:08 -06:00
}
2025-02-08 08:07:03 -06:00
me.mouse.mouseUp = false
me.mouse.down = time.Now()
w, h := g.MousePosition()
me.mouse.downW = w
me.mouse.downH = h
2025-02-08 17:19:41 -06:00
win := findWindowUnderMouse()
if win != nil {
w, h := g.MousePosition()
s := fmt.Sprintf("mouse(%d,%d) ", w, h)
2025-02-09 03:21:48 -06:00
offW := win.full.w1 - w
offH := win.full.h1 - h
2025-02-08 17:19:41 -06:00
s += fmt.Sprintf("corner(%d,%d)", offW, offH)
if (offW < 3) && (offH < 3) {
2025-02-09 03:00:10 -06:00
log.Info("attempting resize on ", s, win.cuiName)
2025-02-08 17:19:41 -06:00
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
}
2025-02-08 18:03:11 -06:00
win.setAsDragging()
2025-02-08 17:19:41 -06:00
}
}
2025-02-09 12:21:43 -06:00
return nil
2025-02-01 19:42:04 -06:00
}