]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
started adding resizing stuff, but I need to know more slang first
authorewt <ewt>
Tue, 28 Oct 1997 16:17:13 +0000 (16:17 +0000)
committerewt <ewt>
Tue, 28 Oct 1997 16:17:13 +0000 (16:17 +0000)
form.c
newt.c
newt.h

diff --git a/form.c b/form.c
index f2811e855b2cff21012256519243864cb5047dd1..de7d5e102cf316c9d64e3668ba3ad1cc38801196 100644 (file)
--- 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 802aeac9e368f60015564103829f9c4450414601..48c957c5459f82d6d1ef214ab8d02ebbd28ba2a2 100644 (file)
--- a/newt.c
+++ b/newt.c
@@ -2,7 +2,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/ioctl.h>
+#include <sys/signal.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <termios.h>
@@ -30,6 +30,7 @@ static char * helplineStack[20];
 static char ** currentHelpline = NULL;
 
 static int cursorRow, cursorCol;
+static int needResize;
 
 static const char * defaultHelpLine = 
 "  <Tab>/<Alt-Tab> between elements   |  <Space> selects   |  <F12> 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 675f5879a66bbdaf238aa0b82431ba70e0652d2c..9b3f6d789d650ebc7e94472c0f646eaf3e957302 100644 (file)
--- 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)