diff --git a/cmd/fynedesk/main.go b/cmd/fynedesk/main.go index 323db1df..31cbf6e5 100644 --- a/cmd/fynedesk/main.go +++ b/cmd/fynedesk/main.go @@ -5,6 +5,7 @@ import ( _ "fyshos.com/fynedesk/modules/composit" _ "fyshos.com/fynedesk/modules/desktops" + _ "fyshos.com/fynedesk/modules/fyles" _ "fyshos.com/fynedesk/modules/launcher" _ "fyshos.com/fynedesk/modules/quaketerm" _ "fyshos.com/fynedesk/modules/status" diff --git a/desk.go b/desk.go index 05a1ad50..a75504d8 100644 --- a/desk.go +++ b/desk.go @@ -18,9 +18,11 @@ type Desktop interface { AddShortcut(shortcut *Shortcut, handler func()) ShowMenuAt(menu *fyne.Menu, pos fyne.Position) + Root() fyne.Window Desktop() int SetDesktop(int) + ShowSettings() } var instance Desktop diff --git a/go.mod b/go.mod index 8f44c64c..8104e502 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/Knetic/govaluate v3.0.0+incompatible github.com/disintegration/imaging v1.6.2 github.com/fyne-io/image v0.0.0-20240417123036-dc0ee9e7c964 + github.com/fyshos/fyles v0.0.0-20240105185750-ba0c41e1f720 github.com/godbus/dbus/v5 v5.1.0 github.com/jackmordaunt/icns v1.0.1-0.20200413110149-9e181b441ab2 github.com/mafik/pulseaudio v0.0.0-20200511091429-8449222912dd @@ -18,6 +19,8 @@ require ( howett.net/plist v0.0.0-20181124034731-591f970eefbb ) +require github.com/creack/pty v1.1.21 // indirect + require ( github.com/BurntSushi/toml v1.4.0 // indirect github.com/jeandeaual/go-locale v0.0.0-20240223122105-ce5225dcaa49 // indirect @@ -31,7 +34,6 @@ require ( github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 // indirect github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect - github.com/creack/pty v1.1.21 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/fredbi/uri v1.1.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect @@ -52,7 +54,7 @@ require ( golang.org/x/image v0.18.0 // indirect golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a // indirect golang.org/x/net v0.25.0 // indirect - golang.org/x/sys v0.20.0 // indirect + golang.org/x/sys v0.20.0 golang.org/x/text v0.16.0 gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index f948d89b..42970fcd 100644 --- a/go.sum +++ b/go.sum @@ -108,6 +108,8 @@ github.com/fyne-io/terminal v0.0.0-20240728203942-56c3b98b9208 h1:ZMTEq3IAv6EQv6 github.com/fyne-io/terminal v0.0.0-20240728203942-56c3b98b9208/go.mod h1:uTxDe2dNdJWfmUAgWwG+leivgNxSfCY50t+AiNdPmiM= github.com/fyne-io/xgbutil v0.0.0-20191220152344-7d838166824d h1:8+poQtDqiRfAZmeyYRlInuaIBsQEflmxtpJeZklvNuE= github.com/fyne-io/xgbutil v0.0.0-20191220152344-7d838166824d/go.mod h1:vPqYMuTmTyrLNDQWQXy9lqdnV+WRQn6jhaSon8TppBs= +github.com/fyshos/fyles v0.0.0-20240105185750-ba0c41e1f720 h1:vxPbMYBDz3sA9Cv1+06yF24p/HssWP2jJjf2u0tNgik= +github.com/fyshos/fyles v0.0.0-20240105185750-ba0c41e1f720/go.mod h1:1g01pnfrasGx2mvHz69XwmgswxWncg41UMzyrqh7b6M= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 h1:zDw5v7qm4yH7N8C8uWd+8Ii9rROdgWxQuGoJ9WDXxfk= github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw= diff --git a/internal/ui/desk.go b/internal/ui/desk.go index c17b5c53..31cb3b5c 100644 --- a/internal/ui/desk.go +++ b/internal/ui/desk.go @@ -5,14 +5,13 @@ import ( "os/exec" "strconv" - "fyshos.com/fynedesk/internal/notify" - "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" deskDriver "fyne.io/fyne/v2/driver/desktop" "fyshos.com/fynedesk" + "fyshos.com/fynedesk/internal/notify" wmtheme "fyshos.com/fynedesk/theme" "fyshos.com/fynedesk/wm" ) @@ -86,11 +85,15 @@ func (l *desktop) SetDesktop(id int) { } } +func (l *desktop) ShowSettings() { + l.widgets.showSettings() +} + func (l *desktop) Layout(objects []fyne.CanvasObject, size fyne.Size) { bg := objects[0].(*background) bg.Resize(size) if l.Settings().NarrowLeftLauncher() { - l.bar.Resize(size) + l.bar.Resize(fyne.NewSize(wmtheme.NarrowBarWidth, size.Height)) l.bar.Move(fyne.NewPos(0, 0)) } else { barHeight := l.bar.MinSize().Height @@ -109,6 +112,10 @@ func (l *desktop) MinSize(_ []fyne.CanvasObject) fyne.Size { return fyne.NewSize(640, 480) // tiny - window manager will scale up to screen size } +func (l *desktop) Root() fyne.Window { + return l.root +} + func (l *desktop) ShowMenuAt(menu *fyne.Menu, pos fyne.Position) { l.showMenu(menu, pos) } @@ -186,7 +193,7 @@ func (l *desktop) ContentBoundsPixels(screen *fynedesk.Screen) (x, y, w, h uint3 screenW := uint32(screen.Width) screenH := uint32(screen.Height) pad := wmtheme.WidgetPanelWidth - if fynedesk.Instance().Settings().NarrowWidgetPanel() { + if l.Settings().NarrowWidgetPanel() { pad = wmtheme.NarrowBarWidth } if l.screens.Primary() == screen { diff --git a/internal/ui/notifications.go b/internal/ui/notifications.go index e12f716d..00b9e5a5 100644 --- a/internal/ui/notifications.go +++ b/internal/ui/notifications.go @@ -33,7 +33,7 @@ func (n *notification) show(list *fyne.Container) { n.popup = fyne.CurrentApp().Driver().(deskDriver.Driver).CreateSplashWindow() n.popup.SetContent(n.renderer) - winSize := fynedesk.Instance().(*desktop).root.Canvas().Size() + winSize := fynedesk.Instance().Root().Canvas().Size() pos := fyne.NewPos(winSize.Width-280-wmtheme.NarrowBarWidth, 10) fynedesk.Instance().WindowManager().ShowOverlay(n.popup, fyne.NewSize(270, 120), pos) } else { diff --git a/internal/ui/settings_ui.go b/internal/ui/settings_ui.go index ba09136d..56b2c395 100644 --- a/internal/ui/settings_ui.go +++ b/internal/ui/settings_ui.go @@ -398,6 +398,7 @@ func (d *settingsUI) loadThemeScreen() fyne.CanvasObject { list, err := storage.List(themes) if err != nil { fyne.LogError("Unable to list themes - missing?", err) + themeList = make([]string, 1) } else { for _, l := range list { themeList = append(themeList, l.Name()) diff --git a/modules/fyles/fyles.go b/modules/fyles/fyles.go new file mode 100644 index 00000000..1de26acf --- /dev/null +++ b/modules/fyles/fyles.go @@ -0,0 +1,129 @@ +package fyles + +import ( + "image/color" + "log" + "os" + "path/filepath" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/canvas" + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/storage" + "fyne.io/fyne/v2/theme" + + lib "github.com/fyshos/fyles/pkg/fyles" + "golang.org/x/sys/execabs" + + "fyshos.com/fynedesk" + wmtheme "fyshos.com/fynedesk/theme" +) + +var fylesMeta = fynedesk.ModuleMetadata{ + Name: "Desktop Files", + NewInstance: newFyles, +} + +type fyles struct{} + +func (f *fyles) Destroy() { +} + +func (f *fyles) ScreenAreaWidget() fyne.CanvasObject { + icons := lib.NewFylesPanel(f.tapped, fynedesk.Instance().Root()) + icons.HideParent = true + icons.Filter = filterHidden() + f.setDesktopDir(icons) + + desk := fynedesk.Instance() + var barPad fyne.CanvasObject + if desk.Settings().NarrowLeftLauncher() { + r := canvas.NewRectangle(color.Transparent) + r.SetMinSize(fyne.NewSize(wmtheme.NarrowBarWidth, 1)) + barPad = r + } + + rightIndent := wmtheme.WidgetPanelWidth + if desk.Settings().NarrowWidgetPanel() { + rightIndent = wmtheme.NarrowBarWidth + } + widgetPad := canvas.NewRectangle(color.Transparent) + widgetPad.SetMinSize(fyne.NewSize(rightIndent, 1)) + + return container.NewBorder(nil, nil, barPad, widgetPad, container.NewPadded(icons)) +} + +func (f *fyles) Metadata() fynedesk.ModuleMetadata { + return fylesMeta +} + +func (f *fyles) setDesktopDir(p *lib.Panel) { + home, _ := os.UserHomeDir() + u := storage.NewFileURI(filepath.Join(home, "Desktop")) + settings := newCustomURI("settings://", "Settings", theme.SettingsIcon()) + trash := newCustomURI("file://"+filepath.Join(home, ".local", "share", "Trash", "files"), "Trash", theme.DeleteIcon()) + + list, err := storage.List(u) + list = append([]fyne.URI{settings, trash}, list...) + if err != nil { + fyne.LogError("Could not read Desktop dir", err) + } else { + p.SetListing(list) + } +} + +func (f *fyles) tapped(u fyne.URI) { + if u.Scheme() == "settings" { + fynedesk.Instance().ShowSettings() + return + } + p, err := execabs.LookPath("fyles") + if p != "" && err == nil { + if ok, _ := storage.CanList(u); ok { + err := execabs.Command(p, u.Path()).Start() + if err != nil { + log.Println("Error opening Fyles", err) + } + return + } + } else { + log.Println(">>> dir", u) + return + } + log.Println(">>> open", u) +} + +// newFyles creates a new module that will manage desktop file icons. +func newFyles() fynedesk.Module { + return &fyles{} +} + +type filter struct{} + +func (f *filter) Matches(u fyne.URI) bool { + return u.Name()[0] != '.' +} + +func filterHidden() storage.FileFilter { + return &filter{} +} + +type trashURI struct { + fyne.URI + + name string + icon fyne.Resource +} + +func newCustomURI(str, name string, icon fyne.Resource) fyne.URI { + u, _ := storage.ParseURI(str) + return &trashURI{URI: u, name: name, icon: icon} +} + +func (t *trashURI) Name() string { + return t.name +} + +func (t *trashURI) Icon() fyne.Resource { + return t.icon +} diff --git a/modules/fyles/init.go b/modules/fyles/init.go new file mode 100644 index 00000000..6a5a876a --- /dev/null +++ b/modules/fyles/init.go @@ -0,0 +1,7 @@ +package fyles + +import "fyshos.com/fynedesk" + +func init() { + fynedesk.RegisterModule(fylesMeta) +} diff --git a/test/desktop.go b/test/desktop.go index af53ac11..fba0eb5f 100644 --- a/test/desktop.go +++ b/test/desktop.go @@ -62,6 +62,9 @@ func (*Desktop) Desktop() int { func (*Desktop) SetDesktop(int) { } +// ShowSettings does nothing for the test package +func (*Desktop) ShowSettings() {} + // IconProvider returns the icon provider, by default it uses a simple in-memory implementation func (td *Desktop) IconProvider() fynedesk.ApplicationProvider { return td.icons