diff --git a/app/window.go b/app/window.go index 120c7e7f..195e7c0c 100644 --- a/app/window.go +++ b/app/window.go @@ -8,10 +8,10 @@ import ( "image" "time" - "gioui.org/app/internal/input" "gioui.org/app/internal/window" "gioui.org/io/event" "gioui.org/io/profile" + "gioui.org/io/router" "gioui.org/io/system" "gioui.org/op" "gioui.org/unit" @@ -56,7 +56,7 @@ type callbacks struct { // Queue is an event.Queue implementation that distributes system events // to the input handlers declared in the most recent frame. type Queue struct { - q input.Router + q router.Router } // driverEvent is sent when a new native driver @@ -128,9 +128,9 @@ func (w *Window) draw(frameStart time.Time, size image.Point, frame *op.Ops) { sync := w.loop.Draw(size, frame) w.queue.q.Frame(frame) switch w.queue.q.TextInputState() { - case input.TextInputOpen: + case router.TextInputOpen: w.driver.ShowTextInput(true) - case input.TextInputClose: + case router.TextInputClose: w.driver.ShowTextInput(false) } if w.queue.q.Profiling() { diff --git a/app/internal/input/key.go b/io/router/key.go similarity index 99% rename from app/internal/input/key.go rename to io/router/key.go index 2fee78e6..dd63c65c 100644 --- a/app/internal/input/key.go +++ b/io/router/key.go @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Unlicense OR MIT -package input +package router import ( "gioui.org/internal/opconst" diff --git a/app/internal/input/pointer.go b/io/router/pointer.go similarity index 99% rename from app/internal/input/pointer.go rename to io/router/pointer.go index d2fffd63..78f04c03 100644 --- a/app/internal/input/pointer.go +++ b/io/router/pointer.go @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Unlicense OR MIT -package input +package router import ( "encoding/binary" diff --git a/app/internal/input/router.go b/io/router/router.go similarity index 81% rename from app/internal/input/router.go rename to io/router/router.go index 0484a6e0..38b6c567 100644 --- a/app/internal/input/router.go +++ b/io/router/router.go @@ -1,6 +1,14 @@ // SPDX-License-Identifier: Unlicense OR MIT -package input +/* +Package router implements Router, a event.Queue implementation +that that disambiguates and routes events to handlers declared +in operation lists. + +Router is used by app.Window and is otherwise only useful for +using Gio with external window implementations. +*/ +package router import ( "encoding/binary" @@ -15,8 +23,8 @@ import ( "gioui.org/op" ) -// Router is a Queue implementation that routes events from -// all available input sources to registered handlers. +// Router is a Queue implementation that routes events +// to handlers declared in operation lists. type Router struct { pqueue pointerQueue kqueue keyQueue @@ -40,6 +48,7 @@ type handlerEvents struct { hadEvents bool } +// Events returns the available events for the handler key. func (q *Router) Events(k event.Key) []event.Event { events := q.handlers.Events(k) if _, isprof := q.profHandlers[k]; isprof { @@ -49,6 +58,9 @@ func (q *Router) Events(k event.Key) []event.Event { return events } +// Frame replaces the declared handlers from the supplied +// operation list. The text input state, wakeup time and whether +// there are active profile handlers is also saved. func (q *Router) Frame(ops *op.Ops) { q.handlers.Clear() q.wakeup = false @@ -79,6 +91,8 @@ func (q *Router) Add(e event.Event) bool { return q.handlers.HadEvents() } +// TextInputState returns the input state from the most recent +// call to Frame. func (q *Router) TextInputState() TextInputState { return q.kqueue.InputState() } @@ -103,10 +117,14 @@ func (q *Router) collect() { } } +// Profiling reports whether there was profile handlers in the +// most recent Frame call. func (q *Router) Profiling() bool { return q.profiling } +// WakeupTime returns the most recent time for doing another frame, +// as determined from the last call to Frame. func (q *Router) WakeupTime() (time.Time, bool) { return q.wakeupTime, q.wakeup }