forked from u-root/wingo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transition to new XGB and new xgbutil. Graphics and many other things…
… 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
Showing
26 changed files
with
270 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.