BurntSushi / xgbutil

A utility library to make use of the X Go Binding easier. (Implements EWMH and ICCCM specs, key binding support, etc.)
Do What The F*ck You Want To Public License
194 stars 46 forks source link

ximg doesn't get saved with SavePng. #36

Open CamilleScholtz opened 7 years ago

CamilleScholtz commented 7 years ago

Reproduce

Expected result

A window that pops up with the contents of the screenshot and a png gets written to disk with the contents of the screenshot.

Actual result

A window that pops up with the contents of the screenshot and blank png gets written to disk (https://punpun.xyz/hqgz.png)

ghost commented 7 years ago

You can either show or save, not both at the same time, I think

CamilleScholtz commented 7 years ago

Nope, commenting out the XShowExtra line doesn't fix it. I don't know I am somehow missing a dependency or something, or if this is an actual problem with xgbutil.

ghost commented 7 years ago

Also comment out the last line, xevent.Main(x), otherwise the process hangs. if that doesn't work I can't help, it works fine on my system

ghost commented 7 years ago

here's the full snippet

// Example screenshot shows how to take a screenshot of the current desktop
// and show it in a window. In a comment, it also shows how to save it as
// a png.
//
// It works by getting the image of the root window, which automatically
// includes all child windows.
package main

import (
    "log"

    "github.com/BurntSushi/xgb/xproto"

    "github.com/BurntSushi/xgbutil"
    "github.com/BurntSushi/xgbutil/xgraphics"
)

func main() {
    X, err := xgbutil.NewConn()
    if err != nil {
        log.Fatal(err)
    }

    // Use the "NewDrawable" constructor to create an xgraphics.Image value
    // from a drawable. (Usually this is done with pixmaps, but drawables
    // can also be windows.)
    ximg, err := xgraphics.NewDrawable(X, xproto.Drawable(X.RootWin()))
    if err != nil {
        log.Fatal(err)
    }

    // Shows the screenshot in a window.
    //ximg.XShowExtra("Screenshot", true)

    // If you'd like to save it as a png, use:
    err = ximg.SavePng("screenshot.png")
    if err != nil {
        log.Fatal(err)
    }

    //xevent.Main(X)
}
CamilleScholtz commented 7 years ago

Yup, that's exactly what I tried, and yet it still produced a blank png image (that does have the right size though). The method you use in burdet does work, so I'm not sure what's going wrong here.

alex3d commented 3 months ago

This issue should be fixed by this PR https://github.com/jezek/xgbutil/pull/6