Avoid double mutex lock on programmatic resize (#192)

This commit is contained in:
Max Risuhin 2019-02-04 00:26:34 -08:00 committed by Liam Galvin
parent 0c7499bf7e
commit f7b162e83e
1 changed files with 8 additions and 2 deletions

View File

@ -54,6 +54,7 @@ type GUI struct {
prevLeftClickY uint16 prevLeftClickY uint16
leftClickTime time.Time leftClickTime time.Time
leftClickCount int // number of clicks in a serie - single click, double click, or triple click leftClickCount int // number of clicks in a serie - single click, double click, or triple click
internalResize bool
} }
func Min(x, y int) int { func Min(x, y int) int {
@ -146,6 +147,7 @@ func New(config *config.Config, terminal *terminal.Terminal, logger *zap.Sugared
terminalAlpha: 1, terminalAlpha: 1,
keyboardShortcuts: shortcuts, keyboardShortcuts: shortcuts,
resizeLock: &sync.Mutex{}, resizeLock: &sync.Mutex{},
internalResize: false,
}, nil }, nil
} }
@ -183,7 +185,9 @@ func (gui *GUI) resizeToTerminal(newCols uint, newRows uint) {
gui.resizeCache = &ResizeCache{roundedWidth, roundedHeight, newCols, newRows} gui.resizeCache = &ResizeCache{roundedWidth, roundedHeight, newCols, newRows}
gui.logger.Debugf("Resizing window to %dx%d", roundedWidth, roundedHeight) gui.logger.Debugf("Resizing window to %dx%d", roundedWidth, roundedHeight)
gui.internalResize = true
gui.window.SetSize(roundedWidth, roundedHeight) // will trigger resize() gui.window.SetSize(roundedWidth, roundedHeight) // will trigger resize()
gui.internalResize = false
} }
func (gui *GUI) generateDefaultCell(reverse bool) { func (gui *GUI) generateDefaultCell(reverse bool) {
@ -213,8 +217,10 @@ func (gui *GUI) resize(w *glfw.Window, width int, height int) {
return return
} }
gui.resizeLock.Lock() if gui.internalResize == false {
defer gui.resizeLock.Unlock() gui.resizeLock.Lock()
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)