#37 reduce calls to resizeToScreen
authorKevin Lamonte <kevin.lamonte@gmail.com>
Sat, 10 Aug 2019 11:24:32 +0000 (06:24 -0500)
committerKevin Lamonte <kevin.lamonte@gmail.com>
Sat, 10 Aug 2019 11:24:32 +0000 (06:24 -0500)
src/jexer/TApplication.java

index bffe38e455f13658b4c7988c776e4c6af8d9b12a..fdbc0e39ad964318a801a211a71972f3a7f4bdb0 100644 (file)
@@ -294,6 +294,11 @@ public class TApplication implements Runnable {
      */
     private List<Runnable> invokeLaters = new LinkedList<Runnable>();
 
+    /**
+     * The last time the screen was resized.
+     */
+    private long screenResizeTime = 0;
+
     /**
      * WidgetEventHandler is the main event consumer loop.  There are at most
      * two such threads in existence: the primary for normal case and a
@@ -1025,8 +1030,14 @@ public class TApplication implements Runnable {
             if (event instanceof TResizeEvent) {
                 TResizeEvent resize = (TResizeEvent) event;
                 synchronized (getScreen()) {
-                    getScreen().setDimensions(resize.getWidth(),
-                        resize.getHeight());
+                    if ((System.currentTimeMillis() - screenResizeTime >= 15)
+                        || (resize.getWidth() < getScreen().getWidth())
+                        || (resize.getHeight() < getScreen().getHeight())
+                    ) {
+                        getScreen().setDimensions(resize.getWidth(),
+                            resize.getHeight());
+                        screenResizeTime = System.currentTimeMillis();
+                    }
                     desktopBottom = getScreen().getHeight() - 1;
                     mouseX = 0;
                     mouseY = 0;