mirror of https://github.com/liamg/aminal.git
Do not trigger window resizing work if no change in dimensions (#164)
* Do not trigger window resizing work if no change in dimensions; Redundant dpiScale removed from GUI; dpiScale used to calculate desired size in pixels. * Keep last applied window size Signed-off-by: Max Risuhin <risuhin.max@gmail.com>
This commit is contained in:
parent
9c60167ca8
commit
2d2f4c95cc
|
@ -15,7 +15,7 @@ func (gui *GUI) getPackedFont(name string) (*glfont.Font, error) {
|
||||||
return nil, fmt.Errorf("packaged font '%s' could not be read: %s", name, err)
|
return nil, fmt.Errorf("packaged font '%s' could not be read: %s", name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
font, err := glfont.LoadFont(bytes.NewReader(fontBytes), gui.fontScale*gui.dpiScale/gui.scale(), gui.Width(), gui.Height())
|
font, err := glfont.LoadFont(bytes.NewReader(fontBytes), gui.fontScale*gui.dpiScale/gui.scale(), gui.width, gui.height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("font '%s' failed to load: %v", name, err)
|
return nil, fmt.Errorf("font '%s' failed to load: %v", name, err)
|
||||||
}
|
}
|
||||||
|
|
48
gui/gui.go
48
gui/gui.go
|
@ -15,13 +15,13 @@ import (
|
||||||
|
|
||||||
"github.com/go-gl/gl/all-core/gl"
|
"github.com/go-gl/gl/all-core/gl"
|
||||||
"github.com/go-gl/glfw/v3.2/glfw"
|
"github.com/go-gl/glfw/v3.2/glfw"
|
||||||
|
"github.com/kbinani/screenshot"
|
||||||
"github.com/liamg/aminal/buffer"
|
"github.com/liamg/aminal/buffer"
|
||||||
"github.com/liamg/aminal/config"
|
"github.com/liamg/aminal/config"
|
||||||
"github.com/liamg/aminal/terminal"
|
"github.com/liamg/aminal/terminal"
|
||||||
"github.com/liamg/aminal/version"
|
"github.com/liamg/aminal/version"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
"github.com/kbinani/screenshot"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GUI struct {
|
type GUI struct {
|
||||||
|
@ -29,8 +29,10 @@ type GUI struct {
|
||||||
logger *zap.SugaredLogger
|
logger *zap.SugaredLogger
|
||||||
config *config.Config
|
config *config.Config
|
||||||
terminal *terminal.Terminal
|
terminal *terminal.Terminal
|
||||||
width int //window width in pixels
|
width int //window width in pixels
|
||||||
height int //window height in pixels
|
height int //window height in pixels
|
||||||
|
appliedWidth int
|
||||||
|
appliedHeight int
|
||||||
resizeCache *ResizeCache // resize cache formed by resizeToTerminal()
|
resizeCache *ResizeCache // resize cache formed by resizeToTerminal()
|
||||||
dpiScale float32
|
dpiScale float32
|
||||||
fontMap *FontMap
|
fontMap *FontMap
|
||||||
|
@ -117,22 +119,6 @@ func (g *GUI) RecalculateDpiScale() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GUI) Width() int {
|
|
||||||
return int(float32(g.width) * g.dpiScale)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GUI) SetWidth(width int) {
|
|
||||||
g.width = int(float32(width) / g.dpiScale)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GUI) Height() int {
|
|
||||||
return int(float32(g.height) * g.dpiScale)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GUI) SetHeight(height int) {
|
|
||||||
g.height = int(float32(height) / g.dpiScale)
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(config *config.Config, terminal *terminal.Terminal, logger *zap.SugaredLogger) (*GUI, error) {
|
func New(config *config.Config, terminal *terminal.Terminal, logger *zap.SugaredLogger) (*GUI, error) {
|
||||||
|
|
||||||
shortcuts, err := config.KeyMapping.GenerateActionMap()
|
shortcuts, err := config.KeyMapping.GenerateActionMap()
|
||||||
|
@ -145,6 +131,8 @@ func New(config *config.Config, terminal *terminal.Terminal, logger *zap.Sugared
|
||||||
logger: logger,
|
logger: logger,
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 600,
|
height: 600,
|
||||||
|
appliedWidth: 0,
|
||||||
|
appliedHeight: 0,
|
||||||
dpiScale: 1,
|
dpiScale: 1,
|
||||||
terminal: terminal,
|
terminal: terminal,
|
||||||
fontScale: 10.0,
|
fontScale: 10.0,
|
||||||
|
@ -198,19 +186,25 @@ func (gui *GUI) resize(w *glfw.Window, width int, height int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if gui.appliedWidth == width && gui.appliedHeight == height {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
gui.resizeLock.Lock()
|
gui.resizeLock.Lock()
|
||||||
defer gui.resizeLock.Unlock()
|
defer gui.resizeLock.Unlock()
|
||||||
|
|
||||||
gui.logger.Debugf("Initiating GUI resize to %dx%d", width, height)
|
gui.logger.Debugf("Initiating GUI resize to %dx%d", width, height)
|
||||||
|
|
||||||
gui.SetWidth(width)
|
gui.width = width
|
||||||
gui.SetHeight(height)
|
gui.height = height
|
||||||
|
gui.appliedWidth = width
|
||||||
|
gui.appliedHeight = height
|
||||||
|
|
||||||
gui.logger.Debugf("Updating font resolutions...")
|
gui.logger.Debugf("Updating font resolutions...")
|
||||||
gui.loadFonts()
|
gui.loadFonts()
|
||||||
|
|
||||||
gui.logger.Debugf("Setting renderer area...")
|
gui.logger.Debugf("Setting renderer area...")
|
||||||
gui.renderer.SetArea(0, 0, gui.Width(), gui.Height())
|
gui.renderer.SetArea(0, 0, gui.width, gui.height)
|
||||||
|
|
||||||
if gui.resizeCache != nil && gui.resizeCache.Width == width && gui.resizeCache.Height == height {
|
if gui.resizeCache != nil && gui.resizeCache.Width == width && gui.resizeCache.Height == height {
|
||||||
gui.logger.Debugf("No need to resize internal terminal!")
|
gui.logger.Debugf("No need to resize internal terminal!")
|
||||||
|
@ -226,7 +220,7 @@ func (gui *GUI) resize(w *glfw.Window, width int, height int) {
|
||||||
gui.resizeCache = nil
|
gui.resizeCache = nil
|
||||||
|
|
||||||
gui.logger.Debugf("Setting viewport size...")
|
gui.logger.Debugf("Setting viewport size...")
|
||||||
gl.Viewport(0, 0, int32(gui.Width()), int32(gui.Height()))
|
gl.Viewport(0, 0, int32(gui.width), int32(gui.height))
|
||||||
|
|
||||||
gui.terminal.SetCharSize(gui.renderer.cellWidth, gui.renderer.cellHeight)
|
gui.terminal.SetCharSize(gui.renderer.cellWidth, gui.renderer.cellHeight)
|
||||||
|
|
||||||
|
@ -256,7 +250,8 @@ func (gui *GUI) Render() error {
|
||||||
var err error
|
var err error
|
||||||
gui.window, err = gui.createWindow()
|
gui.window, err = gui.createWindow()
|
||||||
gui.RecalculateDpiScale()
|
gui.RecalculateDpiScale()
|
||||||
gui.window.SetSize(gui.Width(), gui.Height())
|
gui.window.SetSize(int(float32(gui.width) * gui.dpiScale),
|
||||||
|
int(float32(gui.height) * gui.dpiScale))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to create window: %s", err)
|
return fmt.Errorf("Failed to create window: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -279,7 +274,7 @@ func (gui *GUI) Render() error {
|
||||||
titleChan := make(chan bool, 1)
|
titleChan := make(chan bool, 1)
|
||||||
resizeChan := make(chan bool, 1)
|
resizeChan := make(chan bool, 1)
|
||||||
|
|
||||||
gui.renderer = NewOpenGLRenderer(gui.config, gui.fontMap, 0, 0, gui.Width(), gui.Height(), gui.colourAttr, program)
|
gui.renderer = NewOpenGLRenderer(gui.config, gui.fontMap, 0, 0, gui.width, gui.height, gui.colourAttr, program)
|
||||||
|
|
||||||
gui.window.SetFramebufferSizeCallback(gui.resize)
|
gui.window.SetFramebufferSizeCallback(gui.resize)
|
||||||
gui.window.SetKeyCallback(gui.key)
|
gui.window.SetKeyCallback(gui.key)
|
||||||
|
@ -558,7 +553,8 @@ func (gui *GUI) createWindowWithOpenGLVersion(major int, minor int) (*glfw.Windo
|
||||||
glfw.WindowHint(glfw.ContextVersionMajor, major)
|
glfw.WindowHint(glfw.ContextVersionMajor, major)
|
||||||
glfw.WindowHint(glfw.ContextVersionMinor, minor)
|
glfw.WindowHint(glfw.ContextVersionMinor, minor)
|
||||||
|
|
||||||
window, err := glfw.CreateWindow(gui.Width(), gui.Height(), "Terminal", nil, nil)
|
window, err := glfw.CreateWindow(int(float32(gui.width) * gui.dpiScale),
|
||||||
|
int(float32(gui.height) * gui.dpiScale), "Terminal", nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := err.Error()
|
e := err.Error()
|
||||||
if i := strings.Index(e, ", got version "); i > -1 {
|
if i := strings.Index(e, ", got version "); i > -1 {
|
||||||
|
|
Loading…
Reference in New Issue