Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ jobs:
# native structure ABI tests are here for the same reason: they build only
# on Windows.
- name: Material contracts and controls (WARP)
run: go test ./internal/platform/windows ./ui ./components ./headless ./app -run 'Test(Backdrop|WindowBackdrop|Notification|TaskbarCreated|CompositionClear|CompositionFallback|CompositionCreation|CustomBackdrop|AcrylicAccent|LegacyAcrylic|RoundedOutline|Translucent|MonospaceFamilies|FontWeights|MonoWeights|InterfaceWeights|EveryListedFamilyResolves|EngineReportsTheFontsUnderline|AlwaysOnTop|SaveDialogCheckbox|FileIcon|NativeStructureABI)' -count=1 -v
run: go test ./internal/platform/windows ./ui ./components ./headless ./app -run 'Test(Backdrop|WindowBackdrop|Notification|TaskbarCreated|CompositionClear|CompositionFallback|CompositionCreation|CustomBackdrop|AcrylicAccent|LegacyAcrylic|RoundedOutline|Translucent|MonospaceFamilies|FontWeights|(The)?MonoWeights|(The)?InterfaceWeights|EveryListedFamilyResolves|EngineReportsTheFontsUnderline|AlwaysOnTop|SaveDialogCheckbox|FileIcon|NativeStructureABI)' -count=1 -v
- name: Terminal keyboard routing
run: go test ./internal/platform/windows -run '^TestATerminalGetsEditingKeysAndChordsAsRawKeys$' -count=1 -v
- name: Native Windows global shortcut
Expand Down
5 changes: 4 additions & 1 deletion cmd/viva/templates/tree.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type TreeItem struct {
Expanded bool
Selected bool
Disabled bool
// Dragging marks the row being dragged: it keeps its chosen fill but gives
// up its focus ring, which otherwise reads as the drop target.
Dragging bool
}

// TreeRow is the geometry reserved for caller-owned row content.
Expand Down Expand Up @@ -105,7 +108,7 @@ func (tree *Tree) Item(item TreeItem) TreeRow {

enabled := !item.Disabled && !item.ID.IsZero()
hovered := enabled && tree.canvas.Hovered() == item.ID
focused := enabled && tree.canvas.FocusVisible() == item.ID
focused := enabled && !item.Dragging && tree.canvas.FocusVisible() == item.ID
radius := tree.theme.Metrics.RadiusControl
if item.Selected || hovered {
background := tree.theme.Muted
Expand Down
5 changes: 4 additions & 1 deletion components/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type TreeItem struct {
Expanded bool
Selected bool
Disabled bool
// Dragging marks the row being dragged: it keeps its chosen fill but gives
// up its focus ring, which otherwise reads as the drop target.
Dragging bool
}

// TreeRow is the geometry reserved for caller-owned row content.
Expand Down Expand Up @@ -105,7 +108,7 @@ func (tree *Tree) Item(item TreeItem) TreeRow {

enabled := !item.Disabled && !item.ID.IsZero()
hovered := enabled && tree.canvas.Hovered() == item.ID
focused := enabled && tree.canvas.FocusVisible() == item.ID
focused := enabled && !item.Dragging && tree.canvas.FocusVisible() == item.ID
radius := tree.theme.Metrics.RadiusControl
if item.Selected || hovered {
background := tree.theme.Muted
Expand Down
29 changes: 29 additions & 0 deletions components/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,32 @@ func BenchmarkTreePaint(b *testing.B) {
}
}
}

// The row being dragged gives up its focus ring so the drop target is the only
// strong outline on screen; the same focused row shows the ring when it is not
// being dragged.
func TestTreeDraggingRowDropsTheFocusRing(t *testing.T) {
var canvas gfx.Canvas
theme := gfx.DarkTheme()
tree := BeginTree(&canvas, theme, gfx.Rect{Width: 200, Height: 100}).RowHeight(32)
ring := theme.Ring
ring.Alpha *= 0.50
paintedRing := func(dragging bool) bool {
canvas.Reset()
canvas.SetInteraction(gfx.ID{}, gfx.ID{}, gfx.Item(1), true)
tree.cursorY = tree.bounds.Y
tree.Item(TreeItem{ID: gfx.Item(1), Label: "Row", Dragging: dragging})
for _, rectangle := range canvas.Rectangles() {
if rectangle.Color == ring {
return true
}
}
return false
}
if paintedRing(true) {
t.Fatal("the dragged row painted its focus ring")
}
if !paintedRing(false) {
t.Fatal("a focused row that is not dragged painted no focus ring")
}
}
37 changes: 35 additions & 2 deletions internal/platform/linux/post_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,49 @@ func (application *linuxApplication) Post(fn func()) {
}
application.postMu.Lock()
application.posts = append(application.posts, fn)
// postWake means a drain is already on its way to a window. Coalescing is
// only safe once that is true: with no window to carry the wake the message
// is dropped, and a flag left set would swallow every later post.
if !application.postWake.Load() && application.deliver(commandPost) {
application.postWake.Store(true)
}
application.postMu.Unlock()
if application.postWake.CompareAndSwap(false, true) {
application.post(commandPost)
}

// wakePosts asks the loop to drain work accepted before a window could carry
// the wake. OpenWindow calls it once the new window is live and polled.
func (application *linuxApplication) wakePosts() {
application.postMu.Lock()
defer application.postMu.Unlock()
if len(application.posts) == 0 || application.postWake.Load() {
return
}
if application.deliver(commandPost) {
application.postWake.Store(true)
}
}

// rearmPosts sends the wake again after the live windows changed. A wake that
// was handed to a window which has since closed went with that window, so the
// flag is cleared and the wake goes to whichever windows remain.
func (application *linuxApplication) rearmPosts() {
application.postMu.Lock()
defer application.postMu.Unlock()
application.postWake.Store(false)
if len(application.posts) == 0 {
return
}
if application.deliver(commandPost) {
application.postWake.Store(true)
}
}

// drainPosts runs the functions accepted since the last drain, in order. A
// function that posts another is picked up by this same drain.
func (application *linuxApplication) drainPosts() {
application.postMu.Lock()
application.postWake.Store(false)
application.postMu.Unlock()
for {
application.postMu.Lock()
if len(application.posts) == 0 {
Expand Down
92 changes: 92 additions & 0 deletions internal/platform/linux/post_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,95 @@ func TestAWindowsDrainPicksUpWorkPostedWhileItRuns(t *testing.T) {
t.Fatalf("seen = %v, want [1 2]", seen)
}
}

func TestAWakeWithNoWindowDoesNotSwallowTheNextPost(t *testing.T) {
application := &linuxApplication{}
application.Post(func() {})
if application.postWake.Load() {
t.Fatal("a wake stayed pending although no window could carry it")
}
application.liveMu.Lock()
application.live = append(application.live, &window{})
application.liveMu.Unlock()
seen := 0
application.Post(func() { seen++ })
if !application.postWake.Load() {
t.Fatal("the post after a window opened did not ask for a drain")
}
application.drainPosts()
if seen != 1 {
t.Fatalf("seen = %d, want 1", seen)
}
}

func TestAWindowCarriesWorkPostedBeforeIt(t *testing.T) {
application := &linuxApplication{}
seen := 0
application.Post(func() { seen++ })
application.liveMu.Lock()
application.live = append(application.live, &window{})
application.liveMu.Unlock()
application.wakePosts()
if !application.postWake.Load() {
t.Fatal("opening a window did not wake work posted before it")
}
application.drainPosts()
if seen != 1 {
t.Fatalf("seen = %d, want 1", seen)
}
}

func TestAClosedWindowHandsItsWakeToTheRemainingWindow(t *testing.T) {
application := &linuxApplication{}
first, second := &window{}, &window{}
application.liveMu.Lock()
application.live = append(application.live, first)
application.liveMu.Unlock()
seen := 0
application.Post(func() { seen++ })
application.liveMu.Lock()
application.live = append(application.live, second)
application.liveMu.Unlock()
application.wakePosts()
application.removeLive(first)
if !application.postWake.Load() {
t.Fatal("the wake went with the closed window; the remaining window was not woken")
}
application.removeLive(second)
if application.postWake.Load() {
t.Fatal("the wake stayed pending after its last carrier closed")
}
application.liveMu.Lock()
application.live = append(application.live, &window{})
application.liveMu.Unlock()
application.wakePosts()
application.drainPosts()
if seen != 1 {
t.Fatalf("seen = %d, want 1", seen)
}
}

func TestAClosedLastWindowLeavesNoStaleWake(t *testing.T) {
application := &linuxApplication{}
last := &window{}
application.liveMu.Lock()
application.live = append(application.live, last)
application.liveMu.Unlock()
seen := 0
application.Post(func() { seen++ })
application.removeLive(last)
if application.postWake.Load() {
t.Fatal("a wake stayed pending after the last window closed")
}
application.liveMu.Lock()
application.live = append(application.live, &window{})
application.liveMu.Unlock()
application.wakePosts()
if !application.postWake.Load() {
t.Fatal("opening a window after the last one closed did not wake the queued work")
}
application.drainPosts()
if seen != 1 {
t.Fatalf("seen = %d, want 1", seen)
}
}
7 changes: 6 additions & 1 deletion internal/platform/linux/status_item_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,18 @@ func (application *linuxApplication) Quit() { application.post(commandQuit) }
// post sends a command to every window that is still open and lets whichever
// handles it first act. Posting to just one would lose the request when that
// window closes before it reads it, as the tray's panel does when it quits.
func (application *linuxApplication) post(command uint32) {
func (application *linuxApplication) post(command uint32) { application.deliver(command) }

// deliver is post for a caller that cannot afford to lose the request: it
// reports whether a window existed to carry it.
func (application *linuxApplication) deliver(command uint32) bool {
application.liveMu.Lock()
windows := append([]*window(nil), application.live...)
application.liveMu.Unlock()
for _, win := range windows {
win.postClientMessage(win.commandAtom, command)
}
return len(windows) > 0
}

// statusConnection is the session bus connection the status icons own. It is an
Expand Down
24 changes: 16 additions & 8 deletions internal/platform/linux/window_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ func (application *linuxApplication) OpenWindow(config platform.Config) (platfor
application.live = append(application.live, win)
application.liveMu.Unlock()
application.rebuildPoll()
application.wakePosts()
application.atspiOpened(state)
application.retryDesktopWatch()
activeWindow.Store(win)
Expand Down Expand Up @@ -712,6 +713,20 @@ func (application *linuxApplication) contains(target *linuxWindowState) bool {
return false
}

// removeLive takes a closing window out of the live set. Work posted to that
// window may not have been drained, so the wake is re-armed for the rest.
func (application *linuxApplication) removeLive(win *window) {
application.liveMu.Lock()
for at, live := range application.live {
if live == win {
application.live = append(application.live[:at], application.live[at+1:]...)
break
}
}
application.liveMu.Unlock()
application.rearmPosts()
}

func (application *linuxApplication) closeWindow(target *linuxWindowState) {
index := -1
for candidate, state := range application.windows {
Expand All @@ -726,14 +741,7 @@ func (application *linuxApplication) closeWindow(target *linuxWindowState) {
copy(application.windows[index:], application.windows[index+1:])
application.windows[len(application.windows)-1] = nil
application.windows = application.windows[:len(application.windows)-1]
application.liveMu.Lock()
for at, live := range application.live {
if live == target.win {
application.live = append(application.live[:at], application.live[at+1:]...)
break
}
}
application.liveMu.Unlock()
application.removeLive(target.win)
if target.config.Waker != nil && target.config.OnRedraw != nil {
target.config.Waker.Unbind()
}
Expand Down
34 changes: 28 additions & 6 deletions ui/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ func (s *TreeState) Dropped() (TreeMove, bool) { return s.dropped, s.dropped.Fro
// Dragging reports whether a row is being dragged.
func (s *TreeState) Dragging() bool { return s.drag.active }

// DragSource reports the visible row a drag is carrying and where the pointer
// is, while a drag runs. A row no longer shown has no source.
func (s *TreeState) DragSource() (row int, at gfx.Point, ok bool) {
if !s.drag.active {
return 0, gfx.Point{}, false
}
row = s.indexOf(s.drag.from)
if row < 0 {
return 0, gfx.Point{}, false
}
return row, s.drag.at, true
}

// Toggled reports which row's chevron this paint delivers a press on, or Left or
// Right on a branch: the application opens or closes it.
func (s *TreeState) Toggled() (int, bool) { return s.toggled, s.toggled >= 0 }
Expand Down Expand Up @@ -356,14 +369,23 @@ func (s *TreeState) dragOver(row *treeRow, d *DrawContext) {
return
}
theme := d.Theme
left := r.X + float32(row.item.Depth)*s.indent(theme)
switch drag.target.Where {
case TreeDropInside:
d.Canvas.RoundedBorder(r, theme.Metrics.RadiusItem(), 2, theme.Primary, gfx.Color{})
case TreeDropBefore:
d.Canvas.Fill(Rect{X: left, Y: r.Y - 1, Width: r.X + r.Width - left, Height: 2}, theme.Primary)
case TreeDropAfter:
d.Canvas.Fill(Rect{X: left, Y: r.Y + r.Height - 1, Width: r.X + r.Width - left, Height: 2}, theme.Primary)
// A faint wash and a half-strength edge mark the destination, as DBX
// marks the folder it is dropped into; the dragged row's focus ring is
// gone, so this is the only strong outline.
tint := theme.Primary
tint.Alpha *= 0.05
edge := theme.Primary
edge.Alpha *= 0.5
d.Canvas.Rounded(r, theme.Metrics.RadiusItem(), tint)
d.Canvas.RoundedBorder(r, theme.Metrics.RadiusItem(), 2, edge, gfx.Color{})
case TreeDropBefore, TreeDropAfter:
y := r.Y - 1
if drag.target.Where == TreeDropAfter {
y = r.Y + r.Height - 1
}
d.Canvas.Fill(Rect{X: r.X + 8, Y: y, Width: max(r.Width-16, 0), Height: 2}, theme.Primary)
}
}

Expand Down
4 changes: 3 additions & 1 deletion update/download_resume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ func TestDownloadEndsAStalledTransfer(t *testing.T) {
}
}
server, client := newResumeServer(t, stall, serveRanges(content))
client.stall = 50 * time.Millisecond
// Long enough that a loaded runner still delivers the first 2000 bytes before
// the stall fires, short enough to end well inside the test's own deadline.
client.stall = 2 * time.Second
asset := testAsset(server.Server, content)
dir := t.TempDir()

Expand Down
Loading