add: alpha command

This commit is contained in:
ShuheiKubota 2019-11-10 09:48:51 +09:00
parent f2e1c726d0
commit 0bc5b39f10
2 changed files with 34 additions and 0 deletions

1
go.sum
View file

@ -7,6 +7,7 @@ github.com/shu-go/cliparser v0.0.0-20190822025044-17b54d2ae1aa/go.mod h1:b89EpZS
github.com/shu-go/clise v0.0.0-20190822023516-79849fb81cfe/go.mod h1:VLiMEzXMBozBLD37i3id3qPflaupus48v/979ipQ43s= github.com/shu-go/clise v0.0.0-20190822023516-79849fb81cfe/go.mod h1:VLiMEzXMBozBLD37i3id3qPflaupus48v/979ipQ43s=
github.com/shu-go/gli v0.0.0-20191003020935-c6817caa1c0a h1:N7WMOChI8J5Dx22ZNbg4xaogju9gKARbjWmNaLo5irM= github.com/shu-go/gli v0.0.0-20191003020935-c6817caa1c0a h1:N7WMOChI8J5Dx22ZNbg4xaogju9gKARbjWmNaLo5irM=
github.com/shu-go/gli v0.0.0-20191003020935-c6817caa1c0a/go.mod h1:F0pECDJ/7sP7e6/BlCGNScgK3O3dOLo/0d8CeH1Z7Ks= github.com/shu-go/gli v0.0.0-20191003020935-c6817caa1c0a/go.mod h1:F0pECDJ/7sP7e6/BlCGNScgK3O3dOLo/0d8CeH1Z7Ks=
github.com/shu-go/gotwant v0.0.0-20190822031422-724391433f13 h1:ny9pVZ7fzuKapDWhfcQwVD5XtO/WUqYDt3BeOgbj+3o=
github.com/shu-go/gotwant v0.0.0-20190822031422-724391433f13/go.mod h1:UxvcvxZEQUBw6lS9UgXOPh1outjvx2+bvDlEOpCTuGo= github.com/shu-go/gotwant v0.0.0-20190822031422-724391433f13/go.mod h1:UxvcvxZEQUBw6lS9UgXOPh1outjvx2+bvDlEOpCTuGo=
github.com/shu-go/rog v0.0.0-20190826055139-09f31aeaaebd h1:4HEm7TeZfpMp8mrjUoRt0MxTCvJrakuRn3rSbOSOBqE= github.com/shu-go/rog v0.0.0-20190826055139-09f31aeaaebd h1:4HEm7TeZfpMp8mrjUoRt0MxTCvJrakuRn3rSbOSOBqE=
github.com/shu-go/rog v0.0.0-20190826055139-09f31aeaaebd/go.mod h1:z2vjwV5lUEhVBjFneBZQECuBiel1kmKuU0sVJCwysDY= github.com/shu-go/rog v0.0.0-20190826055139-09f31aeaaebd/go.mod h1:z2vjwV5lUEhVBjFneBZQECuBiel1kmKuU0sVJCwysDY=

33
vvin.go
View file

@ -33,6 +33,7 @@ type globalCmd struct {
Maximize maxCmd `cli:"maximize,max"` Maximize maxCmd `cli:"maximize,max"`
Restore restoreCmd `cli:"restore"` Restore restoreCmd `cli:"restore"`
Resize resizeCmd `cli:"resize,move,mv"` Resize resizeCmd `cli:"resize,move,mv"`
Alpha alphaCmd `cli:"alpha"`
targetHandle syscall.Handle targetHandle syscall.Handle
@ -171,6 +172,28 @@ func (c resizeCmd) Run(g globalCmd) {
} }
} }
type alphaCmd struct {
}
func (c alphaCmd) Run(args []string, g globalCmd) error {
if len(args) != 1 {
return errors.New("an argument is required")
}
alpha := toInt(args[0], 255)
style, _, _ := getWindowLong.Call(uintptr(g.targetHandle), GWL_EXSTYLE)
setWindowLong.Call(uintptr(g.targetHandle), GWL_EXSTYLE, style|WS_EX_LAYERED)
if alpha == 255 {
setWindowLong.Call(uintptr(g.targetHandle), GWL_EXSTYLE, style&^WS_EX_LAYERED)
} else {
setLayeredWindowAttributes.Call(uintptr(g.targetHandle), 0, uintptr(alpha), LWA_ALPHA)
}
return nil
}
func main() { func main() {
app := gli.NewWith(&globalCmd{}) app := gli.NewWith(&globalCmd{})
app.Name = "vvin" app.Name = "vvin"
@ -193,6 +216,10 @@ var (
setWindowPos = user32.NewProc("SetWindowPos") setWindowPos = user32.NewProc("SetWindowPos")
getWindowRect = user32.NewProc("GetWindowRect") getWindowRect = user32.NewProc("GetWindowRect")
getSystemMetrics = user32.NewProc("GetSystemMetrics") getSystemMetrics = user32.NewProc("GetSystemMetrics")
setLayeredWindowAttributes = user32.NewProc("SetLayeredWindowAttributes")
getWindowLong = user32.NewProc("GetWindowLongW")
setWindowLong = user32.NewProc("SetWindowLongW")
) )
const ( const (
@ -210,6 +237,12 @@ const (
SM_CYVIRTUALSCREEN = 79 SM_CYVIRTUALSCREEN = 79
SM_CXSIZEFRAME = 32 SM_CXSIZEFRAME = 32
SM_CYSIZEFRAME = 33 SM_CYSIZEFRAME = 33
GWL_EXSTYLE = 0xFFFFFFEC
WS_EX_TOOLWINDOW = 0x00000080
WS_EX_LAYERED = 0x80000
LWA_ALPHA = 0x2
) )
type ( type (