From f7b162e83ec9200b07506166e7c00d55512606f4 Mon Sep 17 00:00:00 2001 From: Max Risuhin Date: Mon, 4 Feb 2019 00:26:34 -0800 Subject: [PATCH] Avoid double mutex lock on programmatic resize (#192) --- gui/gui.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gui/gui.go b/gui/gui.go index 134d33e..0201304 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -54,6 +54,7 @@ type GUI struct { prevLeftClickY uint16 leftClickTime time.Time leftClickCount int // number of clicks in a serie - single click, double click, or triple click + internalResize bool } func Min(x, y int) int { @@ -146,6 +147,7 @@ func New(config *config.Config, terminal *terminal.Terminal, logger *zap.Sugared terminalAlpha: 1, keyboardShortcuts: shortcuts, resizeLock: &sync.Mutex{}, + internalResize: false, }, nil } @@ -183,7 +185,9 @@ func (gui *GUI) resizeToTerminal(newCols uint, newRows uint) { gui.resizeCache = &ResizeCache{roundedWidth, roundedHeight, newCols, newRows} gui.logger.Debugf("Resizing window to %dx%d", roundedWidth, roundedHeight) + gui.internalResize = true gui.window.SetSize(roundedWidth, roundedHeight) // will trigger resize() + gui.internalResize = false } func (gui *GUI) generateDefaultCell(reverse bool) { @@ -213,8 +217,10 @@ func (gui *GUI) resize(w *glfw.Window, width int, height int) { return } - gui.resizeLock.Lock() - defer gui.resizeLock.Unlock() + if gui.internalResize == false { + gui.resizeLock.Lock() + defer gui.resizeLock.Unlock() + } gui.logger.Debugf("Initiating GUI resize to %dx%d", width, height)