diff options
author | Leandro Pereira <leandro@hardinfo.org> | 2016-07-10 08:05:19 -0300 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2020-07-02 12:44:27 +0200 |
commit | e10bc606f03750a211ae430b6e2079d8e5b1ed85 (patch) | |
tree | 4ad78e7340d6cbcaf4312ca669b592b6fe606447 | |
parent | c1a27fa340cc8921a35971e442a0836781b1e923 (diff) | |
download | filo-e10bc606f03750a211ae430b6e2079d8e5b1ed85.tar.gz filo-e10bc606f03750a211ae430b6e2079d8e5b1ed85.zip |
Handle SIGWINCH signal to properly resize editor
-rw-r--r-- | kilo.c | 28 |
1 files changed, 21 insertions, 7 deletions
@@ -34,7 +34,9 @@ #define KILO_VERSION "0.0.1" +#ifdef __GLIBC__ #define _POSIX_C_SOURCE 200809L +#endif #include <termios.h> #include <stdlib.h> @@ -49,6 +51,7 @@ #include <unistd.h> #include <stdarg.h> #include <fcntl.h> +#include <signal.h> /* Syntax highlight types */ #define HL_NORMAL 0 @@ -1244,6 +1247,22 @@ int editorFileWasModified(void) { return E.dirty; } +void updateWindowSize(void) { + if (getWindowSize(STDIN_FILENO,STDOUT_FILENO, + &E.screenrows,&E.screencols) == -1) { + perror("Unable to query the screen for size (columns / rows)"); + exit(1); + } + E.screenrows -= 2; /* Get room for status bar. */ +} + +void handleSigWinCh(int unused __attribute__((unused))) { + updateWindowSize(); + if (E.cy > E.screenrows) E.cy = E.screenrows - 1; + if (E.cx > E.screencols) E.cx = E.screencols - 1; + editorRefreshScreen(); +} + void initEditor(void) { E.cx = 0; E.cy = 0; @@ -1254,13 +1273,8 @@ void initEditor(void) { E.dirty = 0; E.filename = NULL; E.syntax = NULL; - if (getWindowSize(STDIN_FILENO,STDOUT_FILENO, - &E.screenrows,&E.screencols) == -1) - { - perror("Unable to query the screen for size (columns / rows)"); - exit(1); - } - E.screenrows -= 2; /* Get room for status bar. */ + updateWindowSize(); + signal(SIGWINCH, handleSigWinCh); } int main(int argc, char **argv) { |