From ca5051fa13fb4631a76fda9a72af6274e8a66d2d Mon Sep 17 00:00:00 2001 From: tramhao Date: Thu, 8 Apr 2021 22:54:22 +0800 Subject: [PATCH] Fixed:position of photo window --- playingbar.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/playingbar.go b/playingbar.go index 21f72a0..0106c70 100644 --- a/playingbar.go +++ b/playingbar.go @@ -3,10 +3,10 @@ package main import ( + "C" "bytes" "errors" "fmt" - "os" "strconv" "strings" "sync/atomic" @@ -17,10 +17,13 @@ import ( "github.com/tramhao/id3v2" "github.com/ztrue/tracerr" ugo "gitlab.com/diamondburned/ueberzug-go" - "golang.org/x/crypto/ssh/terminal" "github.com/issadarkthing/gomu/lyric" ) +import ( + "syscall" + "unsafe" +) // PlayingBar shows song name, progress and lyric type PlayingBar struct { @@ -335,14 +338,12 @@ func (p *PlayingBar) loadLyrics(currentSongPath string) error { go gomu.app.QueueUpdateDraw(func() { x, y, _, _ := p.GetInnerRect() - width, height, err := terminal.GetSize(int(os.Stdin.Fd())) + width, height, windowWidth, windowHeight := getConsoleSize() if err != nil { errorPopup(err) } - windowWidth := 1920 - windowHeight := 1200 - p.albumPhoto, err = ugo.NewImage(dstImage128, x*windowWidth/width, y*windowHeight/height) + p.albumPhoto, err = ugo.NewImage(dstImage128, (x+3)*windowWidth/width, (y+2)*windowHeight/height) if err != nil { errorPopup(err) } @@ -368,3 +369,15 @@ func (p *PlayingBar) getFull() int { func (p *PlayingBar) setFull(full int) { atomic.StoreInt64(&p.full, int64(full)) } + +func getConsoleSize() (int, int, int, int) { + var sz struct { + rows uint16 + cols uint16 + xpixels uint16 + ypixels uint16 + } + _, _, _ = syscall.Syscall(syscall.SYS_IOCTL, + uintptr(syscall.Stdout), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&sz))) + return int(sz.cols), int(sz.rows), int(sz.xpixels), int(sz.ypixels) +}