From ae1235d0e125508a833f12edd10f0aa59da739db Mon Sep 17 00:00:00 2001 From: ewt Date: Tue, 28 Oct 1997 16:17:13 +0000 Subject: [PATCH] started adding resizing stuff, but I need to know more slang first --- form.c | 5 +++++ newt.c | 50 +++++++++++++++++++++++++++++++++++++++++++------- newt.h | 4 ++++ 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/form.c b/form.c index f2811e8..de7d5e1 100644 --- a/form.c +++ b/form.c @@ -434,6 +434,11 @@ void newtFormRun(newtComponent co, struct newtExitStruct * es) { newtRefresh(); key = newtGetKey(); + if (key == NEWT_KEY_RESIZE) { + /* newtResizeScreen(1); */ + continue; + } + for (i = 0; i < form->numHotKeys; i++) { if (form->hotKeys[i] == key) { es->reason = NEWT_EXIT_HOTKEY; diff --git a/newt.c b/newt.c index 802aeac..48c957c 100644 --- a/newt.c +++ b/newt.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include @@ -30,6 +30,7 @@ static char * helplineStack[20]; static char ** currentHelpline = NULL; static int cursorRow, cursorCol; +static int needResize; static const char * defaultHelpLine = " / between elements | selects | next screen" @@ -117,6 +118,14 @@ void newtSetSuspendCallback(newtSuspendCallback cb) { suspendCallback = cb; } +static void handleSigwinch(int signum) { + needResize = 1; +} + +static int getkeyInterruptHook(void) { + return -1; +} + void newtFlushInput(void) { while (SLang_input_pending(0)) { SLang_getkey(); @@ -146,19 +155,31 @@ void newtCls(void) { newtRefresh(); } +void newtResizeScreen(int redraw) { + newtPushHelpLine(""); + + SLtt_get_screen_size(); + SLang_init_tty(0, 0, 0); + + SLsmg_touch_lines (0, SLtt_Screen_Rows - 1); + + /* I don't know why I need this */ + SLsmg_refresh(); + + newtPopHelpLine(); + + if (redraw) + SLsmg_refresh(); +} + int newtInit(void) { - struct winsize ws; char * MonoValue, * MonoEnv = "NEWT_MONO"; /* use the version variable just to be sure it gets included */ strlen(version); SLtt_get_terminfo(); - - if (!ioctl(1, TIOCGWINSZ, &ws)) { - SLtt_Screen_Rows = ws.ws_row; - SLtt_Screen_Cols = ws.ws_col; - } + SLtt_get_screen_size(); MonoValue = getenv(MonoEnv); if ( MonoValue == NULL ) { @@ -175,6 +196,13 @@ int newtInit(void) { /*SLtt_set_cursor_visibility(0);*/ + /*memset(&sa, 0, sizeof(sa)); + sa.sa_handler = handleSigwinch; + sigaction(SIGWINCH, &sa, NULL);*/ + + SLsignal_intr(SIGWINCH, handleSigwinch); + SLang_getkey_intr_hook = getkeyInterruptHook; + return 0; } @@ -238,6 +266,14 @@ int newtGetKey(void) { do { key = SLang_getkey(); + if (key == 0xFFFF) { + if (needResize) + return NEWT_KEY_RESIZE; + + /* ignore other signals */ + continue; + } + if (key == NEWT_KEY_SUSPEND && suspendCallback) suspendCallback(); } while (key == NEWT_KEY_SUSPEND); diff --git a/newt.h b/newt.h index 675f587..9b3f6d7 100644 --- a/newt.h +++ b/newt.h @@ -90,6 +90,7 @@ typedef void (*newtSuspendCallback)(void); int newtInit(void); int newtFinished(void); void newtCls(void); +void newtResizeScreen(int redraw); void newtWaitForKey(void); void newtClearKeyBuffer(void); void newtDelay(int usecs); @@ -227,6 +228,9 @@ void newtFormDestroy(newtComponent form); #define NEWT_KEY_F11 NEWT_KEY_EXTRA_BASE + 111 #define NEWT_KEY_F12 NEWT_KEY_EXTRA_BASE + 112 +/* not really a key, but newtGetKey returns it */ +#define NEWT_KEY_RESIZE NEWT_KEY_EXTRA_BASE + 113 + #define NEWT_ANCHOR_LEFT (1 << 0) #define NEWT_ANCHOR_RIGHT (1 << 1) #define NEWT_ANCHOR_TOP (1 << 2) -- 2.47.2