From 07f39afa0af431656e74fc27322b6c88f9e364a6 Mon Sep 17 00:00:00 2001 From: ShuheiKubota Date: Mon, 18 Nov 2019 18:42:38 +0900 Subject: [PATCH] refactor: rename to private --- cmd_alpha.go | 8 +++---- cmd_minmax.go | 8 +++---- cmd_resize.go | 12 +++++----- cmd_topmost.go | 6 ++--- vvin.go | 64 +++++++++++++++++++++++++++++--------------------- 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/cmd_alpha.go b/cmd_alpha.go index 731bb87..497c5fc 100644 --- a/cmd_alpha.go +++ b/cmd_alpha.go @@ -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 diff --git a/cmd_minmax.go b/cmd_minmax.go index bd7a916..20db10c 100644 --- a/cmd_minmax.go +++ b/cmd_minmax.go @@ -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) } } diff --git a/cmd_resize.go b/cmd_resize.go index 0d598f8..61f606c 100644 --- a/cmd_resize.go +++ b/cmd_resize.go @@ -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) } } diff --git a/cmd_topmost.go b/cmd_topmost.go index 0d715f3..3d9b893 100644 --- a/cmd_topmost.go +++ b/cmd_topmost.go @@ -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) } diff --git a/vvin.go b/vvin.go index b7ed358..dda6b53 100644 --- a/vvin.go +++ b/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 {