restructure-config #8

Merged
sashakoshka merged 15 commits from restructure-config into main 2023-02-08 19:07:08 -07:00
3 changed files with 30 additions and 9 deletions
Showing only changes of commit bdf599f93c - Show all commits

View File

@ -2,6 +2,8 @@ package tomo
import "errors" import "errors"
import "git.tebibyte.media/sashakoshka/tomo/data" 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" import "git.tebibyte.media/sashakoshka/tomo/elements"
// Backend represents a connection to a display server, or something similar. // 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 returns the data currently in the clipboard.
Paste (accept []data.Mime) (data.Data) 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 // BackendFactory represents a function capable of constructing a backend

View File

@ -39,7 +39,8 @@ type Element interface {
type Focusable interface { type Focusable interface {
Element 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) Focused () (selected bool)
// Focus focuses this element, if its parent element grants the // Focus focuses this element, if its parent element grants the

28
tomo.go
View File

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