Skip to content

Commit

Permalink
Allow panes to lock the screen (prevent swiping away)
Browse files Browse the repository at this point in the history
  • Loading branch information
☃ Elliot Shepherd committed Mar 24, 2015
1 parent 14c514c commit 0694e60
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
11 changes: 10 additions & 1 deletion remote/RemoteMatrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type pane interface {
Gesture(*gestic.GestureMessage)
}

type lockable interface {
Locked() bool
}

type Matrix struct {
Disconnected chan bool
log *logger.Logger
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions remote/RemotePane.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Pane struct {
enabled bool
incomingFrames chan *Incoming
keepAwake bool
locked bool
}

type Outgoing struct {
Expand All @@ -35,6 +36,7 @@ type Incoming struct {
Image *image.RGBA
Err error
KeepAwake bool
Locked bool
}

func NewPane(conn net.Conn) *Pane {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -106,6 +112,7 @@ func (p *Pane) listen() {
}

p.keepAwake = msg.KeepAwake
p.locked = msg.Locked

p.incomingFrames <- &msg
}
Expand Down
39 changes: 27 additions & 12 deletions ui/PaneLayout.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ type Pane interface {
Gesture(*gestic.GestureMessage)
}

type lockable interface {
Locked() bool
}

func (l *PaneLayout) Wake() {

l.log.Infof("Waking up")
Expand Down Expand 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)
}
}
}

Expand Down

0 comments on commit 0694e60

Please sign in to comment.