From 04461bf9e2db44dcda9a882f2cd6539192fec93f Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Thu, 16 Feb 2023 19:40:42 -0800 Subject: [PATCH] on Linux, tracklist selection is always in Ctrl+click mode; GLFW workaround --- ui/widgets/tracklist.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/ui/widgets/tracklist.go b/ui/widgets/tracklist.go index b2d1f11..d586f48 100644 --- a/ui/widgets/tracklist.go +++ b/ui/widgets/tracklist.go @@ -1,6 +1,7 @@ package widgets import ( + "runtime" "strconv" "supersonic/ui/layouts" "supersonic/ui/os" @@ -146,11 +147,24 @@ func (t *Tracklist) onPlayTrackAt(idx int) { } } -func (t *Tracklist) onSelectTrack(idx int) { +// Workaround for https://github.com/dweymouth/supersonic/issues/45 +// On Linux, tracklist selection will always operate in ctrl+click mode +// as this allows multi-select without getting 'stuck' in shift mode +func (t *Tracklist) modifiers() (fyne.KeyModifier, bool) { + if runtime.GOOS == "linux" { + return os.ControlModifier, true + } if d, ok := fyne.CurrentApp().Driver().(desktop.Driver); ok { - if d.ActiveKeyModifiers()&os.ControlModifier != 0 { + return d.ActiveKeyModifiers(), true + } + return 0, false +} + +func (t *Tracklist) onSelectTrack(idx int) { + if mod, ok := t.modifiers(); ok { + if mod&os.ControlModifier != 0 { t.selectionMgr.SelectAddOrRemove(idx) - } else if (d.ActiveKeyModifiers() & fyne.KeyModifierShift) != 0 { + } else if mod&fyne.KeyModifierShift != 0 { t.selectionMgr.SelectRange(idx) } else { t.selectionMgr.Select(idx)