diff --git a/remote/RemoteMatrix.go b/remote/RemoteMatrix.go index 0b2bfd9..499ab7c 100644 --- a/remote/RemoteMatrix.go +++ b/remote/RemoteMatrix.go @@ -18,6 +18,10 @@ type pane interface { Gesture(*gestic.GestureMessage) } +type lockable interface { + Locked() bool +} + type Matrix struct { Disconnected chan bool log *logger.Logger @@ -83,7 +87,12 @@ func (m *Matrix) start() { m.log.Errorf("Pane returned an error: %s", err) } - if err := m.outgoing.Encode(&Incoming{img, err, m.pane.KeepAwake()}); err != nil { + var locked = false + if lockablePane, ok := m.pane.(lockable); ok { + locked = lockablePane.Locked() + } + + if err := m.outgoing.Encode(&Incoming{img, err, m.pane.KeepAwake(), locked}); err != nil { m.log.Errorf("Remote matrix error: %s. Disconnecting.", err) m.Close() break diff --git a/remote/RemotePane.go b/remote/RemotePane.go index d21b3c7..78e8d9c 100644 --- a/remote/RemotePane.go +++ b/remote/RemotePane.go @@ -24,6 +24,7 @@ type Pane struct { enabled bool incomingFrames chan *Incoming keepAwake bool + locked bool } type Outgoing struct { @@ -35,6 +36,7 @@ type Incoming struct { Image *image.RGBA Err error KeepAwake bool + Locked bool } func NewPane(conn net.Conn) *Pane { @@ -74,6 +76,10 @@ func (p *Pane) KeepAwake() bool { return p.keepAwake } +func (p *Pane) Locked() bool { + return p.locked +} + func (p *Pane) Gesture(gesture *gestic.GestureMessage) { if !p.enabled { return @@ -106,6 +112,7 @@ func (p *Pane) listen() { } p.keepAwake = msg.KeepAwake + p.locked = msg.Locked p.incomingFrames <- &msg } diff --git a/ui/PaneLayout.go b/ui/PaneLayout.go index 4a41bb7..6eabb01 100644 --- a/ui/PaneLayout.go +++ b/ui/PaneLayout.go @@ -137,6 +137,10 @@ type Pane interface { Gesture(*gestic.GestureMessage) } +type lockable interface { + Locked() bool +} + func (l *PaneLayout) Wake() { l.log.Infof("Waking up") @@ -206,25 +210,36 @@ func (l *PaneLayout) OnGesture(g *gestic.GestureMessage) { // Ignore all gestures while we're fading in or out if l.fadeTween == nil { - if g.Gesture.Gesture == gestic.GestureFlickEastToWest { - l.panBy(1) - l.log.Infof("East to west, panning by 1") + pane := l.panes[l.currentPane] + + if pane == nil { + return } - if g.Gesture.Gesture == gestic.GestureFlickWestToEast { - l.panBy(-1) - l.log.Infof("West to east, panning by -1") + // Panes implementing lockable can force the pane layout to stay on them. + // This should only be done temporarily to force display some information, + // or to interact using east-to-west or west-to-east gestures + var locked = false + if lockablePane, ok := pane.(lockable); ok { + locked = lockablePane.Locked() } - // Don't send gestures to panes while we are panning - if l.panTween == nil { - pane := l.panes[l.currentPane] + if !locked { + if g.Gesture.Gesture == gestic.GestureFlickEastToWest { + l.panBy(1) + l.log.Infof("East to west, panning by 1") + } - // Sometimes they can disappear. - if pane != nil { - pane.Gesture(g) + if g.Gesture.Gesture == gestic.GestureFlickWestToEast { + l.panBy(-1) + l.log.Infof("West to east, panning by -1") } } + + // Don't send gestures to panes while we are panning + if l.panTween == nil { + pane.Gesture(g) + } } }