envbvs@epb2.lbl.gov (Brian V. Smith) (06/22/89)
The following 'xtalk' program was posted by Yaser Doleh recently.
I tried to make the asciiStringWidgetClass Text Widget use a vertical
scroll bar, but it seems to clobber the cursor in the window on the
second display. It dies with:
X Error: BadCursor, invalid Cursor parameter
Request Major code 1 ()
Request Minor code
ResourceID 0x170000a
Error Serial #52
Current Serial #68
When I remove the XtNtextOptions 'scrollVertical' then it works fine (without
a scrollbar of course).
Is there a known bug in using more than one display with the text widgets?
_____________________________________
Brian V. Smith (bvsmith@lbl.gov)
Lawrence Berkeley Laboratory
We don't need no signatures!
/* file xtalk.c
Written by : Yaser Doleh
Kent State University
email doleh@kent.edu
March 15, 1980
*/
#include <stdio.h>
#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
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];
XtAppContext xtalk;
static void xtalk_exit()
{
exit(0);
}
static void 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];
char dpy2name[100];
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) /* open second display */
{
strcpy(dpy2name,argv[1]);
if (strchr(dpy2name,':')==NULL)
strcat(dpy2name,":0");
dpy2 = XtOpenDisplay(NULL, dpy2name, NULL, "XTalk", NULL, 0,
&argc, argv);
if (dpy2 == NULL)
{
fprintf(stderr,"%s: Can't open display %s\n",argv[0],dpy2name);
exit(1);
}
XBell(dpy2, 99);
XBell(dpy2, 99);
XFlush(dpy2);
}
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", topLevelShellWidgetClass, toplevel1,
NULL, 0);
top2 = XtCreatePopupShell("xtalk", topLevelShellWidgetClass, toplevel2,
NULL, 0);
box1 = XtCreateWidget("Box1", boxWidgetClass, top1, NULL, 0);
box2 = XtCreateWidget("Box2", boxWidgetClass, top2, NULL, 0);
XtSetArg( args[0], XtNborderWidth, 0);
XtCreateManagedWidget("USER 1", labelWidgetClass, box1, args, 1);
XtCreateManagedWidget("USER 2", labelWidgetClass, box2, args, 1);
XtSetArg( args[0], XtNlabel, " Place pointer in top window and type ");
XtSetArg( args[1], XtNborderWidth, 0);
XtCreateManagedWidget("label1", labelWidgetClass, box1, args, 2);
XtCreateManagedWidget("label2", labelWidgetClass, box2, args, 2);
XtSetArg( args[0], XtNlabel, " EXIT ");
XtSetArg( args[1], XtNcallback, callback);
XtSetArg( args[2], XtNborderWidth, 2);
XtSetArg( args[3], XtNinternalHeight, 3);
XtCreateManagedWidget("exit 1", commandWidgetClass, box1, args, 4);
XtCreateManagedWidget("exit 2", commandWidgetClass, box2, args, 4);
cursor1 = XCreateFontCursor(dpy1, XC_xterm);
cursor2 = XCreateFontCursor(dpy2, XC_xterm);
num_args=0;
XtSetArg( args[num_args], XtNstring, sbuf1); num_args++;
XtSetArg( args[num_args], XtNwidth, WIDTH); num_args++;
XtSetArg( args[num_args], XtNheight, HEIGHT); num_args++;
XtSetArg( args[num_args], XtNeditType, XttextEdit); num_args++;
XtSetArg( args[num_args], XtNlength, MAXSIZE); num_args++;
XtSetArg( args[num_args], XtNcursor, cursor1); num_args++;
XtSetArg( args[num_args], XtNtextOptions, wordBreak); num_args++;
/*****************************************************************************/
/* The following seems to cause the cursor in the window on the second display
to become invalid. */
XtSetArg( args[num_args], XtNtextOptions, scrollVertical); num_args++;
/*****************************************************************************/
send1 = XtCreateManagedWidget("send1", asciiStringWidgetClass,
box1, args, num_args);
XtSetArg( args[0], XtNstring, rbuf1);
rec1 = XtCreateManagedWidget("rec1", asciiStringWidgetClass,
box1, args, num_args);
XtSetArg( args[0], XtNstring, sbuf2);
XtSetArg( args[5], XtNcursor, cursor2);
send2 = XtCreateManagedWidget("send2", asciiStringWidgetClass,
box2, args, num_args);
XtSetArg( args[0], XtNstring, rbuf2);
rec2 = XtCreateManagedWidget("rec2", asciiStringWidgetClass,
box2, args, num_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);
}
}swick@ATHENA.MIT.EDU (Ralph R. Swick) (06/23/89)
> Is there a known bug in using more than one display with the text widgets?
Actually, the bug is in XmuCvtStringToCursor; somewhere just before R3
an edit got lost that causes this routine to return the same Cursor
resource for two different servers - definitely a no-no.
(The version in Xt works).