2023-10-17 00:00:50 -04:00
|
|
|
//go:build windows
|
|
|
|
// +build windows
|
|
|
|
|
2023-10-16 09:51:11 -04:00
|
|
|
package vvin
|
2019-11-09 22:56:05 -05:00
|
|
|
|
2019-11-17 23:45:12 -05:00
|
|
|
import (
|
|
|
|
"errors"
|
2024-04-04 10:49:31 -04:00
|
|
|
"os"
|
2019-11-17 23:45:12 -05:00
|
|
|
|
2024-04-04 10:49:31 -04:00
|
|
|
"github.com/shu-go/nmfmt"
|
2019-11-17 23:45:12 -05:00
|
|
|
)
|
2019-11-09 22:56:05 -05:00
|
|
|
|
|
|
|
type alphaCmd struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c alphaCmd) Run(args []string, g globalCmd) error {
|
|
|
|
if len(args) != 1 {
|
2024-04-04 10:49:31 -04:00
|
|
|
return errors.New("an argument (opacity; 0%-100% or 0-255) is required")
|
2019-11-09 22:56:05 -05:00
|
|
|
}
|
|
|
|
|
2024-04-04 10:49:31 -04:00
|
|
|
opacity := toInt(args[0], 255)
|
|
|
|
|
|
|
|
g.debug(os.Stderr, "opacity $=arg:q -> $opacity/255\n",
|
|
|
|
nmfmt.M{
|
|
|
|
"arg": args[0],
|
|
|
|
"opacity": opacity,
|
|
|
|
})
|
2019-11-09 22:56:05 -05:00
|
|
|
|
2019-11-18 04:42:38 -05:00
|
|
|
style, _, _ := getWindowLong.Call(uintptr(g.targetHandle), gwlEXStyle)
|
|
|
|
setWindowLong.Call(uintptr(g.targetHandle), gwlEXStyle, style|wsEXLayered)
|
2019-11-09 22:56:05 -05:00
|
|
|
|
2024-04-04 10:49:31 -04:00
|
|
|
setLayeredWindowAttributes.Call(uintptr(g.targetHandle), 0, uintptr(opacity), lwaAlpha)
|
|
|
|
if opacity == 255 {
|
2019-11-18 04:42:38 -05:00
|
|
|
setWindowLong.Call(uintptr(g.targetHandle), gwlEXStyle, style&^wsEXLayered)
|
2019-11-09 22:56:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|