change: merge move command into restore command

This commit is contained in:
Shuhei Kubota 2019-11-09 20:57:42 +09:00
parent 56bef848e0
commit f2e1c726d0

64
vvin.go
View file

@ -32,8 +32,7 @@ type globalCmd struct {
Minimize minCmd `cli:"minimize,min"`
Maximize maxCmd `cli:"maximize,max"`
Restore restoreCmd `cli:"restore"`
Resize resizeCmd `cli:"resize"`
Move moveCmd `cli:"move,mv"`
Resize resizeCmd `cli:"resize,move,mv"`
targetHandle syscall.Handle
@ -172,67 +171,6 @@ func (c resizeCmd) Run(g globalCmd) {
}
}
type moveCmd struct {
Left string `cli:"left,x"`
Top string `cli:"top,y"`
NoRestorable bool `cli:"norestorable"`
rect RECT
}
func (c *moveCmd) Before(g globalCmd) error {
if c.Left == "" && c.Top == "" {
return errors.New("no options")
}
getWindowRect.Call(uintptr(g.targetHandle), uintptr(unsafe.Pointer(&c.rect)))
if g.Debug {
rog.Print(c.rect)
}
if c.Left != "" {
old := c.rect.Left
c.rect.Left = toInt(c.Left, g.scrWidth)
c.rect.Right += -old + c.rect.Left
}
if c.Top != "" {
old := c.rect.Top
c.rect.Top = toInt(c.Top, g.scrHeight)
c.rect.Bottom += -old + c.rect.Top
}
if g.Debug {
rog.Print(c.rect)
}
return nil
}
func (c moveCmd) Run(g globalCmd) {
if !c.NoRestorable {
showWindow.Call(uintptr(g.targetHandle), SW_HIDE)
showWindow.Call(uintptr(g.targetHandle), SW_MAXIMIZE)
setWindowPos.Call(
uintptr(g.targetHandle),
0,
uintptr(c.rect.Left),
uintptr(c.rect.Top),
uintptr(c.rect.Right-c.rect.Left),
uintptr(c.rect.Bottom-c.rect.Top),
SWP_NOACTIVATE|SWP_NOZORDER)
showWindow.Call(uintptr(g.targetHandle), SW_SHOWNA)
} else {
setWindowPos.Call(
uintptr(g.targetHandle),
0,
uintptr(c.rect.Left),
uintptr(c.rect.Top),
0,
0,
SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE)
}
}
func main() {
app := gli.NewWith(&globalCmd{})
app.Name = "vvin"