refactor: rename to private
This commit is contained in:
parent
fd64888d1b
commit
07f39afa0a
5 changed files with 54 additions and 44 deletions
|
@ -19,12 +19,12 @@ func (c alphaCmd) Run(args []string, g globalCmd) error {
|
||||||
rog.Printf("alpha = %v -> %v", args[0], alpha)
|
rog.Printf("alpha = %v -> %v", args[0], alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
style, _, _ := getWindowLong.Call(uintptr(g.targetHandle), GWL_EXSTYLE)
|
style, _, _ := getWindowLong.Call(uintptr(g.targetHandle), gwlEXStyle)
|
||||||
setWindowLong.Call(uintptr(g.targetHandle), GWL_EXSTYLE, style|WS_EX_LAYERED)
|
setWindowLong.Call(uintptr(g.targetHandle), gwlEXStyle, style|wsEXLayered)
|
||||||
|
|
||||||
setLayeredWindowAttributes.Call(uintptr(g.targetHandle), 0, uintptr(alpha), LWA_ALPHA)
|
setLayeredWindowAttributes.Call(uintptr(g.targetHandle), 0, uintptr(alpha), lwaAlpha)
|
||||||
if alpha == 255 {
|
if alpha == 255 {
|
||||||
setWindowLong.Call(uintptr(g.targetHandle), GWL_EXSTYLE, style&^WS_EX_LAYERED)
|
setWindowLong.Call(uintptr(g.targetHandle), gwlEXStyle, style&^wsEXLayered)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -6,9 +6,9 @@ type minCmd struct {
|
||||||
|
|
||||||
func (c minCmd) Run(g globalCmd) {
|
func (c minCmd) Run(g globalCmd) {
|
||||||
if c.Restore {
|
if c.Restore {
|
||||||
showWindow.Call(uintptr(g.targetHandle), SW_RESTORE)
|
showWindow.Call(uintptr(g.targetHandle), swRestore)
|
||||||
} else {
|
} else {
|
||||||
showWindow.Call(uintptr(g.targetHandle), SW_MINIMIZE)
|
showWindow.Call(uintptr(g.targetHandle), smMinimize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ type maxCmd struct {
|
||||||
|
|
||||||
func (c maxCmd) Run(g globalCmd) {
|
func (c maxCmd) Run(g globalCmd) {
|
||||||
if c.Restore {
|
if c.Restore {
|
||||||
showWindow.Call(uintptr(g.targetHandle), SW_RESTORE)
|
showWindow.Call(uintptr(g.targetHandle), swRestore)
|
||||||
} else {
|
} else {
|
||||||
showWindow.Call(uintptr(g.targetHandle), SW_MAXIMIZE)
|
showWindow.Call(uintptr(g.targetHandle), swMaximize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ type resizeCmd struct {
|
||||||
|
|
||||||
NoRestorable bool `cli:"norestorable"`
|
NoRestorable bool `cli:"norestorable"`
|
||||||
|
|
||||||
rect RECT
|
rect rect
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *resizeCmd) Before(g globalCmd) error {
|
func (c *resizeCmd) Before(g globalCmd) error {
|
||||||
|
@ -61,13 +61,13 @@ func (c *resizeCmd) Before(g globalCmd) error {
|
||||||
|
|
||||||
func (c resizeCmd) Run(g globalCmd) {
|
func (c resizeCmd) Run(g globalCmd) {
|
||||||
if c.Restore {
|
if c.Restore {
|
||||||
showWindow.Call(uintptr(g.targetHandle), SW_RESTORE)
|
showWindow.Call(uintptr(g.targetHandle), swRestore)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.NoRestorable {
|
if !c.NoRestorable {
|
||||||
showWindow.Call(uintptr(g.targetHandle), SW_HIDE)
|
showWindow.Call(uintptr(g.targetHandle), swHide)
|
||||||
showWindow.Call(uintptr(g.targetHandle), SW_MAXIMIZE)
|
showWindow.Call(uintptr(g.targetHandle), swMaximize)
|
||||||
}
|
}
|
||||||
setWindowPos.Call(
|
setWindowPos.Call(
|
||||||
uintptr(g.targetHandle),
|
uintptr(g.targetHandle),
|
||||||
|
@ -76,8 +76,8 @@ func (c resizeCmd) Run(g globalCmd) {
|
||||||
uintptr(c.rect.Top),
|
uintptr(c.rect.Top),
|
||||||
uintptr(c.rect.Right-c.rect.Left),
|
uintptr(c.rect.Right-c.rect.Left),
|
||||||
uintptr(c.rect.Bottom-c.rect.Top),
|
uintptr(c.rect.Bottom-c.rect.Top),
|
||||||
SWP_NOACTIVATE|SWP_NOZORDER)
|
swpNoActivate|swpNoZOrder)
|
||||||
if !c.NoRestorable {
|
if !c.NoRestorable {
|
||||||
showWindow.Call(uintptr(g.targetHandle), SW_SHOWNA)
|
showWindow.Call(uintptr(g.targetHandle), swShowNA)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@ type topmostCmd struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c topmostCmd) Run(g globalCmd) {
|
func (c topmostCmd) Run(g globalCmd) {
|
||||||
hwndInsertAfter := HWND_TOPMOST
|
hwndInsertAfter := hwndTopmost
|
||||||
if c.Restore {
|
if c.Restore {
|
||||||
hwndInsertAfter = HWND_NOTOPMOST
|
hwndInsertAfter = hwndNoTopmost
|
||||||
}
|
}
|
||||||
|
|
||||||
setWindowPos.Call(
|
setWindowPos.Call(
|
||||||
|
@ -17,5 +17,5 @@ func (c topmostCmd) Run(g globalCmd) {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
SWP_NOSIZE|SWP_NOMOVE)
|
swpNoSize|swpNoMove)
|
||||||
}
|
}
|
||||||
|
|
64
vvin.go
64
vvin.go
|
@ -53,8 +53,8 @@ func (c *globalCmd) Before() error {
|
||||||
}
|
}
|
||||||
c.targetHandle = win.Handle
|
c.targetHandle = win.Handle
|
||||||
|
|
||||||
w, _, _ := getSystemMetrics.Call(SM_CXVIRTUALSCREEN)
|
w, _, _ := getSystemMetrics.Call(smCXVirtualScreen)
|
||||||
h, _, _ := getSystemMetrics.Call(SM_CYVIRTUALSCREEN)
|
h, _, _ := getSystemMetrics.Call(smCYVirtualScreen)
|
||||||
c.scrWidth = int(w)
|
c.scrWidth = int(w)
|
||||||
c.scrHeight = int(h)
|
c.scrHeight = int(h)
|
||||||
|
|
||||||
|
@ -90,49 +90,59 @@ var (
|
||||||
setLayeredWindowAttributes = user32.NewProc("SetLayeredWindowAttributes")
|
setLayeredWindowAttributes = user32.NewProc("SetLayeredWindowAttributes")
|
||||||
getWindowLong = user32.NewProc("GetWindowLongW")
|
getWindowLong = user32.NewProc("GetWindowLongW")
|
||||||
setWindowLong = user32.NewProc("SetWindowLongW")
|
setWindowLong = user32.NewProc("SetWindowLongW")
|
||||||
|
|
||||||
|
systemParametersInfo = user32.NewProc("SystemParametersInfoW")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SW_MAXIMIZE = 3
|
swMaximize = 3
|
||||||
SW_MINIMIZE = 6
|
smMinimize = 6
|
||||||
SW_RESTORE = 9
|
swRestore = 9
|
||||||
SW_HIDE = 0
|
swHide = 0
|
||||||
SW_SHOWNA = 8
|
swShowNA = 8
|
||||||
|
|
||||||
SWP_NOSIZE = 0x0001
|
swpNoSize = 0x0001
|
||||||
SWP_NOMOVE = 0x0002
|
swpNoMove = 0x0002
|
||||||
SWP_NOZORDER = 0x0004
|
swpNoZOrder = 0x0004
|
||||||
SWP_NOACTIVATE = 0x0010
|
swpNoActivate = 0x0010
|
||||||
SWP_SHOWWINDOW = 0x0040
|
swpShowWindow = 0x0040
|
||||||
|
|
||||||
SM_CXVIRTUALSCREEN = 78
|
smCXVirtualScreen = 78
|
||||||
SM_CYVIRTUALSCREEN = 79
|
smCYVirtualScreen = 79
|
||||||
SM_CXSIZEFRAME = 32
|
smCXSizeFrame = 32
|
||||||
SM_CYSIZEFRAME = 33
|
smCYSizeFrame = 33
|
||||||
|
|
||||||
GWL_EXSTYLE = 0xFFFFFFEC
|
gwlEXStyle = 0xFFFFFFEC
|
||||||
WS_EX_TOOLWINDOW = 0x00000080
|
wsEXToolWindow = 0x00000080
|
||||||
WS_EX_LAYERED = 0x80000
|
wsEXLayered = 0x80000
|
||||||
|
|
||||||
LWA_ALPHA = 0x2
|
lwaAlpha = 0x2
|
||||||
|
|
||||||
HWND_TOPMOST = ^uintptr(0)
|
hwndTopmost = ^uintptr(0)
|
||||||
HWND_NOTOPMOST = ^uintptr(1)
|
hwndNoTopmost = ^uintptr(1)
|
||||||
|
|
||||||
|
spiGetAnimation = 0x0048
|
||||||
|
spiSetAnimation = 0x0049
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Window struct {
|
window struct {
|
||||||
Title string
|
Title string
|
||||||
Handle syscall.Handle
|
Handle syscall.Handle
|
||||||
PID int
|
PID int
|
||||||
}
|
}
|
||||||
|
|
||||||
RECT struct {
|
rect struct {
|
||||||
Left, Top, Right, Bottom int32
|
Left, Top, Right, Bottom int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
anmationinfo struct {
|
||||||
|
Size uint32
|
||||||
|
Animate int32
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func listAllWindows() (wins []*Window, err error) {
|
func listAllWindows() (wins []*window, err error) {
|
||||||
cb := syscall.NewCallback(func(hwnd syscall.Handle, lparam uintptr) uintptr {
|
cb := syscall.NewCallback(func(hwnd syscall.Handle, lparam uintptr) uintptr {
|
||||||
b, _, _ := isWindow.Call(uintptr(hwnd))
|
b, _, _ := isWindow.Call(uintptr(hwnd))
|
||||||
if b == 0 {
|
if b == 0 {
|
||||||
|
@ -163,7 +173,7 @@ func listAllWindows() (wins []*Window, err error) {
|
||||||
uintptr(unsafe.Pointer(&processID)),
|
uintptr(unsafe.Pointer(&processID)),
|
||||||
)
|
)
|
||||||
|
|
||||||
win := &Window{
|
win := &window{
|
||||||
Title: title,
|
Title: title,
|
||||||
Handle: hwnd,
|
Handle: hwnd,
|
||||||
PID: int(processID),
|
PID: int(processID),
|
||||||
|
@ -218,7 +228,7 @@ func toInt(s string, max int) int32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func findFirstTarget(title string, wins []*Window, ancestors []int) *Window {
|
func findFirstTarget(title string, wins []*window, ancestors []int) *window {
|
||||||
if title == "" {
|
if title == "" {
|
||||||
for _, p := range ancestors {
|
for _, p := range ancestors {
|
||||||
for _, w := range wins {
|
for _, w := range wins {
|
||||||
|
|
Loading…
Reference in a new issue