Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable staticcheck and fix all issues #144

Merged
merged 7 commits into from
Dec 16, 2020
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
29 changes: 0 additions & 29 deletions .github/workflows/code_checks.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go
go:
- "1.12.x"
- "1.13.x"
- "1.15.x"
os:
- linux
- osx
Expand Down
5 changes: 2 additions & 3 deletions internal/icon/fdo.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ func extractArgs(args []string) []string {
//Run executes the command for this fdo app
func (data *fdoApplicationData) Run(env []string) error {
vars := os.Environ()
for _, e := range env {
vars = append(vars, e)
}
vars = append(vars, env...)

commands := strings.Split(data.exec, " ")
command := commands[0]
if command[0] == '"' {
Expand Down
5 changes: 5 additions & 0 deletions internal/icon/macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func (m *macOSAppBundle) Icon(_ string, _ int) fyne.Resource {

var data bytes.Buffer
err = png.Encode(&data, icon)
if err != nil {
fyne.LogError("Failed to encode icon data for "+m.iconPath, err)
return wmtheme.BrokenImageIcon
}

iconName := filepath.Base(m.iconPath)
return fyne.NewStaticResource(strings.Replace(iconName, ".icns", ".png", 1), data.Bytes())
}
Expand Down
1 change: 1 addition & 0 deletions internal/icon/xpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestParseColor(t *testing.T) {

id, c = parseColor(" c #000000", 1) // special case, id is spaces
assert.Equal(t, " ", id)
assert.Equal(t, &color.NRGBA{R: 0x0, G: 0x0, B: 0x0, A: 0xff}, c)
}

func TestParseDimensions(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions internal/ui/background.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import (
type background struct {
widget.BaseWidget

objects []fyne.CanvasObject
wallpaper *canvas.Image
wallpaperPath string
objects []fyne.CanvasObject
wallpaper *canvas.Image
}

func (b *background) CreateRenderer() fyne.WidgetRenderer {
Expand Down
9 changes: 4 additions & 5 deletions internal/ui/bar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fyne.io/fyne"
"fyne.io/fyne/test"
"fyne.io/fyne/theme"
"fyne.io/fyne/widget"

wmTest "fyne.io/fynedesk/test"
wmTheme "fyne.io/fynedesk/theme"
Expand Down Expand Up @@ -144,7 +143,7 @@ func TestZoomScaleChange(t *testing.T) {

testBar.mouseInside = true
testBar.mousePosition = testBar.children[0].Position()
widget.Refresh(testBar)
testBar.Refresh()
firstWidth := testBar.children[0].Size().Width

testBar.desk.Settings().(*wmTest.Settings).SetLauncherZoomScale(2.0)
Expand All @@ -153,7 +152,7 @@ func TestZoomScaleChange(t *testing.T) {

testBar.mouseInside = true
testBar.mousePosition = testBar.children[0].Position()
widget.Refresh(testBar)
testBar.Refresh()
secondWidth := testBar.children[0].Size().Width

zoomTest := false
Expand All @@ -173,7 +172,7 @@ func TestIconZoomDisabled(t *testing.T) {

testBar.mouseInside = true
testBar.mousePosition = testBar.children[0].Position()
widget.Refresh(testBar)
testBar.Refresh()

width := testBar.children[0].Size().Width
assert.NotEqual(t, testBar.desk.Settings().LauncherIconSize(), width)
Expand All @@ -184,7 +183,7 @@ func TestIconZoomDisabled(t *testing.T) {

testBar.mouseInside = true
testBar.mousePosition = testBar.children[0].Position()
widget.Refresh(testBar)
testBar.Refresh()

width = testBar.children[0].Size().Width
assert.Equal(t, testBar.desk.Settings().LauncherIconSize(), width)
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/baricon.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (bi *barIcon) TappedSecondary(*fyne.PointEvent) {

c := fyne.CurrentApp().Driver().CanvasForObject(bi)
pos := fyne.CurrentApp().Driver().AbsolutePositionForObject(bi)
menu = widget.NewPopUpMenuAtPosition(fyne.NewMenu("", []*fyne.MenuItem{addRemove}...), c, pos)
menu = widget.NewPopUpMenuAtPosition(fyne.NewMenu("", []*fyne.MenuItem{addRemove}...), c, pos) //lint:ignore SA1019 Sort this out when deprecations gets sorted out upstream
}

// CreateRenderer is a private method to fyne which links this widget to its renderer
Expand Down
3 changes: 2 additions & 1 deletion internal/ui/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ui

import (
"fyne.io/fyne"
"fyne.io/fyne/container"
deskDriver "fyne.io/fyne/driver/desktop"
"fyne.io/fyne/layout"
"fyne.io/fyne/theme"
Expand Down Expand Up @@ -157,7 +158,7 @@ func newAppPicker(title string, callback func(fynedesk.AppData)) *picker {
})

appList := fyne.NewContainerWithLayout(layout.NewVBoxLayout())
appScroller := widget.NewScrollContainer(appList)
appScroller := container.NewScroll(appList)
l := &picker{win: win, desk: fynedesk.Instance(), appList: appList, callback: callback}

entry := &appEntry{pick: l}
Expand Down
1 change: 0 additions & 1 deletion internal/ui/screens_embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type embeddedScreensProvider struct {
}

func (esp embeddedScreensProvider) RefreshScreens() {
return
}

func (esp embeddedScreensProvider) AddChangeListener(func()) {
Expand Down
27 changes: 13 additions & 14 deletions internal/ui/settings_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (d *settingsUI) populateThemeIcons(box *fyne.Container, theme string) {
}
iconRes := appData.Icon(theme, int((float64(d.settings.LauncherIconSize())*d.settings.LauncherZoomScale())*float64(fynedesk.Instance().Screens().Primary().CanvasScale())))
icon := widget.NewIcon(iconRes)
box.AddObject(icon)
box.Add(icon)
}
box.Refresh()
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func (d *settingsUI) loadAppearanceScreen() fyne.CanvasObject {
}))

clockLabel := widget.NewLabelWithStyle("Clock Format", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
clockFormat := &widget.Radio{Options: []string{"12h", "24h"}, Required: true, Horizontal: true}
clockFormat := &widget.RadioGroup{Options: []string{"12h", "24h"}, Required: true, Horizontal: true}
clockFormat.SetSelected(d.settings.ClockFormatting())

themeLabel := widget.NewLabel(d.settings.IconTheme())
Expand All @@ -102,7 +102,7 @@ func (d *settingsUI) loadAppearanceScreen() fyne.CanvasObject {
themeLabel.SetText(themeButton.Text)
d.populateThemeIcons(themeIcons, themeButton.Text)
}
themeList.AddObject(themeButton)
themeList.Add(themeButton)
}

bg := fyne.NewContainerWithLayout(layout.NewBorderLayout(nil, nil, bgLabel, bgButtons), bgLabel, bgPath, bgButtons)
Expand All @@ -111,8 +111,7 @@ func (d *settingsUI) loadAppearanceScreen() fyne.CanvasObject {

themeFormLabel := widget.NewLabelWithStyle("Icon Theme", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
themeCurrent := widget.NewHBox(layout.NewSpacer(), themeLabel, themeIcons)
bottom := fyne.NewContainerWithLayout(layout.NewBorderLayout(nil, themeCurrent, themeFormLabel, nil),
themeCurrent, themeFormLabel, widget.NewScrollContainer(themeList))
bottom := fyne.NewContainerWithLayout(layout.NewBorderLayout(nil, themeCurrent, themeFormLabel, nil), themeCurrent, themeFormLabel, container.NewScroll(themeList))

applyButton := widget.NewHBox(layout.NewSpacer(),
&widget.Button{Text: "Apply", Style: widget.PrimaryButton, OnTapped: func() {
Expand Down Expand Up @@ -190,7 +189,7 @@ func (d *settingsUI) loadBarScreen() fyne.CanvasObject {
}).Show()
}

bar := widget.NewHScrollContainer(orderList)
bar := container.NewHScroll(orderList)

iconSize := widget.NewEntry()
iconSize.SetText(fmt.Sprintf("%d", d.settings.LauncherIconSize()))
Expand Down Expand Up @@ -283,7 +282,7 @@ func (d *settingsUI) loadKeyboardScreen() fyne.CanvasObject {
rows := widget.NewHBox(widget.NewGroup("Action", names...),
widget.NewGroup("Modifier", mods...),
widget.NewGroup("Key Name", keys...))
grid := widget.NewScrollContainer(rows)
grid := container.NewScroll(rows)

applyButton := widget.NewHBox(layout.NewSpacer(),
&widget.Button{Text: "Apply", Style: widget.PrimaryButton, OnTapped: func() {
Expand Down Expand Up @@ -341,17 +340,17 @@ func showSettings(deskSettings *deskSettings) {
ui.win = w
fyneSettings := settings.NewSettings()

tabs := widget.NewTabContainer(
&widget.TabItem{Text: "Fyne Settings", Icon: theme.FyneLogo(),
tabs := container.NewAppTabs(
&container.TabItem{Text: "Fyne Settings", Icon: theme.FyneLogo(),
Content: fyneSettings.LoadAppearanceScreen(w)},
&widget.TabItem{Text: "Appearance", Icon: fyneSettings.AppearanceIcon(),
&container.TabItem{Text: "Appearance", Icon: fyneSettings.AppearanceIcon(),
Content: ui.loadAppearanceScreen()},
&widget.TabItem{Text: "App Bar", Icon: wmtheme.IconifyIcon, Content: ui.loadBarScreen()},
&widget.TabItem{Text: "Keyboard", Icon: wmtheme.KeyboardIcon, Content: ui.loadKeyboardScreen()},
&widget.TabItem{Text: "Advanced", Icon: theme.SettingsIcon(),
&container.TabItem{Text: "App Bar", Icon: wmtheme.IconifyIcon, Content: ui.loadBarScreen()},
&container.TabItem{Text: "Keyboard", Icon: wmtheme.KeyboardIcon, Content: ui.loadKeyboardScreen()},
&container.TabItem{Text: "Advanced", Icon: theme.SettingsIcon(),
Content: ui.loadAdvancedScreen()},
)
tabs.SetTabLocation(widget.TabLocationLeading)
tabs.SetTabLocation(container.TabLocationLeading)
w.SetContent(tabs)

w.Resize(fyne.NewSize(480, 320))
Expand Down
3 changes: 2 additions & 1 deletion internal/ui/widgetpanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,12 @@ func (w *widgetPanel) showAccountMenu(from fyne.CanvasObject) {
w.desk.WindowManager().Close()
}))

popup := widget.NewPopUpMenu(fyne.NewMenu("Account", items...), root.Canvas())
popup := widget.NewPopUpMenuAtPosition(fyne.NewMenu("Account", items...), root.Canvas(), fyne.NewPos(0, 0)) //lint:ignore SA1019 Sort this out when deprecations gets sorted out upstream

bottomLeft := fyne.CurrentApp().Driver().AbsolutePositionForObject(from)
popup.Move(bottomLeft.Subtract(fyne.NewPos(0, popup.MinSize().Height)))
popup.Resize(fyne.NewSize(from.Size().Width, popup.MinSize().Height))
popup.Show()
}

func (w *widgetPanel) CreateRenderer() fyne.WidgetRenderer {
Expand Down
27 changes: 13 additions & 14 deletions internal/x11/win/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,14 @@ func (c *client) Close() {
fyne.LogError("Get Delete Window Error", err)
return
}
cm, err := xevent.NewClientMessage(32, c.win, protocols,
int(delWin))
err = xproto.SendEventChecked(c.wm.Conn(), false, c.win, 0,
string(cm.Bytes())).Check()

cm, err := xevent.NewClientMessage(32, c.win, protocols, int(delWin))
if err != nil {
fyne.LogError("Get ClientMessage Error", err)
return
}

err = xproto.SendEventChecked(c.wm.Conn(), false, c.win, 0, string(cm.Bytes())).Check()
if err != nil {
fyne.LogError("Window Delete Error", err)
}
Expand Down Expand Up @@ -293,10 +297,7 @@ func (c *client) SizeMin() (uint, uint) {
}

func (c *client) TopWindow() bool {
if c.wm.TopWindow() == c {
return true
}
return false
return c.wm.TopWindow() == c
}

func (c *client) Unfullscreen() {
Expand All @@ -317,10 +318,6 @@ func (c *client) fullscreenMessage(action x11.WindowStateAction) {
ewmh.WmStateReq(c.wm.X(), c.win, int(action), "_NET_WM_STATE_FULLSCREEN")
}

func (c *client) getWindowGeometry() (int16, int16, uint16, uint16) {
return c.frame.getGeometry()
}

func (c *client) maximizeMessage(action x11.WindowStateAction) {
ewmh.WmStateReqExtra(c.wm.X(), c.win, int(action), "_NET_WM_STATE_MAXIMIZED_VERT",
"_NET_WM_STATE_MAXIMIZED_HORZ", 1)
Expand Down Expand Up @@ -375,11 +372,13 @@ func (c *client) stateMessage(state int) {
fyne.LogError("Error getting X Atom", err)
return
}
cm, err := xevent.NewClientMessage(32, c.win, stateChangeAtom,
state)
cm, err := xevent.NewClientMessage(32, c.win, stateChangeAtom, state)
if err != nil {
fyne.LogError("Error creating client message", err)
return
}
err = xevent.SendRootEvent(c.wm.X(), cm, xproto.EventMaskSubstructureNotify|xproto.EventMaskSubstructureRedirect)
if err != nil {
fyne.LogError("Error sending root event", err)
}
}
56 changes: 25 additions & 31 deletions internal/x11/win/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (f *frame) drawDecoration(pidTop xproto.Pixmap, drawTop xproto.Gcontext, pi
b.SetMaximized(f.client.maximized)
// TODO maybe update icon?
}
f.canvas.SetScale(scale)
Jacalz marked this conversation as resolved.
Show resolved Hide resolved
f.canvas.SetScale(scale) //lint:ignore SA1019 Sort this out when other scaling changes are done

heightPix := x11.TitleHeight(x11.XWin(f.client))
iconBorderPixWidth := heightPix + x11.BorderWidth(x11.XWin(f.client))*2
Expand Down Expand Up @@ -370,10 +370,6 @@ func (f *frame) freePixmaps() {
}
}

func (f *frame) getGeometry() (int16, int16, uint16, uint16) {
return f.x, f.y, f.width, f.height
}

func (f *frame) getInnerWindowCoordinates(w uint16, h uint16) (uint32, uint32, uint32, uint32) {
if f.client.Fullscreened() || !f.client.Properties().Decorated() {
constrainW, constrainH := w, h
Expand Down Expand Up @@ -644,34 +640,32 @@ func (f *frame) mouseReleaseWaitForDoubleClick(relX int, relY int) {
var ctx context.Context
ctx, f.cancelFunc = context.WithDeadline(context.TODO(), time.Now().Add(time.Millisecond*300))
defer f.cancelFunc()
select {
case <-ctx.Done():
if f.clickCount == 2 {
obj := wm.FindObjectAtPixelPositionMatching(relX, relY, f.canvas,
func(obj fyne.CanvasObject) bool {
_, ok := obj.(fyne.DoubleTappable)
return ok
},
)
if obj != nil {
obj.(fyne.DoubleTappable).DoubleTapped(&fyne.PointEvent{})
}
} else {
obj := wm.FindObjectAtPixelPositionMatching(relX, relY, f.canvas,
func(obj fyne.CanvasObject) bool {
_, ok := obj.(fyne.Tappable)
return ok
},
)
if obj != nil {
obj.(fyne.Tappable).Tapped(&fyne.PointEvent{})
}
}

f.clickCount = 0
f.cancelFunc = nil
return
<-ctx.Done()
if f.clickCount == 2 {
obj := wm.FindObjectAtPixelPositionMatching(relX, relY, f.canvas,
func(obj fyne.CanvasObject) bool {
_, ok := obj.(fyne.DoubleTappable)
return ok
},
)
if obj != nil {
obj.(fyne.DoubleTappable).DoubleTapped(&fyne.PointEvent{})
}
} else {
obj := wm.FindObjectAtPixelPositionMatching(relX, relY, f.canvas,
func(obj fyne.CanvasObject) bool {
_, ok := obj.(fyne.Tappable)
return ok
},
)
if obj != nil {
obj.(fyne.Tappable).Tapped(&fyne.PointEvent{})
}
}

f.clickCount = 0
f.cancelFunc = nil
}

// Notify the child window that it's geometry has changed to update menu positions etc.
Expand Down
Loading