From 0bc5b39f1034971917c5331c6e0975f9fe1c6926 Mon Sep 17 00:00:00 2001 From: ShuheiKubota Date: Sun, 10 Nov 2019 09:48:51 +0900 Subject: [PATCH] add: alpha command --- go.sum | 1 + vvin.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/go.sum b/go.sum index ff92e53..e9c5162 100644 --- a/go.sum +++ b/go.sum @@ -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/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/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/rog v0.0.0-20190826055139-09f31aeaaebd h1:4HEm7TeZfpMp8mrjUoRt0MxTCvJrakuRn3rSbOSOBqE= github.com/shu-go/rog v0.0.0-20190826055139-09f31aeaaebd/go.mod h1:z2vjwV5lUEhVBjFneBZQECuBiel1kmKuU0sVJCwysDY= diff --git a/vvin.go b/vvin.go index 27cf2b7..53832ed 100644 --- a/vvin.go +++ b/vvin.go @@ -33,6 +33,7 @@ type globalCmd struct { Maximize maxCmd `cli:"maximize,max"` Restore restoreCmd `cli:"restore"` Resize resizeCmd `cli:"resize,move,mv"` + Alpha alphaCmd `cli:"alpha"` 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() { app := gli.NewWith(&globalCmd{}) app.Name = "vvin" @@ -193,6 +216,10 @@ var ( setWindowPos = user32.NewProc("SetWindowPos") getWindowRect = user32.NewProc("GetWindowRect") getSystemMetrics = user32.NewProc("GetSystemMetrics") + + setLayeredWindowAttributes = user32.NewProc("SetLayeredWindowAttributes") + getWindowLong = user32.NewProc("GetWindowLongW") + setWindowLong = user32.NewProc("SetWindowLongW") ) const ( @@ -210,6 +237,12 @@ const ( SM_CYVIRTUALSCREEN = 79 SM_CXSIZEFRAME = 32 SM_CYSIZEFRAME = 33 + + GWL_EXSTYLE = 0xFFFFFFEC + WS_EX_TOOLWINDOW = 0x00000080 + WS_EX_LAYERED = 0x80000 + + LWA_ALPHA = 0x2 ) type (