]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
added suspend callback
authorewt <ewt>
Fri, 13 Dec 1996 17:07:45 +0000 (17:07 +0000)
committerewt <ewt>
Fri, 13 Dec 1996 17:07:45 +0000 (17:07 +0000)
newt.c
newt.h
test.c

diff --git a/newt.c b/newt.c
index 2c79a330670ed0f60eccc85e59c4ba0d45cb5992..c777ace45406cf94f588388048b25ac6f88a6f13 100644 (file)
--- a/newt.c
+++ b/newt.c
@@ -107,6 +107,12 @@ static char * version = "Newt windowing library version " VERSION
                        "GNU Public Library. "
                        "Written by Erik Troan\n";
 
+static newtSuspendCallback suspendCallback = NULL;
+
+void newtSetSuspendCallback(newtSuspendCallback cb) {
+    suspendCallback = cb;
+}
+
 void newtRefresh(void) {
     SLsmg_refresh();
 }
@@ -212,7 +218,11 @@ int newtGetKey(void) {
     char buf[10], * chptr = buf;
     struct keymap * curr;
 
-    key = SLang_getkey();
+    do {
+       key = SLang_getkey();
+       if (key == NEWT_KEY_SUSPEND && suspendCallback)
+           suspendCallback();
+    } while (key == NEWT_KEY_SUSPEND);
 
     switch (key) {
       case 0x7f:
diff --git a/newt.h b/newt.h
index 2f16c38bb6882e166bd1cd3da729b649f590223b..b4e887ea91b9f0e5f40ee0742ca214be1a9d72dc 100644 (file)
--- a/newt.h
+++ b/newt.h
@@ -48,10 +48,10 @@ struct newtColors {
 
 typedef struct newtComponent * newtComponent;
 
-
 extern struct newtColors newtDefaultColorPalette;
 
 typedef void (*newtCallback)(newtComponent, void *);
+typedef void (*newtSuspendCallback)(void);
 
 int newtInit(void);
 int newtFinished(void);
@@ -66,6 +66,7 @@ void newtPopWindow(void);
 void newtSetColors(struct newtColors colors);
 void newtRefresh(void);
 void newtSuspend(void);
+void newtSetSuspendCallback(newtSuspendCallback cb);
 void newtResume(void);
 void newtPushHelpLine(char * text);
 void newtRedrawHelpLine(void);
@@ -151,6 +152,7 @@ void newtFormDestroy(newtComponent form);
 
 #define NEWT_KEY_TAB                   '\t'
 #define NEWT_KEY_ENTER                 '\r'
+#define NEWT_KEY_SUSPEND               '\032'                  /* ctrl - z*/
 #define NEWT_KEY_RETURN                        NEWT_KEY_ENTER
 
 #define NEWT_KEY_EXTRA_BASE            0x8000
diff --git a/test.c b/test.c
index 236c65524debf8cba0fd3f738a15dc96e5a0b9d4..da028d011296d5080a08eb18f862f7f140c4babf 100644 (file)
--- a/test.c
+++ b/test.c
@@ -1,6 +1,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <signal.h>
 
 #include "newt.h"
 
@@ -21,6 +22,12 @@ void disableCallback(newtComponent co, void * data) {
     newtRefresh();
 }
 
+void suspend(void) {
+    newtSuspend();
+    raise(SIGTSTP);
+    newtResume();
+}
+
 void main(void) {
     newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale;
     newtComponent lb, t, rsf, answer;
@@ -35,6 +42,8 @@ void main(void) {
     newtInit();
     newtCls();
 
+    newtSetSuspendCallback(suspend);
+
     newtDrawRootText(0, 0, "Newt test program");
     newtPushHelpLine(NULL);