Path: utzoo!attcan!uunet!samsung!zaphod.mps.ohio-state.edu!ncar!mephisto!mcnc!rti!mozart!news From: markwk@metheny.unx.sas.com (Mark Kernodle) Newsgroups: comp.windows.x Subject: Problem with multi-key translations in Xt Intrinsics. Keywords: multiple keysyms Message-ID: <1990Aug13.152553.114@unx.sas.com> Date: 13 Aug 90 15:25:53 GMT Sender: sasetb@sas.com Organization: SAS Institute Inc. Lines: 195 /* * Sample application for Xt intrinsics "feature" * Author: E. Blair, SAS Institute, Inc. (919) 677-8000 x6956 * * Problem statement: This program demonstrates what I believe to be a problem * in the _XtTranslateEvent Xt event handler interpretation of * eventObjTbl entries in the XtTranslations state table. This problem was * experienced in the DECwindows Xt intrinsics as well as in the Motif * intrinsics. The behavior is that non-initial key events associated * with a multi-key event sequence are thrown away even though a translation * action exists in the table that should receive the event. The * _XtTranslateEvent handler returns for such events because the EventRec * state is NULL. For this sample, I would expect the translation to match the * explicit sequences given, dispatching all other keys to the "normal-key" * action. Instead, KeyPress events for keys a and b are never delivered to * the "normal-key" action. */ #include #include #include #include /* Some statics for widgets */ static Widget toplevel, window_widget; /* * Widget action table and translations */ static void MyFocusIn(); static void MyFocusOut(); static void MyPFKey(); static void MyNormalKey(); static XtActionsRec TestActions[] = { {"focus-in", MyFocusIn}, {"focus-out", MyFocusOut}, {"pf-key", MyPFKey}, {"normal-key", MyNormalKey}, {NULL, NULL} }; static XtTranslations TestTLP = NULL; static char TestTranslations[] = ": focus-in() \n\ : focus-out() \n\ KP_F1,a: pf-key(1) \n\ KP_F1,b: pf-key(2) \n\ : normal-key()"; static void ShowKey(event) XEvent *event; { int keylen,keysym; char *modify,*keystr; char keyascii[4]; keylen = XLookupString (event, keyascii, sizeof(keyascii), &keysym, NULL); keyascii[keylen] = '\0'; if (event->xkey.state & ShiftMask) modify = "Shift"; if (event->xkey.state & LockMask) modify = "Lock"; else if (event->xkey.state & ControlMask) modify = "Control"; else if (event->xkey.state & Mod1Mask) modify = "Meta"; else modify = ""; if (isprint(keyascii[0])) keystr = keyascii; else { keystr = XKeysymToString (keysym); if (!keystr) keystr = "**NoKeySymString**"; } printf ("KeyString: %s%s\n",modify,keystr); return; } static void MyFocusIn (w, event, argv, nargs) Widget w; XEvent *event; String argv[]; int *nargs; { printf ("Focus in window\n"); return; } static void MyFocusOut (w, event, argv, nargs) Widget w; XEvent *event; String argv[]; int *nargs; { printf ("Focus left window\n"); return; } static void MyPFKey(w, event, argv, nargs) Widget w; XEvent *event; int *nargs; String argv[]; { int i; for (i=0; i < *nargs; i++) printf ("PF key: Arg[%d]: %s\n", i, argv[i]); ShowKey(event); return; } static void MyNormalKey(w, event, argv, nargs) Widget w; XEvent *event; int *nargs; String argv[]; { printf("Normal key event\n"); ShowKey (event); return; } static Widget build_main (p) Widget p; { Arg al[10]; int ac = 0; XtSetArg (al[ac], XmNx, 100); ac++; XtSetArg (al[ac], XmNy, 100); ac++; XtSetArg (al[ac], XmNheight, 100); ac++; XtSetArg (al[ac], XmNwidth, 300); ac++; XtSetArg (al[ac], XmNtranslations, TestTLP); ac++; window_widget = XmCreateDrawingArea(p, "Window", al, ac); XtManageChild (window_widget); return (window_widget); } main (argc, argv) int argc; char *argv[]; { Arg args[1]; /* * do toolkit initialization */ toplevel = XtInitialize("Simple", "TEST", NULL, 0, &argc, argv); if (!toplevel) { printf ("Initialize failed\n"); exit(1); } XtSetArg (args[0], XtNallowShellResize, TRUE); XtSetValues (toplevel, args, 1); XtAddActions (TestActions,XtNumber(TestActions)); TestTLP = XtParseTranslationTable (TestTranslations); if (!TestTLP) { printf ("Translation parse failed\n"); exit(1); } /* * now set up the test window */ build_main (toplevel); /* * and realize the test window */ XtRealizeWidget (toplevel); /* * main event loop for test window */ XtMainLoop(); }