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

Propose desktop integration #48

Draft
wants to merge 46 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1bf0ab2
Initial proposition for Gnome theme
metal3d May 13, 2022
396f841
Add font detection and conversion
metal3d May 15, 2022
2041d9d
Make a more complete theme manager for desktop
metal3d May 15, 2022
f977a91
Remove gnome.go, now in desktop package
metal3d May 15, 2022
8a9b79a
Fixes some colors and more optims
metal3d May 16, 2022
f35b297
Fix a lot of things...
metal3d May 17, 2022
8631afc
Reorder
metal3d May 17, 2022
f2a1cb7
Optimize gjs script
metal3d May 17, 2022
ccf227e
Doc, reorder, needed defers...
metal3d May 17, 2022
b6c3d5c
Detect theme changes with dbus
metal3d May 17, 2022
76850a9
fixed some color and add examples
metal3d May 17, 2022
4e4d801
Make color selection easier to tweak
metal3d May 17, 2022
a0004f4
React on settings also
metal3d May 18, 2022
6817a40
Improve image convertion
metal3d May 18, 2022
a60bfd7
The temp file were not removed in certain cases
metal3d May 18, 2022
af8c864
Cleanup
metal3d May 18, 2022
d3c2689
Add a demo for desktop integration
metal3d May 24, 2022
50967b5
Add invert mode
metal3d May 24, 2022
bd8aef8
Add more widgets to play
metal3d May 24, 2022
8f1ac47
Add a bit more doc
metal3d May 24, 2022
24c1991
Prefer alias for fyne-x
metal3d May 24, 2022
9dcbcdd
Get theme variant from Gnome 42 interface
metal3d Nov 6, 2022
8f098e9
Adaptation to use Gnome 42
metal3d Nov 6, 2022
bdfeb3b
Make some fixes for Adwaita and Gnome >= 42
metal3d Nov 7, 2022
3c32385
Fix Adwaita usage
metal3d Nov 10, 2022
6cba316
Make the scale factor to be applied for everything
metal3d Nov 15, 2022
de3d6d4
Add a message in the console for convertion tools
metal3d Nov 15, 2022
40626dc
USe 96x96 icon size to avoid aliasing
metal3d Nov 15, 2022
a11355c
Changed the inkscape command line to the newest
metal3d Nov 15, 2022
58ddbd9
Fix go.mod after rebasing
metal3d Nov 16, 2022
95c01c9
wrong varname it's not font scale, it's scale
metal3d Nov 16, 2022
a5cc1f4
Fix tests and doc...
metal3d Nov 18, 2022
a0ccede
io.WriteFile is not working on go 1.14
metal3d Nov 18, 2022
51a0d61
One more time, fix tests...
metal3d Nov 18, 2022
10a34c2
Fix nil pointer + rename theme import
metal3d Nov 18, 2022
135828a
Restrict compilation OS
metal3d Nov 18, 2022
e26af0a
Fixed imports
metal3d Nov 18, 2022
759b894
Restrict OS on Linux at this time
metal3d Nov 18, 2022
29373dc
Fix OS restriction
metal3d Nov 18, 2022
2696bf3
Fix unused and not initialized variables
metal3d Nov 18, 2022
94b21de
Simplify the integration, see details
metal3d Nov 22, 2022
1a1c34f
Cleanup, no need to get Gnome Version
metal3d Nov 22, 2022
aafaa76
Forgotten to remove the flags
metal3d Nov 22, 2022
84966ca
Add lxqt desktop environment
metal3d Nov 22, 2022
c842d67
Optimize string split
metal3d Nov 22, 2022
db2d88b
Remove unused versionNumber
metal3d Nov 22, 2022
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
100 changes: 100 additions & 0 deletions cmd/desktop_demo/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//go:build linux
// +build linux

package main

import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
xtheme "fyne.io/x/fyne/theme"
xdesktop "fyne.io/x/fyne/theme/desktop"
)

func main() {
app := app.New()
app.Settings().SetTheme(xtheme.FromDesktopEnvironment())
win := app.NewWindow("Desktop integration demo")
win.Resize(fyne.NewSize(550, 390))
win.CenterOnScreen()

// Gnome/GTK theme invertion
invertButton := widget.NewButton("Invert Gnome theme", func() {
if t, ok := app.Settings().Theme().(*xdesktop.GnomeTheme); ok {
t.Invert()
win.Content().Refresh()
}
})

// the invertButton can only work on Gnome / GTK theme.
if _, ok := app.Settings().Theme().(*xdesktop.GnomeTheme); !ok {
invertButton.Disable()
invertButton.SetText("Invert only works on Gnome/GTK")
}

var switched bool
switchThemeButton := widget.NewButton("Switch theme", func() {
if switched {
app.Settings().SetTheme(xtheme.FromDesktopEnvironment())
} else {
app.Settings().SetTheme(theme.DefaultTheme())
}
switched = !switched
win.Content().Refresh()
})

entry := widget.NewEntry()
entry.SetPlaceHolder("Example of text entry...")
win.SetContent(container.NewBorder(
nil,
container.NewHBox(
widget.NewButtonWithIcon("Home icon button", theme.HomeIcon(), nil),
widget.NewButtonWithIcon("Info icon button", theme.InfoIcon(), nil),
widget.NewButtonWithIcon("Example file dialog", theme.FolderIcon(), func() {
dialog.ShowFileSave(func(fyne.URIWriteCloser, error) {}, win)
}),
invertButton,
),
nil,
nil,
container.NewVBox(
createExplanationLabel(app),
entry,
widget.NewLabel("Try to switch theme"),
switchThemeButton,
),
))

win.ShowAndRun()
}

func createExplanationLabel(app fyne.App) fyne.CanvasObject {

var current string

switch app.Settings().Theme().(type) {
case *xdesktop.GnomeTheme:
current = "Gnome / GTK"
case *xdesktop.KDETheme:
current = "KDE / Plasma"
default:
current = "This window manager is not supported for now"
}

text := "Current Desktop: " + current + "\n"
text += `

This window should be styled to look like a desktop application. It works with GTK/Gnome based desktops and KDE/Plasma at this time
For the others desktops, the application will look like a normal window with default theme.

You may try to change icon theme or GTK/KDE theme in your desktop settings, as font, font scaling...

Note that you need to have fontforge package to make Fyne able to convert non-ttf fonts to ttf.
`
label := widget.NewLabel(text)
label.Wrapping = fyne.TextWrapWord
return label
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/eclipse/paho.mqtt.golang v1.3.5
github.com/gorilla/websocket v1.4.2
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564
github.com/stretchr/testify v1.7.2
github.com/wagslane/go-password-validator v0.3.0
golang.org/x/image v0.0.0-20220601225756-64ec528b34cd
Expand Down
25 changes: 25 additions & 0 deletions theme/desktop/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Package desktop provides theme for Linux (for now) desktop environment like Gnome, KDE, Plasma...
//
// To be fully used, the system need to have gsettings and gjs for all GTK/Gnome based desktop.
// KDE/Plasma theme only works when the user has already initialize a session to create ~/.config/kdeglobals
//
// The package will try to use fontconfig ("fc-match" and "fontconfig" commands).
// This is not required but recommended to be able to generate TTF font if the user as configure a non TTF font.
//
// The package also tries to use "inkscape" or "convert" command (from ImageMagick) to generate SVG icons when they
// cannot be parsed by Fyne (it happens when oksvg package fails to load icons).
//
// Some recent desktop environment now use Adwaita as default theme. If this theme is applied, the desktop package
// loads the default Fyne theme colors. It only try to change the scaling factor, font and icons of the applications.
//
// The easiest way to use this package is to call the FromDesktopEnvironment function from "theme" package.
//
// Example:
//
// app := app.New()
// theme := FromDesktopEnvironment()
// app.Settings().SetTheme(theme)
//
// This loads the theme from the current detected desktop environment. For Windows and MacOS, and mobile devices
// it will return the default Fyne theme.
package desktop
Loading