0

I'm working on a TUI (Text User Interface) library for C++, and I have a function for detecting the size of the console window. Is it possible for me to detect a window resize? I would prefer if it would work with any terminal emulator, but if it matters I am using Ubuntu Budgie 20.10, and my terminal emulator is Tilix.

2 Answers 2

7

You can set up a signal handler for the SIGWINCH signal (you can use signal() or sigaction()), and you will get this signal whenever the terminal size changes. Note that, as with all signal handlers, any code in the signal handler must be signal-safe.

If you are using the curses library, you will get a KEY_RESIZE key, and then check COLS and LINES.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I'll look into it. I would also like to point out, that I am not using curses/ncurses, I'm using ASCII escape codes to control it.
Not sure how useful this is for the OP thread but after listening to SIGWINCH signal you can get the size using ioctl with TIOCGWINSZ as the op argument and a winsize struct as a 3rd argument.
-2

I found a way by constantly checking the screen size. If the screen size changes, it will be recorded and the screen redrawn.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.