Backends must now accept Config and Theme

This commit is contained in:
Sasha Koshka 2023-02-03 01:25:45 -05:00
parent 8ccaa0faba
commit bdf599f93c
3 changed files with 30 additions and 9 deletions

View File

@ -2,6 +2,8 @@ package tomo
import "errors"
import "git.tebibyte.media/sashakoshka/tomo/data"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/elements"
// Backend represents a connection to a display server, or something similar.
@ -28,6 +30,12 @@ type Backend interface {
// Paste returns the data currently in the clipboard.
Paste (accept []data.Mime) (data.Data)
// SetTheme sets the theme of all open windows.
SetTheme (theme.Theme)
// SetConfig sets the configuration of all open windows.
SetConfig (config.Config)
}
// BackendFactory represents a function capable of constructing a backend

View File

@ -39,7 +39,8 @@ type Element interface {
type Focusable interface {
Element
// Focused returns whether or not this element is currently focused.
// Focused returns whether or not this element or any of its children
// are currently focused.
Focused () (selected bool)
// Focus focuses this element, if its parent element grants the

28
tomo.go
View File

@ -1,7 +1,8 @@
package tomo
import "errors"
import "git.tebibyte.media/sashakoshka/tomo/data"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/elements"
var backend Backend
@ -26,7 +27,7 @@ func Stop () {
// Do executes the specified callback within the main thread as soon as
// possible. This function can be safely called from other threads.
func Do (callback func ()) {
if backend == nil { panic("no backend is running") }
assertBackend()
backend.Do(callback)
}
@ -35,22 +36,33 @@ func Do (callback func ()) {
// why. If this function is called without a running backend, an error is
// returned as well.
func NewWindow (width, height int) (window elements.Window, err error) {
if backend == nil {
err = errors.New("no backend is running.")
return
}
assertBackend()
return backend.NewWindow(width, height)
}
// Copy puts data into the clipboard.
func Copy (data data.Data) {
if backend == nil { panic("no backend is running") }
assertBackend()
backend.Copy(data)
}
// Paste returns the data currently in the clipboard. This method may
// return nil.
func Paste (accept []data.Mime) (data.Data) {
if backend == nil { panic("no backend is running") }
assertBackend()
return backend.Paste(accept)
}
// SetTheme sets the theme of all open windows.
func SetTheme (theme theme.Theme) {
backend.SetTheme(theme)
}
// SetConfig sets the configuration of all open windows.
func SetConfig (config config.Config) {
backend.SetConfig(config)
}
func assertBackend () {
if backend == nil { panic("no backend is running") }
}