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)
|
||||
}
|
||||
|
||||
style, _, _ := getWindowLong.Call(uintptr(g.targetHandle), GWL_EXSTYLE)
|
||||
setWindowLong.Call(uintptr(g.targetHandle), GWL_EXSTYLE, style|WS_EX_LAYERED)
|
||||
style, _, _ := getWindowLong.Call(uintptr(g.targetHandle), gwlEXStyle)
|
||||
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 {
|
||||
setWindowLong.Call(uintptr(g.targetHandle), GWL_EXSTYLE, style&^WS_EX_LAYERED)
|
||||
setWindowLong.Call(uintptr(g.targetHandle), gwlEXStyle, style&^wsEXLayered)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -6,9 +6,9 @@ type minCmd struct {
|
|||
|
||||
func (c minCmd) Run(g globalCmd) {
|
||||
if c.Restore {
|
||||
showWindow.Call(uintptr(g.targetHandle), SW_RESTORE)
|
||||
showWindow.Call(uintptr(g.targetHandle), swRestore)
|
||||
} 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) {
|
||||
if c.Restore {
|
||||
showWindow.Call(uintptr(g.targetHandle), SW_RESTORE)
|
||||
showWindow.Call(uintptr(g.targetHandle), swRestore)
|
||||
} 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"`
|
||||
|
||||
rect RECT
|
||||
rect rect
|
||||
}
|
||||
|
||||
func (c *resizeCmd) Before(g globalCmd) error {
|
||||
|
@ -61,13 +61,13 @@ func (c *resizeCmd) Before(g globalCmd) error {
|
|||
|
||||
func (c resizeCmd) Run(g globalCmd) {
|
||||
if c.Restore {
|
||||
showWindow.Call(uintptr(g.targetHandle), SW_RESTORE)
|
||||
showWindow.Call(uintptr(g.targetHandle), swRestore)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.NoRestorable {
|
||||
showWindow.Call(uintptr(g.targetHandle), SW_HIDE)
|
||||
showWindow.Call(uintptr(g.targetHandle), SW_MAXIMIZE)
|
||||
showWindow.Call(uintptr(g.targetHandle), swHide)
|
||||
showWindow.Call(uintptr(g.targetHandle), swMaximize)
|
||||
}
|
||||
setWindowPos.Call(
|
||||
uintptr(g.targetHandle),
|
||||
|
@ -76,8 +76,8 @@ func (c resizeCmd) Run(g globalCmd) {
|
|||
uintptr(c.rect.Top),
|
||||
uintptr(c.rect.Right-c.rect.Left),
|
||||
uintptr(c.rect.Bottom-c.rect.Top),
|
||||
SWP_NOACTIVATE|SWP_NOZORDER)
|
||||
swpNoActivate|swpNoZOrder)
|
||||
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) {
|
||||
hwndInsertAfter := HWND_TOPMOST
|
||||
hwndInsertAfter := hwndTopmost
|
||||
if c.Restore {
|
||||
hwndInsertAfter = HWND_NOTOPMOST
|
||||
hwndInsertAfter = hwndNoTopmost
|
||||
}
|
||||
|
||||
setWindowPos.Call(
|
||||
|
@ -17,5 +17,5 @@ func (c topmostCmd) Run(g globalCmd) {
|
|||
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
|
||||
|
||||
w, _, _ := getSystemMetrics.Call(SM_CXVIRTUALSCREEN)
|
||||
h, _, _ := getSystemMetrics.Call(SM_CYVIRTUALSCREEN)
|
||||
w, _, _ := getSystemMetrics.Call(smCXVirtualScreen)
|
||||
h, _, _ := getSystemMetrics.Call(smCYVirtualScreen)
|
||||
c.scrWidth = int(w)
|
||||
c.scrHeight = int(h)
|
||||
|
||||
|
@ -90,49 +90,59 @@ var (
|
|||
setLayeredWindowAttributes = user32.NewProc("SetLayeredWindowAttributes")
|
||||
getWindowLong = user32.NewProc("GetWindowLongW")
|
||||
setWindowLong = user32.NewProc("SetWindowLongW")
|
||||
|
||||
systemParametersInfo = user32.NewProc("SystemParametersInfoW")
|
||||
)
|
||||
|
||||
const (
|
||||
SW_MAXIMIZE = 3
|
||||
SW_MINIMIZE = 6
|
||||
SW_RESTORE = 9
|
||||
SW_HIDE = 0
|
||||
SW_SHOWNA = 8
|
||||
swMaximize = 3
|
||||
smMinimize = 6
|
||||
swRestore = 9
|
||||
swHide = 0
|
||||
swShowNA = 8
|
||||
|
||||
SWP_NOSIZE = 0x0001
|
||||
SWP_NOMOVE = 0x0002
|
||||
SWP_NOZORDER = 0x0004
|
||||
SWP_NOACTIVATE = 0x0010
|
||||
SWP_SHOWWINDOW = 0x0040
|
||||
swpNoSize = 0x0001
|
||||
swpNoMove = 0x0002
|
||||
swpNoZOrder = 0x0004
|
||||
swpNoActivate = 0x0010
|
||||
swpShowWindow = 0x0040
|
||||
|
||||
SM_CXVIRTUALSCREEN = 78
|
||||
SM_CYVIRTUALSCREEN = 79
|
||||
SM_CXSIZEFRAME = 32
|
||||
SM_CYSIZEFRAME = 33
|
||||
smCXVirtualScreen = 78
|
||||
smCYVirtualScreen = 79
|
||||
smCXSizeFrame = 32
|
||||
smCYSizeFrame = 33
|
||||
|
||||
GWL_EXSTYLE = 0xFFFFFFEC
|
||||
WS_EX_TOOLWINDOW = 0x00000080
|
||||
WS_EX_LAYERED = 0x80000
|
||||
gwlEXStyle = 0xFFFFFFEC
|
||||
wsEXToolWindow = 0x00000080
|
||||
wsEXLayered = 0x80000
|
||||
|
||||
LWA_ALPHA = 0x2
|
||||
lwaAlpha = 0x2
|
||||
|
||||
HWND_TOPMOST = ^uintptr(0)
|
||||
HWND_NOTOPMOST = ^uintptr(1)
|
||||
hwndTopmost = ^uintptr(0)
|
||||
hwndNoTopmost = ^uintptr(1)
|
||||
|
||||
spiGetAnimation = 0x0048
|
||||
spiSetAnimation = 0x0049
|
||||
)
|
||||
|
||||
type (
|
||||
Window struct {
|
||||
window struct {
|
||||
Title string
|
||||
Handle syscall.Handle
|
||||
PID int
|
||||
}
|
||||
|
||||
RECT struct {
|
||||
rect struct {
|
||||
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 {
|
||||
b, _, _ := isWindow.Call(uintptr(hwnd))
|
||||
if b == 0 {
|
||||
|
@ -163,7 +173,7 @@ func listAllWindows() (wins []*Window, err error) {
|
|||
uintptr(unsafe.Pointer(&processID)),
|
||||
)
|
||||
|
||||
win := &Window{
|
||||
win := &window{
|
||||
Title: title,
|
||||
Handle: hwnd,
|
||||
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 == "" {
|
||||
for _, p := range ancestors {
|
||||
for _, w := range wins {
|
||||
|
|
Loading…
Reference in a new issue