-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from kbinani/flatten
Flatten project directory structure
- Loading branch information
Showing
14 changed files
with
138 additions
and
155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
module github.com/kbinani/screenshot | ||
|
||
go 1.17 | ||
go 1.21 | ||
|
||
require ( | ||
github.com/gen2brain/shm v0.0.0-20230802011745-f2460f5984f7 | ||
github.com/jezek/xgb v1.1.0 | ||
github.com/gen2brain/shm v0.1.0 | ||
github.com/jezek/xgb v1.1.1 | ||
github.com/lxn/win v0.0.0-20210218163916-a377121e959e | ||
) | ||
|
||
require ( | ||
golang.org/x/sys v0.24.0 // indirect | ||
github.com/godbus/dbus/v5 v5.1.0 // indirect | ||
golang.org/x/sys v0.11.0 // indirect | ||
) |
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,13 +1,11 @@ | ||
github.com/gen2brain/shm v0.0.0-20230802011745-f2460f5984f7 h1:VLEKvjGJYAMCXw0/32r9io61tEXnMWDRxMk+peyRVFc= | ||
github.com/gen2brain/shm v0.0.0-20230802011745-f2460f5984f7/go.mod h1:uF6rMu/1nvu+5DpiRLwusA6xB8zlkNoGzKn8lmYONUo= | ||
github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7nQPrNITa4= | ||
github.com/godbus/dbus v4.1.0+incompatible/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= | ||
github.com/gen2brain/shm v0.1.0 h1:MwPeg+zJQXN0RM9o+HqaSFypNoNEcNpeoGp0BTSx2YY= | ||
github.com/gen2brain/shm v0.1.0/go.mod h1:UgIcVtvmOu+aCJpqJX7GOtiN7X2ct+TKLg4RTxwPIUA= | ||
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= | ||
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= | ||
github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk= | ||
github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk= | ||
github.com/jezek/xgb v1.1.1 h1:bE/r8ZZtSv7l9gk6nU0mYx51aXrvnyb44892TwSaqS4= | ||
github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk= | ||
github.com/lxn/win v0.0.0-20210218163916-a377121e959e h1:H+t6A/QJMbhCSEH5rAuRxh+CtW96g0Or0Fxa9IKr4uc= | ||
github.com/lxn/win v0.0.0-20210218163916-a377121e959e/go.mod h1:KxxjdtRkfNoYDCUP5ryK7XJJNTnpC8atvtmTheChOtk= | ||
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= | ||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= | ||
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//go:build !s390x && !ppc64le && !darwin && !windows && (linux || freebsd || openbsd || netbsd) | ||
|
||
package screenshot | ||
|
||
import ( | ||
"github.com/jezek/xgb" | ||
"github.com/jezek/xgb/xinerama" | ||
"image" | ||
) | ||
|
||
// NumActiveDisplays returns the number of active displays. | ||
func NumActiveDisplays() (num int) { | ||
defer func() { | ||
e := recover() | ||
if e != nil { | ||
num = 0 | ||
} | ||
}() | ||
|
||
c, err := xgb.NewConn() | ||
if err != nil { | ||
return 0 | ||
} | ||
defer c.Close() | ||
|
||
err = xinerama.Init(c) | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
reply, err := xinerama.QueryScreens(c).Reply() | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
num = int(reply.Number) | ||
return num | ||
} | ||
|
||
// GetDisplayBounds returns the bounds of displayIndex'th display. | ||
// The main display is displayIndex = 0. | ||
func GetDisplayBounds(displayIndex int) (rect image.Rectangle) { | ||
defer func() { | ||
e := recover() | ||
if e != nil { | ||
rect = image.Rectangle{} | ||
} | ||
}() | ||
|
||
c, err := xgb.NewConn() | ||
if err != nil { | ||
return image.Rectangle{} | ||
} | ||
defer c.Close() | ||
|
||
err = xinerama.Init(c) | ||
if err != nil { | ||
return image.Rectangle{} | ||
} | ||
|
||
reply, err := xinerama.QueryScreens(c).Reply() | ||
if err != nil { | ||
return image.Rectangle{} | ||
} | ||
|
||
if displayIndex >= int(reply.Number) { | ||
return image.Rectangle{} | ||
} | ||
|
||
primary := reply.ScreenInfo[0] | ||
x0 := int(primary.XOrg) | ||
y0 := int(primary.YOrg) | ||
|
||
screen := reply.ScreenInfo[displayIndex] | ||
x := int(screen.XOrg) - x0 | ||
y := int(screen.YOrg) - y0 | ||
w := int(screen.Width) | ||
h := int(screen.Height) | ||
rect = image.Rect(x, y, x+w, y+h) | ||
return rect | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build freebsd | ||
|
||
package screenshot | ||
|
||
import ( | ||
"image" | ||
) | ||
|
||
// Capture returns screen capture of specified desktop region. | ||
// x and y represent distance from the upper-left corner of primary display. | ||
// Y-axis is downward direction. This means coordinates system is similar to Windows OS. | ||
func Capture(x, y, width, height int) (img *image.RGBA, e error) { | ||
return captureXinerama(x, y, width, height) | ||
} |
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
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Oops, something went wrong.