diff --git a/event.go b/event.go index 38cd54c..26df879 100644 --- a/event.go +++ b/event.go @@ -293,6 +293,7 @@ func (window *window) handleButtonRelease ( window.updateModifiers(buttonEvent.State) window.updateMousePosition(buttonEvent.EventX, buttonEvent.EventY) dragging := window.drags[buttonEvent.Detail] + window.drags[buttonEvent.Detail] = nil if dragging != nil { dragging.handleMouseUp(input.Button(buttonEvent.Detail)) @@ -314,11 +315,14 @@ func (window *window) handleMotionNotify ( for _, child := range window.drags { if child == nil { continue } child.handleMouseMove() + window.hover(child) handled = true } if !handled { - window.boxUnder(image.Pt(x, y)).handleMouseMove() + underneath := window.boxUnder(image.Pt(x, y)) + underneath.handleMouseMove() + window.hover(underneath) } } diff --git a/system.go b/system.go index f55c581..3eea89c 100644 --- a/system.go +++ b/system.go @@ -56,8 +56,8 @@ type anyBox interface { // handleDndEnter () // handleDndLeave () // handleDndDrop (data.Data) - // handleMouseEnter () - // handleMouseLeave () + handleMouseEnter () + handleMouseLeave () handleMouseMove () handleMouseDown (input.Button) handleMouseUp (input.Button) @@ -119,15 +119,31 @@ func (window *window) focus (box anyBox) { window.focused = box if previous != nil { + // FIXME why are we invalidating draw here window.invalidateDraw(previous) previous.handleFocusLeave() } if box != nil && box.canBeFocused() { + // FIXME why are we invalidating draw here window.invalidateDraw(box) box.handleFocusEnter() } } +func (window *window) hover (box anyBox) { + if window.hovered == box { return } + + previous := window.hovered + window.hovered = box + + if previous != nil { + previous.handleMouseLeave() + } + if box != nil { + box.handleMouseEnter() + } +} + func (window *window) anyFocused () bool { return window.focused != nil } diff --git a/window.go b/window.go index bfc67bf..0932d18 100644 --- a/window.go +++ b/window.go @@ -44,6 +44,7 @@ type window struct { root anyBox focused anyBox + hovered anyBox needDraw boxSet needLayout boxSet