Last active
July 22, 2022 20:13
-
-
Save ben-cohen/2a31fba7b9b954c47053810f06d31232 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// window-size-changed.c: Demo program to handle window changed events | |
// | |
// Ben Cohen, July 2022. | |
// | |
#include <sys/ioctl.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <signal.h> | |
int changed = 0; | |
void handler(int i) | |
{ | |
changed = 1; | |
} | |
int main (int argc, char **argv) | |
{ | |
signal(SIGWINCH, handler); | |
while (1) | |
{ | |
usleep(1000); | |
if (changed) | |
{ | |
changed = 0; | |
struct winsize terminal_size; | |
ioctl(STDOUT_FILENO, TIOCGWINSZ, &terminal_size); | |
printf ("rows %d\n", terminal_size.ws_row); | |
printf ("columns %d\n", terminal_size.ws_col); | |
printf ("x pixels %d\n", terminal_size.ws_xpixel); | |
printf ("y pixels %d\n", terminal_size.ws_ypixel); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment