[PATCH] libXt add example for XtAppAddSignal man page

walter harms wharms at bfs.de
Sun Jan 23 08:20:12 PST 2011


libXt add example for XtAppAddSignal man page
add specs for XtSignalCallbackProc

Signed-off-by: walter harms <wharms at bfs.de>
---
 man/XtAppAddSignal.man |   89 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 88 insertions(+), 1 deletions(-)

diff --git a/man/XtAppAddSignal.man b/man/XtAppAddSignal.man
index 13fa09b..91fca3e 100644
--- a/man/XtAppAddSignal.man
+++ b/man/XtAppAddSignal.man
@@ -1,3 +1,5 @@
+.\" $Xorg: XtAppASig.man,v 1.3 2000/08/17 19:41:57 cpqbld Exp $
+.\"
 .\" Copyright (c) 1993, 1994  X Consortium
 .\"
 .\" Permission is hereby granted, free of charge, to any person obtaining a
@@ -23,6 +25,8 @@
 .\" dealing in this Software without prior written authorization from the
 .\" X Consortium.
 .\"
+.\" $XFree86: xc/doc/man/Xt/XtAppASig.man,v 1.2 2001/01/27 18:20:23 dawes Exp $
+.\"
 .ds tk X Toolkit
 .ds xT X Toolkit Intrinsics \- C Language Interface
 .ds xI Intrinsics
@@ -181,13 +185,96 @@ and the flag is set to
 .ZN False
 just before the callback is invoked.
 .LP
+the \fBXtSignalCallbackProc\fP is defined as follows:
+.nf
+	typedef void (*XtSignalCallbackProc)(
+	    XtPointer		/* closure */,
+	    XtSignalId*		/* id */
+	);
+.fi
+
+.LP
 The
 .ZN XtRemoveSignal
 function is called to remove the specified Intrinsics signal handler. The
 client should disable the source of the signal before calling
 .ZN XtRemoveSignal .
+.Sh EXAMPLE
+The example counts the signal SIGUSR1. You can send the signal
+either by pressing the widget or via the kill command.
+.nf
+
+#include <stdio.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include <Intrinsic.h>
+#include <StringDefs.h>
+#include <Xaw/Command.h>
+#include <Shell.h>
+/* gcc -I /usr/include/X11/ sample.c -lX11 -lXaw */
+
+
+static XtSignalId sigId;
+
+static void
+catchsig(int signal)
+{
+    XtNoticeSignal(sigId);
+}
+
+
+void signal_cb(XtPointer data,  XtSignalId *Id)
+{
+  char buf[40];
+  static int i;
+  i++;
+  snprintf(buf,sizeof(buf),"got:%ld ",i);
+  XtVaSetValues(data,XtNlabel,buf,NULL);
+}
+
+
+void sendsignal(Widget w, XtPointer c_data, XtPointer calld)
+{
+  raise(SIGUSR1);
+}
+
+
+int main(int argc, char *argv[])
+{
+  Widget top,cmd;
+  XtAppContext app;
+  char buf[40];
+
+  top=XtOpenApplication(&app,"Xtdemo",
+                         NULL,0,
+                         &argc,argv,
+                         NULL,
+                         applicationShellWidgetClass,
+                         NULL,0);
+
+  snprintf(buf,sizeof(buf),"PID:%ld ",getpid());
+
+  cmd=XtVaCreateManagedWidget
+    ("commando", commandWidgetClass, top,
+     XtNlabel,buf,
+     NULL);
+
+  XtAddCallback(cmd,XtNcallback,sendsignal,NULL);
+  signal(SIGUSR1,catchsig);
+
+  sigId=XtAppAddSignal(app,signal_cb,cmd);
+
+  XtRealizeWidget(top);
+  XtAppMainLoop(app);
+  return 0;
+}
+
+.fi
 .SH "SEE ALSO"
-XtAppAddTimeOut(3Xt),XtAppAddInput(3Xt),XtAppAddWorkProc(3Xt)
+.BR XtAppAddTimeOut (3Xt) ,
+.BR XtAppAddInput (3Xt) ,
+.BR XtAppAddWorkProc (3Xt)
 .br
 \fI\*(xT\fP
 .br
-- 
1.6.0.2



More information about the xorg-devel mailing list