From c865f7146a92921d974e4cef36ed69615d39be89 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 11 Nov 2022 22:46:07 -0500 Subject: [PATCH] Buffer is now reallocated on window size change --- backends/x/x.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/backends/x/x.go b/backends/x/x.go index ffd2f14..78845c7 100644 --- a/backends/x/x.go +++ b/backends/x/x.go @@ -150,14 +150,13 @@ func (backend *Backend) handleXEvent (event xgb.Event) { backend.metrics.windowHeight = newHeight if sizeChanged { - // compress events configureEvent = backend.compressConfigureNotify(configureEvent) - - // resize and rebind canvas + // TODO: remove draw functions from reallocate canvas, + // and only reallocate when drawing and the window + // dimensions have changed backend.reallocateCanvas() - - // notify application of resize + backend.application.SetSize(backend.calculateBufferSize()) backend.channel <- stone.EventResize { } } } @@ -204,6 +203,16 @@ func (backend *Backend) calculateWindowSize () (x, y int) { return } +func (backend *Backend) calculateBufferSize () (width, height int) { + width = + (backend.metrics.windowWidth - backend.metrics.padding * 2) / + backend.metrics.cellWidth + height = + (backend.metrics.windowHeight - backend.metrics.padding * 2) / + backend.metrics.cellHeight + return +} + func (backend *Backend) reallocateCanvas () { backend.drawLock.Lock() defer backend.drawLock.Unlock()