Fix queue mouse support

This commit is contained in:
Trevor Slocum 2020-05-01 16:35:50 -07:00
parent 7cb0e70d2f
commit 6a163f3229
5 changed files with 54 additions and 29 deletions

View file

@ -213,7 +213,7 @@ func skipPrevious() {
}
queuePrevious()
go queueSelect()
go queueSelect(queueList.GetCurrentItem())
}
func skipNext() {
@ -222,7 +222,7 @@ func skipNext() {
}
queueNext()
go queueSelect()
go queueSelect(queueList.GetCurrentItem())
}
func roundUnit(x, unit float64) float64 {

6
go.mod
View file

@ -14,10 +14,10 @@ require (
github.com/mewkiz/pkg v0.0.0-20200411195739-f6b5e26764c3 // indirect
github.com/pkg/errors v0.9.1 // indirect
gitlab.com/tslocum/cbind v0.1.1
gitlab.com/tslocum/cview v1.4.6-0.20200428215940-66d27850585b
gitlab.com/tslocum/cview v1.4.6-0.20200501230822-52150da761fb
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5 // indirect
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 // indirect
golang.org/x/mobile v0.0.0-20200329125638-4c31acba0007 // indirect
golang.org/x/sys v0.0.0-20200428200454-593003d681fa // indirect
golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 // indirect
gopkg.in/yaml.v2 v2.2.8
)

12
go.sum
View file

@ -57,8 +57,8 @@ github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
gitlab.com/tslocum/cbind v0.1.1 h1:JXXtxMWHgWLvoF+QkrvcNvOQ59juy7OE1RhT7hZfdt0=
gitlab.com/tslocum/cbind v0.1.1/go.mod h1:rX7vkl0pUSg/yy427MmD1FZAf99S7WwpUlxF/qTpPqk=
gitlab.com/tslocum/cview v1.4.6-0.20200428215940-66d27850585b h1:vUWH84j1UTgAj95bS8qdZPTuU/MZQNAAzTTFQLpp61U=
gitlab.com/tslocum/cview v1.4.6-0.20200428215940-66d27850585b/go.mod h1:85Ec3ByMemrI3tUK4Rpd8jcF3J7maOFHGwzlNnCrPVI=
gitlab.com/tslocum/cview v1.4.6-0.20200501230822-52150da761fb h1:abb4b3nSQrl9t++rZ1ale32XElX/hXkYrDdqHxr4JAw=
gitlab.com/tslocum/cview v1.4.6-0.20200501230822-52150da761fb/go.mod h1:85Ec3ByMemrI3tUK4Rpd8jcF3J7maOFHGwzlNnCrPVI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@ -71,8 +71,8 @@ golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86h
golang.org/x/image v0.0.0-20190220214146-31aff87c08e9/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 h1:5h3ngYt7+vXCDZCup/HkCQgW5XwmSvR/nA2JmJ0RErg=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 h1:6WW6V3x1P/jokJBpRQYUJnMHRP6isStQwCozxnU7XQw=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mobile v0.0.0-20180806140643-507816974b79/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
@ -98,8 +98,8 @@ golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f h1:gWF768j/LaZugp8dyS4UwsslYCYz9XgFxvlgsn0n9H8=
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200428200454-593003d681fa h1:yMbJOvnfYkO1dSAviTu/ZguZWLBTXx4xE3LYrxUCCiA=
golang.org/x/sys v0.0.0-20200428200454-593003d681fa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 h1:5B6i6EAiSYyejWfvc5Rc9BbI3rzIsrrXfAQBWnYfn+w=
golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=

21
gui.go
View file

@ -90,6 +90,7 @@ func initTUI() error {
mainList.SetSelectedFunc(handleMainSelection)
queueList.SetBorder(true).SetTitleAlign(cview.AlignLeft).SetTitle(" Queue ")
queueList.SetSelectedFunc(handleQueueSelection)
grid.AddItem(mainList, 0, 0, 1, 1, 0, 0, false)
grid.AddItem(queueList, 1, 0, 1, 1, 0, 0, false)
@ -98,13 +99,21 @@ func initTUI() error {
app.SetRoot(grid, true)
focusUpdated()
focusUpdated(true)
return nil
}
func handleBeforeFocus(p cview.Primitive) bool {
return p == mainList || p == queueList
focusMain := p == mainList
focusQueue := p == queueList
if focusMain || focusQueue {
queueFocused = focusQueue
focusUpdated(false)
return true
}
return false
}
func browseFolder(browse string) {
@ -206,8 +215,10 @@ func updateMain() {
mainList.SetTitle(" " + cview.Escape(runewidth.Truncate(mainBuffer.String(), screenWidth-4, "...")) + " ")
mainBuffer.Reset()
mainOffset := 0
if mainCursor == -1 {
mainCursor = mainList.GetCurrentItem()
mainOffset = mainList.GetOffset()
}
mainList.Clear()
@ -245,6 +256,8 @@ func updateMain() {
printed++
}
mainList.SetOffset(mainOffset)
if mainCursor >= mainList.GetItemCount() {
mainList.SetCurrentItem(mainList.GetItemCount() - 1)
} else if mainCursor >= 0 {
@ -456,3 +469,7 @@ func handleResize(width int, height int) {
func handleMainSelection(i int, s string, s2 string, r rune) {
go listSelect(i)
}
func handleQueueSelection(i int, s string, s2 string, r rune) {
go queueSelect(i)
}

View file

@ -39,15 +39,14 @@ func queueNext() {
}
func listSelectCurrent() {
go listSelect(mainList.GetCurrentItem())
if queueFocused {
go queueSelect(queueList.GetCurrentItem())
} else {
go listSelect(mainList.GetCurrentItem())
}
}
func listSelect(cursor int) {
if queueFocused {
queueSelect()
return
}
if cursor == 0 {
browseFolder(path.Join(mainDirectory, ".."))
return
@ -79,10 +78,13 @@ func listSelect(cursor int) {
go app.QueueUpdateDraw(updateStatus)
}
func queueSelect() {
entry := selectedQueueEntry()
func queueSelect(cursor int) {
if cursor < 0 || cursor > len(queueFiles) {
return
}
entry := queueFiles[cursor]
if entry.File.IsDir() {
// TODO error
return
}
@ -119,7 +121,7 @@ func listQueue() {
queueLock.Unlock()
if !disableAutoplay && playingFileID == 0 && len(queueFiles) > 0 {
queueSelect()
queueSelect(queueList.GetCurrentItem())
}
go app.QueueUpdateDraw(updateQueue)
return
@ -131,7 +133,7 @@ func listQueue() {
queueFiles = append(queueFiles, entry)
if !disableAutoplay && playingFileID == 0 {
queueSelect()
queueSelect(queueList.GetCurrentItem())
}
go app.QueueUpdateDraw(updateLists)
}
@ -238,12 +240,14 @@ func listToggleHidden() {
func toggleFocusedList() {
queueFocused = !queueFocused
focusUpdated()
focusUpdated(true)
}
func focusUpdated() {
func focusUpdated(setFocus bool) {
if queueFocused {
app.SetFocus(queueList)
if setFocus {
app.SetFocus(queueList)
}
mainList.SetSelectedTextColor(tcell.ColorWhite)
queueList.SetSelectedTextColor(tcell.ColorBlack)
@ -254,7 +258,9 @@ func focusUpdated() {
mainList.SetSelectedBackgroundColor(tcell.ColorBlack)
queueList.SetSelectedBackgroundColor(tcell.ColorWhite)
} else {
app.SetFocus(mainList)
if setFocus {
app.SetFocus(mainList)
}
mainList.SetSelectedTextColor(tcell.ColorBlack)
queueList.SetSelectedTextColor(tcell.ColorWhite)
@ -269,5 +275,7 @@ func focusUpdated() {
mainList.SetHighlightFullLine(!queueFocused)
queueList.SetHighlightFullLine(queueFocused)
go app.QueueUpdateDraw(updateLists)
if setFocus {
go app.QueueUpdateDraw(updateLists)
}
}