From bdf599f93cbf37ca6ec572458bdaa361ee0e5eda Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 3 Feb 2023 01:25:45 -0500 Subject: [PATCH] Backends must now accept Config and Theme --- backend.go | 8 ++++++++ elements/element.go | 3 ++- tomo.go | 28 ++++++++++++++++++++-------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/backend.go b/backend.go index 3b1ff31..a22e1ec 100644 --- a/backend.go +++ b/backend.go @@ -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 diff --git a/elements/element.go b/elements/element.go index 3743aa4..30022ee 100644 --- a/elements/element.go +++ b/elements/element.go @@ -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 diff --git a/tomo.go b/tomo.go index b1416b0..ac0a87e 100644 --- a/tomo.go +++ b/tomo.go @@ -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") } +}