Added X backend stub
This commit is contained in:
parent
e7b5136ea6
commit
0c5118b59a
@ -20,9 +20,7 @@ func (application *Application) SetTitle (title string) {
|
|||||||
|
|
||||||
// Run initializes the application, starts it, and then returns a channel that
|
// 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.
|
// broadcasts events. If no suitable backend can be found, an error is returned.
|
||||||
func (application *Application) Run (
|
func (application *Application) Run () (
|
||||||
callback func (application *Application),
|
|
||||||
) (
|
|
||||||
channel chan(Event),
|
channel chan(Event),
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
@ -44,7 +42,9 @@ func (application *Application) Run (
|
|||||||
|
|
||||||
application.backend, err = instantiateBackend(application)
|
application.backend, err = instantiateBackend(application)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
channel = application.backend.Run()
|
|
||||||
|
channel = make(chan(Event))
|
||||||
|
application.backend.Run(channel)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import "image"
|
|||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
type Backend interface {
|
type Backend interface {
|
||||||
Run () (channel chan(Event))
|
Run (channel chan(Event))
|
||||||
SetTitle (title string)
|
SetTitle (title string)
|
||||||
SetIcon (icons []image.Image)
|
SetIcon (icons []image.Image)
|
||||||
}
|
}
|
||||||
|
34
backends/x/x.go
Normal file
34
backends/x/x.go
Normal 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) {
|
||||||
|
|
||||||
|
}
|
@ -1,31 +1,25 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "os"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "time"
|
import "time"
|
||||||
import "git.tebibyte.media/sashakoshka/stone"
|
import "git.tebibyte.media/sashakoshka/stone"
|
||||||
// import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
|
// import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
|
||||||
|
|
||||||
func main () {
|
func main () {
|
||||||
application := stone.Application { }
|
application := &stone.Application { }
|
||||||
err := application.Run(run)
|
channel, err := application.Run()
|
||||||
if err != nil { panic(err) }
|
if err != nil { panic(err) }
|
||||||
}
|
|
||||||
|
|
||||||
func run (application *stone.Application) {
|
|
||||||
currentTime := time.Time { }
|
currentTime := time.Time { }
|
||||||
frameDelay := time.Second / 2
|
|
||||||
textBuffer := ""
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
typed := application.Typed()
|
event := <- channel
|
||||||
textBuffer += typed
|
switch event.(type) {
|
||||||
|
case stone.EventQuit:
|
||||||
|
os.Exit(0)
|
||||||
|
|
||||||
shouldRender :=
|
case stone.EventResize:
|
||||||
application.Resized() ||
|
|
||||||
time.Since(currentTime) > frameDelay ||
|
|
||||||
len(typed) > 0
|
|
||||||
|
|
||||||
if shouldRender {
|
|
||||||
currentTime = time.Now()
|
currentTime = time.Now()
|
||||||
|
|
||||||
application.ResetDot()
|
application.ResetDot()
|
||||||
@ -43,18 +37,54 @@ func run (application *stone.Application) {
|
|||||||
application.SetRune(5, 1, ':')
|
application.SetRune(5, 1, ':')
|
||||||
application.SetRune(6, 1, rune(second / 10 + 48))
|
application.SetRune(6, 1, rune(second / 10 + 48))
|
||||||
application.SetRune(7, 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
4
go.mod
@ -4,14 +4,18 @@ go 1.18
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/faiface/pixel v0.10.0
|
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
|
golang.org/x/image v0.0.0-20190523035834-f03afa92d3ff
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
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/glhf v0.0.0-20181018222622-82a6317ac380 // indirect
|
||||||
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 // 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/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/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72 // indirect
|
||||||
github.com/go-gl/mathgl v0.0.0-20190416160123-c4601bc793c7 // 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
|
github.com/pkg/errors v0.8.1 // indirect
|
||||||
)
|
)
|
||||||
|
9
go.sum
9
go.sum
@ -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 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
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=
|
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/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 h1:THttjeRn1iiz69E875U6gAik8KTWk/JYAHoSVpUxBBI=
|
||||||
github.com/go-gl/mathgl v0.0.0-20190416160123-c4601bc793c7/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
|
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/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 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
Loading…
Reference in New Issue
Block a user