doleh@encore.kent.EDU (Yaser Doleh) (06/16/89)
This is something I thought of sometime ago. It need some more work to make it a real xtalk program. I might work on it some more if I find the time. Anybody is welcome to change it as they wish. Also any suggesions to improve the program are welcomed. To compile % cc -o xtalk xtalk.c -lXaw -lXmu -lXt -lX11 To run % xtalk remotedisplay where the remote display is the display you want to talk to. If you do not specify remotedisplay the two windows will popup on your display on the top of each others. Try it, may be its worth something. ---------------------------------------------------------------------------- /* file xtalk.c Written by : Yaser Doleh Kent State University email doleh@kent.edu March 15, 1980 */ #include <X11/Xlib.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> #include <X11/Cardinals.h> #include <X11/AsciiText.h> #include <X11/Box.h> #include <X11/Command.h> #include <X11/Label.h> #include <X11/Shell.h> #include <X11/cursorfont.h> #define MAXSIZE 4096 #define WIDTH 500 #define HEIGHT 200 XtAppContext xtalk; Cursor cursor1, cursor2; Display *dpy1, *dpy2; Widget toplevel1, toplevel2, top1, top2, box1, box2, send1, send2, rec1, rec2; char sbuf1[MAXSIZE], sbuf2[MAXSIZE], rbuf1[MAXSIZE], rbuf2[MAXSIZE]; static void xtalk_exit() { exit(0); } static Beep(w, event, params, nparams) Widget w; XEvent *event; String *params; Cardinal *nparams; { XBell(XtDisplay(w), 99); } main(argc,argv) int argc; char *argv[]; { Arg args[10]; int num_args; static XtCallbackRec callback[][2]={ { xtalk_exit, NULL }, { NULL, NULL }, }; XtTranslations trans; static char trans_string[] = "<Key>: beep()\n"; static XtActionsRec actionsList[] = { { "beep", Beep }, { NULL, NULL }, }; XtToolkitInitialize(); xtalk = XtCreateApplicationContext(); dpy1 = XtOpenDisplay(NULL, NULL, NULL, "XTalk", NULL, 0, &argc, argv); if (argc > 1) dpy2 = XtOpenDisplay(NULL, argv[1], NULL, "XTalk", NULL, 0, &argc, argv); else dpy2 = dpy1; XtSetArg( args[0], XtNscreen, DefaultScreenOfDisplay(dpy1)); num_args=1; toplevel1 = XtAppCreateShell("xtalk", "XTalk", applicationShellWidgetClass, dpy1, args, num_args); XtSetArg( args[0], XtNscreen, DefaultScreenOfDisplay(dpy2)); num_args=1; toplevel2 = XtAppCreateShell("xtalk", "XTalk", applicationShellWidgetClass, dpy2, args, num_args); top1 = XtCreatePopupShell("xtalk", overrideShellWidgetClass, toplevel1, NULL, 0); top2 = XtCreatePopupShell("xtalk", overrideShellWidgetClass, toplevel2, NULL, 0); box1 = XtCreateWidget("Box1", boxWidgetClass, top1, NULL, 0); box2 = XtCreateWidget("Box2", boxWidgetClass, top2, NULL, 0); XtCreateManagedWidget("USER 1", labelWidgetClass, box1, NULL, 0); XtCreateManagedWidget("USER 2", labelWidgetClass, box2, NULL, 0); XtSetArg( args[0], XtNlabel, " Place pointer in top window and type "); XtCreateManagedWidget("label1", labelWidgetClass, box1, args, 1); XtCreateManagedWidget("label2", labelWidgetClass, box2, args, 1); XtSetArg( args[0], XtNlabel, " EXIT "); XtSetArg( args[1], XtNcallback, callback); XtCreateManagedWidget("exit 1", commandWidgetClass, box1, args, 2); XtCreateManagedWidget("exit 2", commandWidgetClass, box2, args, 2); cursor1 = XCreateFontCursor(dpy1, XC_xterm); cursor2 = XCreateFontCursor(dpy2, XC_xterm); XtSetArg( args[0], XtNstring, sbuf1); XtSetArg( args[1], XtNwidth, WIDTH); XtSetArg( args[2], XtNheight, HEIGHT); XtSetArg( args[3], XtNeditType, XttextEdit); XtSetArg( args[4], XtNlength, MAXSIZE); XtSetArg( args[5], XtNcursor, cursor1); XtSetArg( args[6], NULL, NULL); send1 = XtCreateManagedWidget("send1", asciiStringWidgetClass, box1, args, XtNumber(args)); XtSetArg( args[0], XtNstring, rbuf1); rec1 = XtCreateManagedWidget("rec1", asciiStringWidgetClass, box1, args, XtNumber(args)); XtSetArg( args[0], XtNstring, sbuf2); XtSetArg( args[5], XtNcursor, cursor2); send2 = XtCreateManagedWidget("send2", asciiStringWidgetClass, box2, args, XtNumber(args)); XtSetArg( args[0], XtNstring, rbuf2); rec2 = XtCreateManagedWidget("rec2", asciiStringWidgetClass, box2, args, XtNumber(args)); XtManageChild(box1); XtManageChild(box2); XtRealizeWidget(top1); XtRealizeWidget(top2); XtPopup(top1, XtGrabNonexclusive); XtPopup(top2, XtGrabNonexclusive); XtAddActions(actionsList, XtNumber(actionsList)); trans = XtParseTranslationTable(trans_string); XtOverrideTranslations(rec1, trans); XtOverrideTranslations(rec2, trans); while(1) { XEvent event; XtTextBlock text; XtNextEvent(&event); XtDispatchEvent(&event); text.firstPos = 0; text.ptr = sbuf1; text.length = strlen(sbuf1); XtTextReplace(rec2, 0, text.length, &text); text.firstPos = 0; text.ptr = sbuf2; text.length = strlen(sbuf2); XtTextReplace(rec1, 0, text.length, &text); } }