Added X backend stub

This commit is contained in:
Sasha Koshka 2022-11-09 15:52:49 -05:00
parent e7b5136ea6
commit 0c5118b59a
6 changed files with 111 additions and 34 deletions

View File

@ -20,9 +20,7 @@ func (application *Application) SetTitle (title string) {
// Run initializes the application, starts it, and then returns a channel that
// broadcasts events. If no suitable backend can be found, an error is returned.
func (application *Application) Run (
callback func (application *Application),
) (
func (application *Application) Run () (
channel chan(Event),
err error,
) {
@ -44,7 +42,9 @@ func (application *Application) Run (
application.backend, err = instantiateBackend(application)
if err != nil { return }
channel = application.backend.Run()
channel = make(chan(Event))
application.backend.Run(channel)
return
}

View File

@ -4,7 +4,7 @@ import "image"
import "errors"
type Backend interface {
Run () (channel chan(Event))
Run (channel chan(Event))
SetTitle (title string)
SetIcon (icons []image.Image)
}

34
backends/x/x.go Normal file
View File

@ -0,0 +1,34 @@
package x
import "image"
import "github.com/jezek/xgbutil"
// import "github.com/jezek/xgbutil/ewmh"
// import "github.com/jezek/xgbutil/xevent"
import "github.com/jezek/xgbutil/xwindow"
import "github.com/jezek/xgbutil/xgraphics"
import "git.tebibyte.media/sashakoshka/stone"
type Backend struct {
connection *xgbutil.Conn
window *xwindow.Window
canvas *xgraphics.Image
}
func (backend *Backend) Run (channel chan(stone.Event)) {
// TODO: setup
go backend.mainLoop(channel)
}
func (backend *Backend) mainLoop (channel chan(stone.Event)) {
}
func (backend *Backend) SetTitle (title string) {
}
func (backend *Backend) SetIcon (icons []image.Image) {
}

View File

@ -1,31 +1,25 @@
package main
import "os"
import "fmt"
import "time"
import "git.tebibyte.media/sashakoshka/stone"
// import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
func main () {
application := stone.Application { }
err := application.Run(run)
application := &stone.Application { }
channel, err := application.Run()
if err != nil { panic(err) }
}
func run (application *stone.Application) {
currentTime := time.Time { }
frameDelay := time.Second / 2
textBuffer := ""
for {
typed := application.Typed()
textBuffer += typed
event := <- channel
switch event.(type) {
case stone.EventQuit:
os.Exit(0)
shouldRender :=
application.Resized() ||
time.Since(currentTime) > frameDelay ||
len(typed) > 0
if shouldRender {
case stone.EventResize:
currentTime = time.Now()
application.ResetDot()
@ -43,18 +37,54 @@ func run (application *stone.Application) {
application.SetRune(5, 1, ':')
application.SetRune(6, 1, rune(second / 10 + 48))
application.SetRune(7, 1, rune(second % 10 + 48))
application.Dot.X = 0
application.Dot.Y = 2
fmt.Fprintln(application, textBuffer)
}
if application.Pressed(stone.MouseButtonLeft) {
x, y := application.MousePosition()
application.SetRune(x, y, '#')
}
if !application.Await(frameDelay) { break }
}
}
}
// func run (application *stone.Application) {
// currentTime := time.Time { }
// frameDelay := time.Second / 2
// textBuffer := ""
//
// for {
// typed := application.Typed()
// textBuffer += typed
//
// shouldRender :=
// application.Resized() ||
// time.Since(currentTime) > frameDelay ||
// len(typed) > 0
//
// if shouldRender {
// currentTime = time.Now()
//
// application.ResetDot()
// fmt.Fprintln(application, "hellorld!")
//
// hour := currentTime.Hour()
// minute := currentTime.Minute()
// second := currentTime.Second()
//
// application.SetRune(0, 1, rune(hour / 10 + 48))
// application.SetRune(1, 1, rune(hour % 10 + 48))
// application.SetRune(2, 1, ':')
// application.SetRune(3, 1, rune(minute / 10 + 48))
// application.SetRune(4, 1, rune(minute % 10 + 48))
// application.SetRune(5, 1, ':')
// application.SetRune(6, 1, rune(second / 10 + 48))
// application.SetRune(7, 1, rune(second % 10 + 48))
//
// application.Dot.X = 0
// application.Dot.Y = 2
// fmt.Fprintln(application, textBuffer)
//
// }
//
// if application.Pressed(stone.MouseButtonLeft) {
// x, y := application.MousePosition()
// application.SetRune(x, y, '#')
// }
//
// if !application.Await(frameDelay) { break }
// }
// }

4
go.mod
View File

@ -4,14 +4,18 @@ go 1.18
require (
github.com/faiface/pixel v0.10.0
github.com/jezek/xgbutil v0.0.0-20210302171758-530099784e66
golang.org/x/image v0.0.0-20190523035834-f03afa92d3ff
)
require (
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 // indirect
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect
github.com/faiface/glhf v0.0.0-20181018222622-82a6317ac380 // indirect
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 // indirect
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72 // indirect
github.com/go-gl/mathgl v0.0.0-20190416160123-c4601bc793c7 // indirect
github.com/jezek/xgb v1.1.0 // indirect
github.com/pkg/errors v0.8.1 // indirect
)

9
go.sum
View File

@ -1,3 +1,7 @@
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 h1:1qlsVAQJXZHsaM8b6OLVo6muQUQd4CwkH/D3fnnbHXA=
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g=
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966/go.mod h1:Mid70uvE93zn9wgF92A/r5ixgnvX8Lh68fxp9KQBaI0=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/faiface/glhf v0.0.0-20181018222622-82a6317ac380 h1:FvZ0mIGh6b3kOITxUnxS3tLZMh7yEoHo75v3/AgUqg0=
@ -12,7 +16,12 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72 h1:b+9H1GAsx5
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/mathgl v0.0.0-20190416160123-c4601bc793c7 h1:THttjeRn1iiz69E875U6gAik8KTWk/JYAHoSVpUxBBI=
github.com/go-gl/mathgl v0.0.0-20190416160123-c4601bc793c7/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk=
github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/jezek/xgbutil v0.0.0-20210302171758-530099784e66 h1:+wPhoJD8EH0/bXipIq8Lc2z477jfox9zkXPCJdhvHj8=
github.com/jezek/xgbutil v0.0.0-20210302171758-530099784e66/go.mod h1:KACeV+k6b+aoLTVrrurywEbu3UpqoQcQywj4qX8aQKM=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=