Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch resize events on windows #1961

Open
dankamongmen opened this issue Jul 20, 2021 · 6 comments
Open

catch resize events on windows #1961

dankamongmen opened this issue Jul 20, 2021 · 6 comments
Labels
enhancement New feature or request input readin' dem bytes mswindows microsoft windows

Comments

@dankamongmen
Copy link
Owner

I assume Windows doesn't make use of POSIX signals (probably a good thing), so we'll need some replacement for SIGWINCH handling on that platform. @michaelsbradleyjr in #1953 refers to some event. thirty seconds of search suggests that the emulator receives a WM_SIZING message through its WindowProc function, which @michaelsbradleyjr 's mention of PeekConsoleInputW kinda implies gets turned into an input on stdin (maybe not)?

@dankamongmen dankamongmen added enhancement New feature or request mswindows microsoft windows labels Jul 20, 2021
@michaelsbradleyjr
Copy link
Collaborator

At one point I was researching terminal resize on Windows given the lack of SIGWINCH and found this:

nico-abram/kibi@434b355

This is the part that caught my eye:

pub fn has_window_size_changed() -> bool { 
    let mut buf: [INPUT_RECORD; 1024] = [Default::default(); 1024];
    let mut read: u32 = 0;
    unsafe {
        PeekConsoleInputW(
            std::os::windows::io::AsRawHandle::as_raw_handle(&HandleRef::stdin()), 
            buf.as_mut_ptr(), 1024, &mut read)
    };
    return buf.iter().any(|x| x.EventType == WINDOW_BUFFER_SIZE_EVENT);
}

I don't recall exactly which search terms, GitHub issues/PRs, etc. I used/followed to end up there, but I kept a note of the commit for future reference.

@michaelsbradleyjr
Copy link
Collaborator

Actually, nevermind, it doesn't work... I found the relevant GH issue (a PR was never made):

ilai-deutel/kibi#32 (comment)

@dankamongmen
Copy link
Owner Author

this obviously ties into #1982

@WSLUser
Copy link

WSLUser commented Aug 2, 2021

https://docs.microsoft.com/en-us/windows/console/ Perhaps this will help. Specifically:

Finding the window size must still be performed with GetConsoleScreenBufferInfo for applications attempting to draw columns, grids, or fill the display. Window and buffer size will match in a pseudoconsole session.

@dankamongmen
Copy link
Owner Author

According to the esteemed @magiblot, it looks like we get window resize events with ReadConsoleInputW. we can put that together with GetConsoleScreenBufferInfo as mentioned by @WSLUser above, and that ought be a complete solution.

@dankamongmen
Copy link
Owner Author

we've got the GetConsoleScreenBufferInfo() working now (though only for Windows Terminal, not for mintty). we need switch from read() to ReadConsoleInputW() in src/lib/input.c.

@dankamongmen dankamongmen added the input readin' dem bytes label Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request input readin' dem bytes mswindows microsoft windows
Projects
None yet
Development

No branches or pull requests

3 participants