Documentation ¶
Overview ¶
Package wallutils can deal with monitors, resolution, dpi, wallpapers, wallpaper collections, timed wallpapers and converting GNOME timed wallpapers to the Simple Timed Wallpaper format.
Index ¶
- Constants
- Variables
- func Closest(filenames []string) (string, error)
- func ClosestByResolutionInFilename(filenames []string) (string, error)
- func CommonPrefix(sl []string) string
- func CommonSuffix(sl []string) string
- func Distance(a, b *Res) int
- func FindImagesAt(searchPath string, _ []string, onlyLarge bool) ([]string, error)
- func Info() (string, error)
- func Meat(s, prefix, suffix string) string
- func MonConfOverlap(filename string) bool
- func NewRect(x, y, w, h uint) image.Rectangle
- func NoXRandrOverlapOrExit(verbose bool)
- func Overlaps(rects []image.Rectangle) bool
- func ParseSize(widthHeight string) (uint, uint, error)
- func Quit(err error)
- func SetWallpaper(imageFilename string) error
- func SetWallpaperCustom(imageFilename, mode string, verbose bool) error
- func SetWallpaperVerbose(imageFilename string, verbose bool) error
- func WaylandCanConnect() bool
- func WaylandInfo() (string, error)
- func WaylandMonitors(IDs, widths, heights, wDPIs, hDPIs *[]uint) error
- func XCanConnect() bool
- func XInfo() (string, error)
- func XMonitors(IDs, widths, heights, wDPIs, hDPIs *[]uint) error
- type Cinnamon
- type Deepin
- type Feh
- type GPU
- type GSettings
- type Gnome2
- type Gnome3
- type MConfiguration
- type MOutput
- type Mate
- type Monitor
- type MonitorConfiguration
- type Pekwm
- type Plasma
- type Res
- type SearchResults
- func (sr *SearchResults) CollectionNames() []string
- func (sr *SearchResults) Empty() bool
- func (sr *SearchResults) GnomeTimedWallpapers() []*gnometimed.Wallpaper
- func (sr *SearchResults) GnomeTimedWallpapersByName(name string) []*gnometimed.Wallpaper
- func (sr *SearchResults) NoTimedWallpapers() bool
- func (sr *SearchResults) SimpleTimedWallpapers() []*simpletimed.Wallpaper
- func (sr *SearchResults) SimpleTimedWallpapersByName(name string) []*simpletimed.Wallpaper
- func (sr *SearchResults) Wallpapers() []*Wallpaper
- func (sr *SearchResults) WallpapersByName(name string) []*Wallpaper
- type Sway
- type SwayBG
- type WM
- type Wallpaper
- type Weston
- type XRandr
- type Xfce4
Examples ¶
Constants ¶
const VersionString = "5.12.7"
VersionString is the current version of wallutils and all included utilities
Variables ¶
var DefaultWallpaperDirectories = []string{
"/usr/share/pixmaps",
"/usr/share/wallpapers",
"/usr/share/backgrounds",
"/usr/local/share/pixmaps",
"/usr/local/share/wallpapers",
"/usr/local/share/backgrounds",
"/usr/share/archlinux",
}
DefaultWallpaperDirectories lists the default locations to look for wallpapers
var WMs = []WM{ &Sway{}, &Deepin{}, &Xfce4{}, &Mate{}, &Cinnamon{}, &Plasma{}, &Gnome3{}, &Gnome2{}, &Pekwm{}, &SwayBG{}, &Weston{}, &Feh{}, }
WMs contains all available backends for changing the wallpaper Some backends may require cgo (sway + x11)
Functions ¶
func Closest ¶
Closest does the same as ClosestByResolutionInfilename. It is provided for backwards compatibility.
func ClosestByResolutionInFilename ¶
ClosestByResolutionInFilename takes a list of filenames on the form "*_WIDTHxHEIGHT.ext", where WIDTH and HEIGHT are numbers. The filename that is closest to the average monitor resolution is returned. Any filenames not following the pattern will cause an error being returned.
func CommonPrefix ¶
CommonPrefix will find the longest common prefix in a slice of strings
func CommonSuffix ¶
CommonSuffix will find the longest common suffix in a slice of strings
func FindImagesAt ¶
FindImagesAt will find images at the given search path. Set onlyLarge to true if the images should be large enough for the desktop.
func Info ¶
Info returns a long info string that looks different for Wayland and for X. The string contains all available information about the connected monitors.
func Meat ¶
Meat returns the meat of the string: the part that is after the prefix and before the suffix. It does not check if the prefix and suffix exists in the string. If the given string is too short to contain the prefix and suffix, it will be returned as it is.
func MonConfOverlap ¶
MonConfOverlap is a convenience function for checking if the x,y,w,h monitor configurations in ie. ~/.config/monitors.xml are overlapping or not. If monitors.xml can not be parsed or read, false is returned.
func NewRect ¶
NewRect is a convenience function for creating an image.Rectangle, given the upper left corner (x and y), a width and a height.
func NoXRandrOverlapOrExit ¶
func NoXRandrOverlapOrExit(verbose bool)
NoXRandrOverlapOrExit is a convenience function for making sure monitor configurations are not overlapping, as reported by "xrandr".
func SetWallpaper ¶
SetWallpaper will set the desktop wallpaper, for any supported windowmanager. The fallback is to use `feh`. The wallpaper mode is "fill".
func SetWallpaperCustom ¶
SetWallpaperCustom will set the given image filename as the wallpaper, regardless of which display server, window manager or desktop environment is in use.
func SetWallpaperVerbose ¶
SetWallpaperVerbose will set the desktop wallpaper, for any supported windowmanager. The fallback is to use `feh`. The wallpaper mode is "fill".
func WaylandCanConnect ¶
func WaylandCanConnect() bool
WaylandCanConnect checks if a Wayland server is up and running
func WaylandInfo ¶
WaylandInfo returns a long info string about the current Wayland setup
func WaylandMonitors ¶
WaylandMonitors returns information about the available monitors. The given slices are filled with data about resolution and DPI.
Types ¶
type Cinnamon ¶
type Cinnamon struct {
// contains filtered or unexported fields
}
Cinnamon windowmanager detector
func (*Cinnamon) ExecutablesExists ¶
ExecutablesExists checks if executables associated with this backend exists in the PATH
func (*Cinnamon) Running ¶
Running examines environment variables to try to figure out if this backend is currently running
func (*Cinnamon) SetMode ¶
SetMode will set the current way to display the wallpaper (stretched, tiled etc)
func (*Cinnamon) SetVerbose ¶
SetVerbose can be used for setting the verbose field to true or false. This will cause this backend to output information about what is is doing on stdout.
func (*Cinnamon) SetWallpaper ¶
SetWallpaper sets the desktop wallpaper, given an image filename. The image must exist and be readable.
type Deepin ¶
type Deepin struct {
// contains filtered or unexported fields
}
Deepin windowmanager detector
func (*Deepin) ExecutablesExists ¶
ExecutablesExists checks if executables associated with this backend exists in the PATH
func (*Deepin) Running ¶
Running examines environment variables to try to figure out if this backend is currently running
func (*Deepin) SetMode ¶
SetMode will set the current way to display the wallpaper (stretched, tiled etc)
func (*Deepin) SetVerbose ¶
SetVerbose can be used for setting the verbose field to true or false. This will cause this backend to output information about what is is doing on stdout.
func (*Deepin) SetWallpaper ¶
SetWallpaper sets the desktop wallpaper, given an image filename. The image must exist and be readable.
type Feh ¶
type Feh struct {
// contains filtered or unexported fields
}
Feh is a structure containing settings for running the "feh" executable
func (*Feh) ExecutablesExists ¶
ExecutablesExists checks if the feh executable exists in the PATH
func (*Feh) Running ¶
Running just returns true for the Feh backend, since this is an application and not a WM / DM
func (*Feh) SetMode ¶
SetMode will set the current way to display the wallpaper (stretched, tiled etc). The selected mode must be compatible with feh.
func (*Feh) SetVerbose ¶
SetVerbose can be used for setting the verbose field to true or false. This will cause this backend to output information about what is is doing on stdout.
func (*Feh) SetWallpaper ¶
SetWallpaper sets the desktop wallpaper, given an image filename. The image must exist and be readable. `feh` is used for setting the desktop background, and must be in the PATH.
type GPU ¶
type GPU struct { ID uint // GPU number, from 0 and up Name string // GPU name VRAM uint // VRAM, in MiB VGA bool // Integrated / shows up as "VGA" with lspci Bus string // ie. 01:00.0 }
GPU contains an ID and the VRAM in MiB
func GPUs ¶
GPUs returns information about all available GPUs. This function will run "nvidia-smi" or any needed utility in order to collect the information. If alsoIntegrated is set to true, also integrated graphic cards will be detected (listed as "VGA" in the lspci output, or contains the string "UHD")
type GSettings ¶
type GSettings struct {
// contains filtered or unexported fields
}
GSettings can be used for getting and setting configuration options with gsettings
func NewGSettings ¶
NewGSettings creates a new GSettings struct given a schema/category and a bool for if the commands should be printed to stdout before running.
type Gnome2 ¶
type Gnome2 struct {
// contains filtered or unexported fields
}
Gnome2 windowmanager detector
func (*Gnome2) ExecutablesExists ¶
ExecutablesExists checks if executables associated with this backend exists in the PATH
func (*Gnome2) Running ¶
Running examines environment variables to try to figure out if this backend is currently running
func (*Gnome2) SetMode ¶
SetMode will set the current way to display the wallpaper (stretched, tiled etc)
func (*Gnome2) SetVerbose ¶
SetVerbose can be used for setting the verbose field to true or false. This will cause this backend to output information about what is is doing on stdout.
func (*Gnome2) SetWallpaper ¶
SetWallpaper sets the desktop wallpaper, given an image filename. The image must exist and be readable.
type Gnome3 ¶
type Gnome3 struct {
// contains filtered or unexported fields
}
Gnome3 windowmanager detector
func (*Gnome3) ExecutablesExists ¶
ExecutablesExists checks if executables associated with this backend exists in the PATH
func (*Gnome3) Running ¶
Running examines environment variables to try to figure out if this backend is currently running
func (*Gnome3) SetMode ¶
SetMode will set the current way to display the wallpaper (stretched, tiled etc)
func (*Gnome3) SetVerbose ¶
SetVerbose can be used for setting the verbose field to true or false. This will cause this backend to output information about what is is doing on stdout.
func (*Gnome3) SetWallpaper ¶
SetWallpaper sets the desktop wallpaper, given an image filename. The image must exist and be readable.
type MConfiguration ¶
type MConfiguration struct { XMLName xml.Name `xml:"configuration"` Clone string `xml:"clone,omitempty"` Outputs []MOutput `xml:"output"` }
MConfiguration is mainly a collection of MOutput + a Clone field
type MOutput ¶
type MOutput struct { XMLName xml.Name `xml:"output"` Name string `xml:"name,attr"` Vendor string `xml:"vendor,omitempty"` Product string `xml:"product,omitempty"` Serial string `xml:"serial,omitempty"` Width string `xml:"width,omitempty"` Height string `xml:"height,omitempty"` Rate string `xml:"rate,omitempty"` X string `xml:"x,omitempty"` Y string `xml:"y,omitempty"` Rotation string `xml:"rotation,omitempty"` ReflectX string `xml:"reflect_x,omitempty"` ReflectY string `xml:"reflect_y,omitempty"` Primary string `xml:"primary,omitempty"` }
MOutput represents a monitor configuration, including: width, height, rotation and if the monitor is the primary monitor.
type Mate ¶
type Mate struct {
// contains filtered or unexported fields
}
Mate windowmanager detector
func (*Mate) ExecutablesExists ¶
ExecutablesExists checks if executables associated with this backend exists in the PATH
func (*Mate) Running ¶
Running examines environment variables to try to figure out if this backend is currently running
func (*Mate) SetMode ¶
SetMode will set the current way to display the wallpaper (stretched, tiled etc)
func (*Mate) SetVerbose ¶
SetVerbose can be used for setting the verbose field to true or false. This will cause this backend to output information about what is is doing on stdout.
func (*Mate) SetWallpaper ¶
SetWallpaper sets the desktop wallpaper, given an image filename. The image must exist and be readable.
type Monitor ¶
type Monitor struct { ID uint // monitor number, from 0 and up Width uint // width, in pixels Height uint // height, in pixels DPIw uint // DPI, if available (width) DPIh uint // DPI, if available (height) }
Monitor contains an ID, the width in pixels and the height in pixels
type MonitorConfiguration ¶
type MonitorConfiguration struct { XMLName xml.Name `xml:"monitors"` Version string `xml:"version,attr"` Configurations []MConfiguration `xml:"configuration"` }
MonitorConfiguration is mainly a collection of MConfiguration + a Version field
func NewMonitorConfiguration ¶
func NewMonitorConfiguration() (*MonitorConfiguration, error)
NewMonitorConfiguration returns a new MonitorConfiguration struct, filled with the contents of ~/.config/monitors.xml.
func ParseMonitorFile ¶
func ParseMonitorFile(filename string) (*MonitorConfiguration, error)
ParseMonitorFile can parse monitor XML files, like the one that typically exists in ~/.config/monitors.xml
func (*MonitorConfiguration) Overlapping ¶
func (mc *MonitorConfiguration) Overlapping() bool
Overlapping can check if configurations in monitors.xml have overlapping areas.
type Pekwm ¶
type Pekwm struct {
// contains filtered or unexported fields
}
Pekwm is a structure containing settings for running the "pekwm_bg" executable
func (*Pekwm) ExecutablesExists ¶
ExecutablesExists checks if the "pekwm_bg" executable exists in the PATH (comes with pekwm 0.2.0 or later)
func (*Pekwm) SetMode ¶
SetMode will set the current way to display the wallpaper (stretched, tiled etc). The selected mode must be compatible with pekwm_bg.
func (*Pekwm) SetVerbose ¶
SetVerbose can be used for setting the verbose field to true or false. This will cause this backend to output information about what is is doing on stdout.
func (*Pekwm) SetWallpaper ¶
SetWallpaper sets the desktop wallpaper, given an image filename. The image must exist and be readable.
type Plasma ¶
type Plasma struct {
// contains filtered or unexported fields
}
Plasma windowmanager detector
func (*Plasma) ExecutablesExists ¶
ExecutablesExists checks if executables associated with this backend exists in the PATH
func (*Plasma) Running ¶
Running examines environment variables to try to figure out if this backend is currently running
func (*Plasma) SetMode ¶
SetMode will set the current way to display the wallpaper (stretched, tiled etc)
func (*Plasma) SetVerbose ¶
SetVerbose can be used for setting the verbose field to true or false. This will cause this backend to output information about what is is doing on stdout.
func (*Plasma) SetWallpaper ¶
SetWallpaper sets the desktop wallpaper, given an image filename. The image must exist and be readable.
type Res ¶
type Res struct {
// contains filtered or unexported fields
}
Res is a structure containing width and height
func AverageResolution ¶
AverageResolution returns the average resolution for all connected monitors.
func ExtractResolutions ¶
ExtractResolutions extracts Res structs from a slice of filenames All the filenames must be on the form *_WIDTHxHEIGHT.ext, where WIDTH and HEIGHT are numbers.
func FilenameToRes ¶
FilenameToRes extracts width and height from a filename on the form: "asdf_123x123.xyz", or filenames that are just on the form "123x123.xyz".
Example ¶
fn := "hello_there_320x200.png" res, err := FilenameToRes(fn) if err != nil { panic(err) } fmt.Println(res)
Output: 320x200
type SearchResults ¶
type SearchResults struct {
// contains filtered or unexported fields
}
SearchResults is a struct containing all found wallpaper collections, of these types: * wallpaper images (several in one directory, of different sizes) * gnome wallpapers (contains a GNOME-compatible XML file) * sime timed wallpapers (contains a .stw file)
func FindWallpapers ¶
func FindWallpapers() (*SearchResults, error)
FindWallpapers will search for wallpaper collections, simple timed wallpapers and GNOME timed wallpapers in all default wallpaper directories on the system.
func FindWallpapersAt ¶
func FindWallpapersAt(path string) (*SearchResults, error)
FindWallpapersAt will search for wallpaper collections, simple timed wallpapers and GNOME timed wallpapers in the given path.
func NewSearchResults ¶
func NewSearchResults() *SearchResults
NewSearchResults will reset the search and prepare to search again
func (*SearchResults) CollectionNames ¶
func (sr *SearchResults) CollectionNames() []string
CollectionNames gathers all the names of all available wallpaper packs or GNOME timed backgrounds
func (*SearchResults) Empty ¶
func (sr *SearchResults) Empty() bool
Empty checks if these search results are empty
func (*SearchResults) GnomeTimedWallpapers ¶
func (sr *SearchResults) GnomeTimedWallpapers() []*gnometimed.Wallpaper
GnomeTimedWallpapers returns a sorted slice of all found gnome timed wallpapers
func (*SearchResults) GnomeTimedWallpapersByName ¶
func (sr *SearchResults) GnomeTimedWallpapersByName(name string) []*gnometimed.Wallpaper
GnomeTimedWallpapersByName will return gnome timed wallpapers that match with the collection name
func (*SearchResults) NoTimedWallpapers ¶
func (sr *SearchResults) NoTimedWallpapers() bool
NoTimedWallpapers checks if the current search results contains no timed wallpapers
func (*SearchResults) SimpleTimedWallpapers ¶
func (sr *SearchResults) SimpleTimedWallpapers() []*simpletimed.Wallpaper
SimpleTimedWallpapers returns a sorted slice of all found simple timed wallpapers
func (*SearchResults) SimpleTimedWallpapersByName ¶
func (sr *SearchResults) SimpleTimedWallpapersByName(name string) []*simpletimed.Wallpaper
SimpleTimedWallpapersByName will return simple timed wallpapers that match with the collection name
func (*SearchResults) Wallpapers ¶
func (sr *SearchResults) Wallpapers() []*Wallpaper
Wallpapers returns a sorted slice of all found wallpapers
func (*SearchResults) WallpapersByName ¶
func (sr *SearchResults) WallpapersByName(name string) []*Wallpaper
WallpapersByName will return simple timed wallpapers that match with the collection name
type Sway ¶
type Sway struct {
// contains filtered or unexported fields
}
Sway windowmanager detector
func (*Sway) ExecutablesExists ¶
ExecutablesExists checks if executables associated with this backend exists in the PATH
func (*Sway) Running ¶
Running examines environment variables to try to figure out if this backend is currently running
func (*Sway) SetMode ¶
SetMode will set the current way to display the wallpaper (stretched, tiled etc)
func (*Sway) SetVerbose ¶
SetVerbose can be used for setting the verbose field to true or false. This will cause this backend to output information about what is is doing on stdout.
func (*Sway) SetWallpaper ¶
SetWallpaper sets the desktop wallpaper, given an image filename. The image must exist and be readable.
type SwayBG ¶
type SwayBG struct {
// contains filtered or unexported fields
}
SwayBG compatible windowmanager
func (*SwayBG) ExecutablesExists ¶
ExecutablesExists checks if executables associated with this backend exists in the PATH
func (*SwayBG) Running ¶
Running examines environment variables to try to figure out if this backend is currently running
func (*SwayBG) SetMode ¶
SetMode will set the current way to display the wallpaper (stretched, tiled etc)
func (*SwayBG) SetVerbose ¶
SetVerbose can be used for setting the verbose field to true or false. This will cause this backend to output information about what is is doing on stdout.
func (*SwayBG) SetWallpaper ¶
SetWallpaper sets the desktop wallpaper, given an image filename. The image must exist and be readable.
type WM ¶
type WM interface { Name() string ExecutablesExists() bool Running() bool SetWallpaper(string) error SetVerbose(bool) SetMode(string) }
WM is an interface with the functions that needs to be implemented for adding support for setting the wallpaper for a new WM or DE
type Wallpaper ¶
type Wallpaper struct { CollectionName string // the name of the directory containing this wallpaper, if it's not "pixmaps", "images" or "contents". May use the parent of the parent. Path string // full path to the image filename Width uint // width of the image Height uint // height of the image PartOfCollection bool // likely to be part of a wallpaper collection }
Wallpaper represents an image file that is part of a wallpaper collection (in a directory with several resolutions of the same image, for example)
func ClosestByResolution ¶
ClosestByResolution returns a wallpaper that is closest to the average monitor resolution. If several wallpapers matches, a random one is returned. The idea is that a slice of wallpapers in a wallpaper collection with several available resolutions is given as input, and a suitable wallpaper is returned.
type Weston ¶
type Weston struct {
// contains filtered or unexported fields
}
Weston windowmanager detector
func (*Weston) ExecutablesExists ¶
ExecutablesExists checks if executables associated with this backend exists in the PATH
func (*Weston) Running ¶
Running examines environment variables to try to figure out if this backend is currently running
func (*Weston) SetMode ¶
SetMode will set the current way to display the wallpaper (stretched, tiled etc)
func (*Weston) SetVerbose ¶
SetVerbose can be used for setting the verbose field to true or false. This will cause this backend to output information about what is is doing on stdout.
func (*Weston) SetWallpaper ¶
SetWallpaper sets the desktop wallpaper, given an image filename. The image must exist and be readable.
type XRandr ¶
type XRandr struct {
// contains filtered or unexported fields
}
XRandr can contain information that has been extracted by running the xrandr executable
func NewXRandr ¶
NewXRandr creates a new XRandr struct and fills it with information by running "xrandr". An error is returned if xrandr could not be found.
func (*XRandr) CheckOverlap ¶
func (x *XRandr) CheckOverlap()
CheckOverlap checks if the displays listed by "xrandr" overlaps, or not A slice of relevant lines from the xrandr output is stored in the struct.
func (*XRandr) QuitIfOverlap ¶
func (x *XRandr) QuitIfOverlap()
QuitIfOverlap will quit with an error if monitor configurations overlap
type Xfce4 ¶
type Xfce4 struct {
// contains filtered or unexported fields
}
Xfce4 windowmanager detector
func (*Xfce4) ExecutablesExists ¶
ExecutablesExists checks if executables associated with this backend exists in the PATH
func (*Xfce4) Running ¶
Running examines environment variables to try to figure out if this backend is currently running
func (*Xfce4) SetMode ¶
SetMode will set the current way to display the wallpaper (stretched, tiled etc)
func (*Xfce4) SetVerbose ¶
SetVerbose can be used for setting the verbose field to true or false. This will cause this backend to output information about what is is doing on stdout.
func (*Xfce4) SetWallpaper ¶
SetWallpaper sets the desktop wallpaper, given an image filename. The image must exist and be readable.