GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Shrinking wincon vertically only generates a single KEY_RESIZE · Issue #26 · wmcbrine/PDCurses

Shrinking wincon vertically only generates a single KEY_RESIZE #26

New issue
Copy link
New issue
Copy link
Closed
Closed
Shrinking wincon vertically only generates a single KEY_RESIZE#26
Copy link

Description

@ulfalizer
ulfalizer
opened on Apr 7, 2018
Issue body actions

On at least Windows 10, shrinking a console window by dragging the lower horizontal edge of the window upwards only generates a single initial KEY_RESIZE event if resize_term(0, 0) is used. A scrollbar also appears, indicating that the console buffer is larger than the console window.

Here's what's happening:

  1. getch() calls ReadConsoleInput(), gets a WINDOW_BUFFER_SIZE_EVENT for the initial shrinking (which would make the scrollbar appear, presumably), and returns KEY_RESIZE.

  2. resize_term(0, 0) is called, which calls PDC_resize_screen(0, 0), which never resizes the console buffer, because SetConsoleScreenBufferSize() is only called if nlines || ncols.

  3. getch() is called again, but doesn't get any more WINDOW_BUFFER_SIZE_EVENTs, because only the size of the console window changes and not the size of the console buffer.

Resizing the terminal horizontally clears up the issue. I'm guessing the console buffer is reallocated internally in that case.

The following patch makes the behavior more robust for wincon, but might be incorrect for other platforms (or have other issues), so I'm submitting it more as an RFC. You still get scrollbars if you drag the lower edge quickly upwards, but it's a big improvement nonetheless.

diff --git a/pdcurses/initscr.c b/pdcurses/initscr.c
index 95f23fe..4e42038 100644
--- a/pdcurses/initscr.c
+++ b/pdcurses/initscr.c
@@ -300,7 +300,15 @@ int resize_term(int nlines, int ncols)
 {
     PDC_LOG(("resize_term() - called: nlines %d\n", nlines));
 
-    if (!stdscr || PDC_resize_screen(nlines, ncols) == ERR)
+    if (!stdscr)
+        return ERR;
+
+    if (!(nlines || ncols)) {
+        nlines = PDC_get_rows();
+        ncols = PDC_get_columns();
+    }
+
+    if (PDC_resize_screen(nlines, ncols) == ERR)
         return ERR;
 
     SP->lines = PDC_get_rows();
diff --git a/wincon/pdcscrn.c b/wincon/pdcscrn.c
index daef0e3..3b52041 100644
--- a/wincon/pdcscrn.c
+++ b/wincon/pdcscrn.c
@@ -525,33 +525,30 @@ int PDC_resize_screen(int nlines, int ncols)
     SMALL_RECT rect;
     COORD size, max;
 
-    if (nlines || ncols)
-    {
-        if (nlines < 2 || ncols < 2)
-            return ERR;
+    if (nlines < 2 || ncols < 2)
+        return ERR;
 
-        max = GetLargestConsoleWindowSize(pdc_con_out);
+    max = GetLargestConsoleWindowSize(pdc_con_out);
 
-        rect.Left = rect.Top = 0;
-        rect.Right = ncols - 1;
+    rect.Left = rect.Top = 0;
+    rect.Right = ncols - 1;
 
-        if (rect.Right > max.X)
-            rect.Right = max.X;
+    if (rect.Right > max.X)
+        rect.Right = max.X;
 
-        rect.Bottom = nlines - 1;
+    rect.Bottom = nlines - 1;
 
-        if (rect.Bottom > max.Y)
-            rect.Bottom = max.Y;
+    if (rect.Bottom > max.Y)
+        rect.Bottom = max.Y;
 
-        size.X = rect.Right + 1;
-        size.Y = rect.Bottom + 1;
+    size.X = rect.Right + 1;
+    size.Y = rect.Bottom + 1;
 
-        _fit_console_window(pdc_con_out, &rect);
-        SetConsoleScreenBufferSize(pdc_con_out, size);
-        _fit_console_window(pdc_con_out, &rect);
-        SetConsoleScreenBufferSize(pdc_con_out, size);
-        SetConsoleActiveScreenBuffer(pdc_con_out);
-    }
+    _fit_console_window(pdc_con_out, &rect);
+    SetConsoleScreenBufferSize(pdc_con_out, size);
+    _fit_console_window(pdc_con_out, &rect);
+    SetConsoleScreenBufferSize(pdc_con_out, size);
+    SetConsoleActiveScreenBuffer(pdc_con_out);
 
     PDC_flushinp();
 
-- 
2.14.1

(Are those duplicated _fit_console_window()/SetConsoleScreenBufferSize() calls intentional by the way?)

Here's the interface of my application. Wanting to drag the lower edge of the window is very natural, but currently messes up scrolling if the window is made smaller.

38304415-abebe868-3809-11e8-97fb-63f2b097d041

Activity

  1. wmcbrine
    added a commit that references this issue on Apr 7, 2018

    Improved Windows console resizing, when reducing the vertical size.

    503d7af
  2. wmcbrine commented on Apr 7, 2018

    @wmcbrine
    wmcbrine
    on Apr 7, 2018
    Owner
    More actions

    Thanks. You can refactor this so it only affects wincon/pdcscrn.c, which I've done in the version I just committed.

    The doubled lines seem to be necessary with programmatic resizing (see the Resize Test in testcurs), but not with user resizing, so I've changed that.

  3. wmcbrine
    closed this as completedon Apr 7, 2018
  4. polluks
    added a commit that references this issue on Aug 3, 2019

    Improved Windows console resizing, when reducing the vertical size.

    257e741
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.