X backend conforms to new API

This commit is contained in:
2023-02-03 01:35:59 -05:00
parent bdf599f93c
commit d79701d01b
3 changed files with 56 additions and 0 deletions

View File

@@ -8,6 +8,8 @@ import "github.com/jezek/xgbutil/xevent"
import "github.com/jezek/xgbutil/xwindow"
import "github.com/jezek/xgbutil/xgraphics"
import "git.tebibyte.media/sashakoshka/tomo/input"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/elements"
@@ -20,6 +22,9 @@ type Window struct {
onClose func ()
skipChildDrawCallback bool
theme theme.Theme
config config.Config
metrics struct {
width int
height int
@@ -69,6 +74,9 @@ func (backend *Backend) NewWindow (
Connect(backend.connection, window.xWindow.Id)
xevent.MotionNotifyFun(window.handleMotionNotify).
Connect(backend.connection, window.xWindow.Id)
window.SetTheme(backend.theme)
window.SetConfig(backend.config)
window.metrics.width = width
window.metrics.height = height
@@ -100,6 +108,12 @@ func (window *Window) Adopt (child elements.Element) {
// adopt new child
window.child = child
if newChild, ok := child.(elements.Themeable); ok {
newChild.SetTheme(window.theme)
}
if newChild, ok := child.(elements.Configurable); ok {
newChild.SetConfig(window.config)
}
if newChild, ok := child.(elements.Flexible); ok {
newChild.OnFlexibleHeightChange(window.resizeChildToFit)
}
@@ -196,6 +210,20 @@ func (window *Window) OnClose (callback func ()) {
window.onClose = callback
}
func (window *Window) SetTheme (theme theme.Theme) {
window.theme = theme
if child, ok := window.child.(elements.Themeable); ok {
child.SetTheme(theme)
}
}
func (window *Window) SetConfig (config config.Config) {
window.config = config
if child, ok := window.child.(elements.Configurable); ok {
child.SetConfig(config)
}
}
func (window *Window) reallocateCanvas () {
window.canvas.Reallocate(window.metrics.width, window.metrics.height)

View File

@@ -2,6 +2,8 @@ package x
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/data"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "github.com/jezek/xgbutil"
import "github.com/jezek/xgb/xproto"
@@ -25,6 +27,9 @@ type Backend struct {
hyper uint16
}
theme theme.Theme
config config.Config
windows map[xproto.Window] *Window
}
@@ -95,6 +100,25 @@ func (backend *Backend) Paste (accept []data.Mime) (data data.Data) {
return
}
// SetTheme sets the theme of all open windows.
func (backend *Backend) SetTheme (theme theme.Theme) {
backend.assert()
backend.theme = theme
for _, window := range backend.windows {
window.SetTheme(theme)
}
}
// SetConfig sets the configuration of all open windows.
func (backend *Backend) SetConfig (config config.Config) {
backend.assert()
backend.config = config
for _, window := range backend.windows {
window.SetConfig(config)
}
}
func (backend *Backend) assert () {
if backend == nil { panic("nil backend") }
}