Skip to content

Commit

Permalink
Transition to new XGB and new xgbutil. Graphics and many other things…
Browse files Browse the repository at this point in the history
… are badly broken, but wingo compiles and runs.
  • Loading branch information
Andrew Gallant (Ocelot) authored and Andrew Gallant (Ocelot) committed May 28, 2012
1 parent 7aaa920 commit 8df6eb7
Show file tree
Hide file tree
Showing 26 changed files with 270 additions and 323 deletions.
27 changes: 16 additions & 11 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"fmt"

"code.google.com/p/jamslam-x-go-binding/xgb"
"github.com/BurntSushi/xgb/xproto"

"github.com/BurntSushi/xgbutil/ewmh"
"github.com/BurntSushi/xgbutil/icccm"
Expand Down Expand Up @@ -36,7 +36,7 @@ type client struct {
hints *icccm.Hints
nhints *icccm.NormalHints
protocols []string
transientFor xgb.Id
transientFor xproto.Window
wmclass *icccm.WmClass

stateStore map[string]*clientState
Expand All @@ -49,7 +49,7 @@ type client struct {
frameFull *frameFull
}

func newClient(id xgb.Id) *client {
func newClient(id xproto.Window) *client {
return &client{
window: newWindow(id),
workspace: nil,
Expand Down Expand Up @@ -206,7 +206,7 @@ func (c *client) Close() {
return
}

X.Conn().SendEvent(false, c.window.id, 0, cm.Bytes())
xproto.SendEvent(X.Conn(), false, c.window.id, 0, string(cm.Bytes()))
} else {
c.window.kill()
}
Expand All @@ -219,14 +219,19 @@ func (c *client) Close() {
// (unmapIgnore is incremented whenever Wingo unmaps a window. When Wingo
// unmaps a window, we *don't* want to delete it, just hide it.)
func (c *client) Alive() bool {
X.Flush() // fills up the XGB event queue with ready events
X.Sync() // fills up the XGB event queue with ready events
xevent.Read(X, false) // fills up the xgbutil event queue without blocking

// we only consider a client marked for deletion when 'ignore' reaches 0
ignore := c.unmapIgnore
for _, ev := range X.QueuePeek() {
for _, everr := range xevent.Peek(X) {
if everr.Err != nil {
continue
}

wid := c.Win().id
if unmap, ok := ev.(xgb.UnmapNotifyEvent); ok && unmap.Window == wid {
ev := everr.Event
if um, ok := ev.(xproto.UnmapNotifyEvent); ok && um.Window == wid {
if ignore <= 0 {
return false
}
Expand All @@ -240,7 +245,7 @@ func (c *client) Alive() bool {
// Namely, when we know the window has been unmapped but are not sure
// if it is still an X resource.
func (c *client) TrulyAlive() bool {
_, err := xwindow.RawGeometry(X, c.window.id)
_, err := xwindow.RawGeometry(X, xproto.Drawable(c.window.id))
if err != nil {
return false
}
Expand Down Expand Up @@ -277,13 +282,13 @@ func (c *client) Focus() {
cm, err := xevent.NewClientMessage(32, c.window.id,
wm_protocols,
int(wm_take_focus),
int(X.GetTime()))
int(X.TimeGet()))
if err != nil {
logger.Warning.Println(err)
return
}

X.Conn().SendEvent(false, c.window.id, 0, cm.Bytes())
xproto.SendEvent(X.Conn(), false, c.window.id, 0, string(cm.Bytes()))

c.Focused()
}
Expand Down Expand Up @@ -445,7 +450,7 @@ func (c *client) Geom() xrect.Rect {
return c.window.geom
}

func (c *client) Id() xgb.Id {
func (c *client) Id() xproto.Window {
return c.window.id
}

Expand Down
22 changes: 11 additions & 11 deletions client_geometry.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"code.google.com/p/jamslam-x-go-binding/xgb"
"github.com/BurntSushi/xgb/xproto"

"github.com/BurntSushi/xgbutil/icccm"
"github.com/BurntSushi/xgbutil/xrect"
Expand All @@ -26,13 +26,13 @@ func (c *client) GravitizeX(x int, gravity int) int {

f := c.Frame()
switch {
case g == xgb.GravityStatic || g == xgb.GravityBitForget:
case g == xproto.GravityStatic || g == xproto.GravityBitForget:
x -= f.Left()
case g == xgb.GravityNorth || g == xgb.GravitySouth ||
g == xgb.GravityCenter:
case g == xproto.GravityNorth || g == xproto.GravitySouth ||
g == xproto.GravityCenter:
x -= abs(f.Left()-f.Right()) / 2
case g == xgb.GravityNorthEast || g == xgb.GravityEast ||
g == xgb.GravitySouthEast:
case g == xproto.GravityNorthEast || g == xproto.GravityEast ||
g == xproto.GravitySouthEast:
x -= f.Left() + f.Right()
}

Expand All @@ -58,13 +58,13 @@ func (c *client) GravitizeY(y int, gravity int) int {

f := c.Frame()
switch {
case g == xgb.GravityStatic || g == xgb.GravityBitForget:
case g == xproto.GravityStatic || g == xproto.GravityBitForget:
y -= f.Top()
case g == xgb.GravityEast || g == xgb.GravityWest ||
g == xgb.GravityCenter:
case g == xproto.GravityEast || g == xproto.GravityWest ||
g == xproto.GravityCenter:
y -= abs(f.Top()-f.Bottom()) / 2
case g == xgb.GravitySouthEast || g == xgb.GravitySouth ||
g == xgb.GravitySouthWest:
case g == xproto.GravitySouthEast || g == xproto.GravitySouth ||
g == xproto.GravitySouthWest:
y -= f.Top() + f.Bottom()
}

Expand Down
94 changes: 5 additions & 89 deletions client_icon.go
Original file line number Diff line number Diff line change
@@ -1,103 +1,19 @@
package main

import (
"image"
"image/color"
"image/draw"

"github.com/BurntSushi/xgbutil/ewmh"
"github.com/BurntSushi/xgbutil/icccm"
"github.com/BurntSushi/xgbutil/xgraphics"

"github.com/BurntSushi/wingo/logger"
)

func (c *client) iconImage(width, height int) (draw.Image, draw.Image) {
var img, mask draw.Image
var iok, mok bool

img, mask, iok, mok = c.iconTryEwmh(width, height)
if iok {
goto DONE
}

img, mask, iok, mok = c.iconTryIcccm()
if iok {
goto DONE
}

iok, mok = false, false
img = THEME.defaultIcon
if img != nil {
iok = true
goto DONE
}

DONE:
// If we've got an image, great! If not, just create a completely
// transparent image. It will take up space, but it won't look
// horrendous and we won't crash.
if iok {
img = xgraphics.Scale(img, width, height)
} else {
uni := image.NewUniform(color.RGBA{0, 0, 0, 0})
img = image.NewRGBA(image.Rect(0, 0, width, height))
draw.Draw(img, img.Bounds(), uni, image.ZP, draw.Src)
}

// Just as we did for img above, if we don't have a mask, create a benign
// mask in its stead.
if mok {
mask = xgraphics.Scale(mask, width, height)
} else {
uni := image.NewUniform(color.RGBA{0, 0, 0, 255})
mask = image.NewRGBA(img.Bounds())
draw.Draw(mask, mask.Bounds(), uni, image.ZP, draw.Src)
}
return img, mask
}

func (c *client) iconTryEwmh(width, height int) (
*image.RGBA, *image.RGBA, bool, bool) {

icons, err := ewmh.WmIconGet(X, c.Id())
if err != nil {
logger.Warning.Printf(
"Could not get EWMH icon for window %s because: %v", c, err)
return nil, nil, false, false
}

icon := xgraphics.FindBestIcon(width, height, icons)
if icon == nil {
logger.Warning.Printf(
"Could not find any decent icon for size (%d, %d) "+
" on window %s.", width, height, c)
return nil, nil, false, false
}

img, mask := xgraphics.EwmhIconToImage(icon)
return img, mask, true, true
}

func (c *client) iconTryIcccm() (*image.RGBA, *image.RGBA, bool, bool) {
if c.hints.Flags&icccm.HintIconPixmap == 0 ||
c.hints.IconPixmap == 0 || c.hints.IconMask == 0 {
return nil, nil, false, false
}

img, err := xgraphics.PixmapToImage(X, c.hints.IconPixmap)
if err != nil {
logger.Warning.Printf("Could not get IconPixmap from window %s "+
"because: %v", c, err)
return nil, nil, false, false
}

mask, err := xgraphics.BitmapToImage(X, c.hints.IconMask)
func (c *client) iconImage(width, height int) draw.Image {
ximg, err := xgraphics.FindIcon(X, c.Id(), width, height)
if err != nil {
logger.Warning.Printf("Could not get IconMask from window %s "+
"because: %v", c, err)
return img, nil, true, false
logger.Message.Printf("Could not find icon for '%s': %s", c, err)
ximg = xgraphics.NewConvert(X, THEME.defaultIcon)
}

return img, mask, true, true
return ximg
}
6 changes: 3 additions & 3 deletions client_manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"strings"

"code.google.com/p/jamslam-x-go-binding/xgb"
"github.com/BurntSushi/xgb/xproto"

"github.com/BurntSushi/xgbutil"
"github.com/BurntSushi/xgbutil/ewmh"
Expand Down Expand Up @@ -204,8 +204,8 @@ func (c *client) initPopulate() error {

func (c *client) listen() {
// Listen to the client for property and structure changes.
c.window.listen(xgb.EventMaskPropertyChange |
xgb.EventMaskStructureNotify)
c.window.listen(xproto.EventMaskPropertyChange |
xproto.EventMaskStructureNotify)

// attach some event handlers
xevent.PropertyNotifyFun(
Expand Down
6 changes: 3 additions & 3 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"
"unicode"

"code.google.com/p/jamslam-x-go-binding/xgb"
"github.com/BurntSushi/xgb/xproto"

"github.com/BurntSushi/xgbutil"
"github.com/BurntSushi/xgbutil/xevent"
Expand Down Expand Up @@ -174,7 +174,7 @@ func commandArgsClient(args []string) (*client, bool) {
return nil, false
}

goodId := xgb.Id(maybeId64)
goodId := xproto.Window(maybeId64)
for _, c := range WM.clients {
if c.Id() == goodId {
return c, true
Expand Down Expand Up @@ -473,7 +473,7 @@ func cmdPromptSelect(args ...string) func() {
func cmdQuit() func() {
return func() {
logger.Message.Println("The User has told us to quit.")
X.Quit()
xevent.Quit(X)
}
}

Expand Down
10 changes: 5 additions & 5 deletions command_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (kcmd keyCommand) attach(run func()) {
if kcmd.cmd == "PromptCyclePrev" || kcmd.cmd == "PromptCycleNext" {
// We've got to parse the key string first and make sure
// there are some modifiers; otherwise this utterly fails!
mods, _ := keybind.ParseString(X, kcmd.keyStr)
mods, _, _ := keybind.ParseString(X, kcmd.keyStr)
if mods == 0 {
logger.Warning.Printf("Sorry but the key binding '%s' for the %s "+
"command is invalid. It must have a modifier "+
Expand All @@ -57,22 +57,22 @@ func (kcmd keyCommand) attach(run func()) {
keybind.KeyPressFun(
func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
run()
}).Connect(X, ROOT.id, kcmd.keyStr)
}).Connect(X, ROOT.id, kcmd.keyStr, true)
keybind.KeyPressFun(
func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
run()
}).Connect(X, X.Dummy(), kcmd.keyStr)
}).Connect(X, X.Dummy(), kcmd.keyStr, true)
} else {
if kcmd.down {
keybind.KeyPressFun(
func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
run()
}).Connect(X, ROOT.id, kcmd.keyStr)
}).Connect(X, ROOT.id, kcmd.keyStr, true)
} else {
keybind.KeyReleaseFun(
func(X *xgbutil.XUtil, ev xevent.KeyReleaseEvent) {
run()
}).Connect(X, ROOT.id, kcmd.keyStr)
}).Connect(X, ROOT.id, kcmd.keyStr, true)
}
}
}
Loading

0 comments on commit 8df6eb7

Please sign in to comment.