Added icon setting
This commit is contained in:
@@ -7,7 +7,7 @@ import "image"
|
||||
import "github.com/jezek/xgb"
|
||||
import "github.com/jezek/xgbutil"
|
||||
import "github.com/jezek/xgb/xproto"
|
||||
// import "github.com/jezek/xgbutil/ewmh"
|
||||
import "github.com/jezek/xgbutil/ewmh"
|
||||
import "github.com/jezek/xgbutil/xevent"
|
||||
import "github.com/jezek/xgbutil/xwindow"
|
||||
import "github.com/jezek/xgbutil/xgraphics"
|
||||
@@ -68,12 +68,46 @@ func (backend *Backend) Run (channel chan(stone.Event)) {
|
||||
}
|
||||
}
|
||||
|
||||
func (backend *Backend) SetTitle (title string) {
|
||||
|
||||
func (backend *Backend) SetTitle (title string) (err error) {
|
||||
err = ewmh.WmNameSet(backend.connection, backend.window.Id, title)
|
||||
return
|
||||
}
|
||||
|
||||
func (backend *Backend) SetIcon (icons []image.Image) {
|
||||
func (backend *Backend) SetIcon (icons []image.Image) (err error) {
|
||||
wmIcons := []ewmh.WmIcon { }
|
||||
|
||||
for _, icon := range icons {
|
||||
width := icon.Bounds().Max.X
|
||||
height := icon.Bounds().Max.Y
|
||||
wmIcon := ewmh.WmIcon {
|
||||
Width: uint(width),
|
||||
Height: uint(height),
|
||||
Data: make ([]uint, width * height),
|
||||
}
|
||||
|
||||
// manually convert image data beacuse of course we have to do
|
||||
// this
|
||||
index := 0
|
||||
for y := 0; y < height; y ++ {
|
||||
for x := 0; x < width; x ++ {
|
||||
r, g, b, a := icon.At(x, y).RGBA()
|
||||
r >>= 8
|
||||
g >>= 8
|
||||
b >>= 8
|
||||
a >>= 8
|
||||
wmIcon.Data[index] =
|
||||
(uint(a) << 24) |
|
||||
(uint(r) << 16) |
|
||||
(uint(g) << 8) |
|
||||
(uint(b) << 0)
|
||||
index ++
|
||||
}}
|
||||
|
||||
wmIcons = append(wmIcons, wmIcon)
|
||||
}
|
||||
|
||||
err = ewmh.WmIconSet(backend.connection, backend.window.Id, wmIcons)
|
||||
return
|
||||
}
|
||||
|
||||
func (backend *Backend) handleXEvent (event xgb.Event) {
|
||||
@@ -192,6 +226,8 @@ func factory (application *stone.Application) (output stone.Backend, err error)
|
||||
0)
|
||||
backend.window.Map()
|
||||
backend.window.Listen(xproto.EventMaskStructureNotify)
|
||||
backend.SetTitle(application.Title())
|
||||
backend.SetIcon(application.Icon())
|
||||
|
||||
// create a canvas
|
||||
backend.canvas = xgraphics.New (
|
||||
|
||||
Reference in New Issue
Block a user