diff --git a/eventBindings.go b/eventBindings.go index 26348e5..166696e 100644 --- a/eventBindings.go +++ b/eventBindings.go @@ -92,27 +92,6 @@ func addDropdown() *tree.Node { return addDropdownNew(-222) } -func findNextWindow() *guiWidget { - var found bool - if len(me.allwin) == 0 { - return nil - } - for _, win := range me.allwin { - if win.activeWindow { - found = true - win.activeWindow = false - continue - } - if found { - win.activeWindow = true - return win - } - } - me.allwin[0].activeWindow = true - // at the end, loop to the beginning - return me.allwin[0] -} - // use this to test code ideas // put whatever you want here and hit '2' to activate it func theNotsure(g *gocui.Gui, v *gocui.View) error { log.Info("got keypress 2. now what?") diff --git a/eventMouse.go b/eventMouse.go index f3a223d..1757ed0 100644 --- a/eventMouse.go +++ b/eventMouse.go @@ -80,6 +80,12 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error { } found = true } + if tk := findWindowUnderMouse(); tk != nil { + w, h := g.MousePosition() + tk.dragW = w - tk.gocuiSize.w0 + tk.dragH = h - tk.gocuiSize.h0 + tk.doWidgetClick(w-tk.dragW, w-tk.dragH) + } mx, my := g.MousePosition() for _, tk := range findByXY(mx, my) { diff --git a/eventMouseMove.go b/eventMouseMove.go index eb6beed..a88fa79 100644 --- a/eventMouseMove.go +++ b/eventMouseMove.go @@ -47,6 +47,11 @@ func mouseMove(g *gocui.Gui) { currentDrag.moveNew() return } + // new function that is smarter + if tk := findWindowUnderMouse(); tk != nil { + currentDrag = tk + return + } // first look for windows for _, tk := range findByXY(w, h) { if tk.node.WidgetType == widget.Window { diff --git a/find.go b/find.go index 6fd84a7..a248a09 100644 --- a/find.go +++ b/find.go @@ -5,6 +5,7 @@ package main import ( "github.com/awesome-gocui/gocui" + log "go.wit.com/log" "go.wit.com/widget" ) @@ -108,6 +109,27 @@ func (tk *guiWidget) findBG() *guiWidget { return nil } +func findNextWindow() *guiWidget { + var found bool + if len(me.allwin) == 0 { + return nil + } + for _, win := range me.allwin { + if win.activeWindow { + found = true + win.activeWindow = false + continue + } + if found { + win.activeWindow = true + return win + } + } + me.allwin[0].activeWindow = true + // at the end, loop to the beginning + return me.allwin[0] +} + func findWindowUnderMouse() *guiWidget { w, h := me.baseGui.MousePosition() @@ -117,6 +139,30 @@ func findWindowUnderMouse() *guiWidget { return me.stdout.tk } } + + // now check if the active window is below the mouse + for _, win := range me.allwin { + if win.activeWindow { + if win.full.inRect(w, h) { + return win + } + } + } + + // well, just find any window then + for _, win := range me.allwin { + if win.full.inRect(w, h) { + return win + } + } + + // okay, no window. maybe the stdout is there? + if me.stdout.tk.full.inRect(w, h) { + return me.stdout.tk + } + + // geez. nothing! maybe auto return stdout? + log.Info("no window found at", w, h) return nil }