From e316f3b1c2db527b27bd6a0b7b7c9095a5d62953 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 28 Feb 2022 12:02:16 +0100 Subject: [PATCH] cmd/tailscale: improve focus navigation This change prevents focusing hidden widgets or widgets under modal dialogs. For tailscale/tailscale#1611 Signed-off-by: Elias Naur --- cmd/tailscale/ui.go | 46 ++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/cmd/tailscale/ui.go b/cmd/tailscale/ui.go index 5633ae3..eb27f14 100644 --- a/cmd/tailscale/ui.go +++ b/cmd/tailscale/ui.go @@ -245,22 +245,39 @@ func mulAlpha(c color.NRGBA, alpha uint8) color.NRGBA { } func (ui *UI) onBack() bool { + b := ui.activeDialog() + if b == nil { + return false + } + *b = false + return true +} + +func (ui *UI) activeDialog() *bool { switch { case ui.menu.show: - ui.menu.show = false - return true + return &ui.menu.show case ui.shareDialog.show: - ui.shareDialog.show = false - return true + return &ui.shareDialog.show case ui.exitDialog.show: - ui.exitDialog.show = false - return true + return &ui.exitDialog.show } - return false + return nil } func (ui *UI) layout(gtx layout.Context, sysIns system.Insets, state *clientState) []UIEvent { + // "Get started". + if ui.intro.show { + if ui.intro.start.Clicked() { + ui.store.WriteBool(keyShowIntro, false) + ui.intro.show = false + } + ui.layoutIntro(gtx, sysIns) + return nil + } + var events []UIEvent + if ui.enabled.Changed() { events = append(events, ConnectEvent{Enable: ui.enabled.Value}) } @@ -397,7 +414,11 @@ func (ui *UI) layout(gtx layout.Context, sysIns system.Insets, state *clientStat const numHeaders = 6 n := numHeaders + len(state.Peers) needsLogin := state.backend.State == ipn.NeedsLogin - ui.root.Layout(gtx, n, func(gtx C, idx int) D { + rootGtx := gtx + if ui.activeDialog() != nil { + rootGtx.Queue = nil + } + ui.root.Layout(rootGtx, n, func(gtx C, idx int) D { var in layout.Inset if idx == n-1 { // The last list element includes the bottom system @@ -473,15 +494,6 @@ func (ui *UI) layout(gtx layout.Context, sysIns system.Insets, state *clientStat ui.layoutMenu(gtx, sysIns, expiry, exitID != "" || len(state.backend.Exits) > 0) } - // "Get started". - if ui.intro.show { - if ui.intro.start.Clicked() { - ui.store.WriteBool(keyShowIntro, false) - ui.intro.show = false - } - ui.layoutIntro(gtx, sysIns) - } - return events }