simpletimed

package
v0.0.0-...-389cf96 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

README

Simpletimed

simpletimed can be used for parsing the STW file format and for running an event loop for setting the wallpaper, given a function with this signature:

func(string) error

Where the given string is the image filename to be set.

The Simple Timed Wallpaper Format

STW is a format for a configuration file that specifies in which time ranges wallpapers should change from one to another, and with which transition.

It's a similar to the GNOME timed wallpaper XML format, but much simpler and less verbose.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultLoopTime = 30 * time.Second

Functions

This section is empty.

Types

type Static

type Static struct {
	At       time.Time
	Filename string
}

func (*Static) String

func (s *Static) String(format string) string

type Transition

type Transition struct {
	From         time.Time
	UpTo         time.Time
	FromFilename string
	ToFilename   string
	Type         string
}

func (*Transition) Duration

func (t *Transition) Duration() time.Duration

func (*Transition) String

func (t *Transition) String(format string) string

type Wallpaper

type Wallpaper struct {
	STWVersion  string
	Name        string
	Format      string
	Path        string // not part of the file data, but handy when parsing
	Statics     []*Static
	Transitions []*Transition
	LoopWait    time.Duration // how long the main event loop should sleep
}

func DataToSimple

func DataToSimple(path string, data []byte) (*Wallpaper, error)

DataToSimple converts from the contents of a Simple Timed Wallpaper file to a Wallpaper structs. The given path is used in the error messages and for setting stw.Path.

func NewWallpaper

func NewWallpaper(version, name, format string) *Wallpaper

func ParseSTW

func ParseSTW(filename string) (*Wallpaper, error)
Example
stw, err := ParseSTW("testdata/adwaita-timed2.stw")
if err != nil {
	panic(err)
}
fmt.Println(stw.Name)

stw, err = ParseSTW("testdata/comments.stw")
if err != nil {
	panic(err)
}
fmt.Println(stw.Name)
Output:

adwaita-timed
comments

func (*Wallpaper) AddStatic

func (stw *Wallpaper) AddStatic(at time.Time, filename string)

func (*Wallpaper) AddTransition

func (stw *Wallpaper) AddTransition(from, upto time.Time, fromFilename, toFilename, transitionType string)

func (*Wallpaper) EventLoop

func (stw *Wallpaper) EventLoop(verbose bool, setWallpaperFunc func(string) error, tempImageFilename string) error

EventLoop will start the event loop for this Simple Timed Wallpaper

func (*Wallpaper) NextEvent

func (stw *Wallpaper) NextEvent(et time.Time) (interface{}, time.Time, error)

NextEvent finds the next event, given a timestamp. Returns an interface{} that is either a static or transition event.

func (*Wallpaper) PrevEvent

func (stw *Wallpaper) PrevEvent(et time.Time) (interface{}, time.Time, error)

PrevEvent finds the previous event, given a timestamp. Returns an interface{} that is either a static or transition event.

func (*Wallpaper) SetInitialWallpaper

func (stw *Wallpaper) SetInitialWallpaper(verbose bool, setWallpaperFunc func(string) error, tempImageFilename string) error

SetInitialWallpaper will set the first wallpaper, before starting the event loop

func (*Wallpaper) String

func (stw *Wallpaper) String() string

String outputs a valid STW file, where the timestamps are in a sorted order

func (*Wallpaper) UntilNext

func (stw *Wallpaper) UntilNext(et time.Time) (time.Duration, time.Time)

UntilNext finds the duration until the next event starts

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL