Skip to content

Commit

Permalink
Switch dbus/xinerama depending on XDG_SESSION_TYPE
Browse files Browse the repository at this point in the history
  • Loading branch information
kbinani committed Aug 19, 2024
1 parent e8201fc commit 59f9954
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/xwindow/xwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ import (
var gCounter uint64 = 0

func Capture(x, y, width, height int) (img *image.RGBA, e error) {
sessionType := os.Getenv("XDG_SESSION_TYPE")
if sessionType == "wayland" {
return captureDbus(x, y, width, height)
} else {
return captureXinerama(x, y, width, height)
}
}

func captureDbus(x, y, width, height int) (img *image.RGBA, e error) {
c, err := dbus.ConnectSessionBus()
if err != nil {
return nil, fmt.Errorf("dbus.SessionBus() failed: %v", err)
Expand Down Expand Up @@ -91,14 +100,17 @@ func Capture(x, y, width, height int) (img *image.RGBA, e error) {
return nil, fmt.Errorf("png.Decode(%s) failed: %v", path, err)
}
canvas, err := util.CreateImage(image.Rect(0, 0, width, height))
if err != nil {
return nil, fmt.Errorf("util.CreateImage(%v) failed: %v", path, err)
}
draw.Draw(canvas, image.Rect(0, 0, width, height), img, image.Point{x, y}, draw.Src)
return canvas, e
}
}
return nil, fmt.Errorf("dbus.Message doesn't contain uri")
}

func Capture_(x, y, width, height int) (img *image.RGBA, e error) {
func captureXinerama(x, y, width, height int) (img *image.RGBA, e error) {
defer func() {
err := recover()
if err != nil {
Expand Down

0 comments on commit 59f9954

Please sign in to comment.