xacct@uhccux.uhcc.hawaii.edu (X-Windows Account) (11/08/88)
Running twm 4.0, the version that appeared in comp.sources.x in September, under R2, SunOs 3.5, I find I cannot type into a window. Keys are pressed -- nothing happens. I think the problem is with grabbing keys, since: (1) the twm event handler is receiving events for every keypress, not just for keys that have actions associated in the .twmrc file, and (2) when I disable the call to XGrabKey for window contexts in add_window.c, then twm works ok. Maybe it's a problem with the way I made libX11.a or the Sun server? I used gcc, v. 1.29 for both. What's going wrong? Greg, lee@uhccux.uhcc.hawaii.edu
davep@ginsu.apple.COM (11/09/88)
In article <2593@uhccux.uhcc.hawaii.edu>, lee@uhccux.uhcc.hawaii.edu (Greg) writes: > Running twm 4.0, the version that appeared in comp.sources.x in > September, under R2, SunOs 3.5, I find I cannot type into a window. > Keys are pressed -- nothing happens. I think the problem is with > grabbing keys, since: (1) the twm event handler is receiving > events for every keypress, not just for keys that have actions > associated in the .twmrc file, and (2) when I disable the call > to XGrabKey for window contexts in add_window.c, then twm works > ok. Yes, you're right, it's a problem with grabbing keys. It's still a problem in twm 5.0 (which is included on the R3 tape). In twm 4.0, Tom added the ability to bind functions to keys on the keyboard. The .twmrc file you're using probably references a key for which your server does not have a keycode. In the .twmrc file, you specify a key string name; this gets converted into a keysym, of which there are many, and gives an error if the keysym doesn't exist. The keysym then gets converted to an actual keycode, of which a much smaller number generally exist. There is no error checking here; if there is no corresponding keycode, a 0 is returned. This value is passed as the keycode to XGrabKey, but 0 means AnyKey to XGrabKey, so it grabs all keys. Here's a patch for this problem. The line numbers match twm 5.0, but it succeeds in patching twm 4.0 also. *** /tmp/,RCSt1a00790 Wed Nov 9 01:20:05 1988 --- menus.c Wed Nov 9 01:20:11 1988 *************** *** 137,144 **** { FuncKey *tmp; KeySym keysym; ! if ((keysym = XStringToKeysym(name)) == NoSymbol) { fprintf(stderr, "twm: unknown key name \"%s\"\n", name); return; --- 137,150 ---- { FuncKey *tmp; KeySym keysym; + KeyCode keycode; ! /* ! * Don't let a 0 keycode go through, since that means AnyKey to the ! * XGrabKey call in GrabKeys(). ! */ ! if ((keysym = XStringToKeysym(name)) == NoSymbol || ! (keycode = XKeysymToKeycode(dpy, keysym)) == 0) { fprintf(stderr, "twm: unknown key name \"%s\"\n", name); return; *************** *** 162,168 **** tmp->name = name; tmp->keysym = keysym; ! tmp->keycode = XKeysymToKeycode(dpy, keysym); tmp->cont = cont; tmp->mods = mods; tmp->func = func; --- 168,174 ---- tmp->name = name; tmp->keysym = keysym; ! tmp->keycode = keycode; tmp->cont = cont; tmp->mods = mods; tmp->func = func; -- Dave Payne Apple Computer, A/UX Engineering Group davep@apple.com Cupertino, CA
myoung@ingr.UUCP (Mark Young) (11/10/88)
In article <2593@uhccux.uhcc.hawaii.edu>, xacct@uhccux.uhcc.hawaii.edu (X-Windows Account) writes: > > Running twm 4.0, the version that appeared in comp.sources.x in > September, under R2, SunOs 3.5, I find I cannot type into a window. > Keys are pressed -- nothing happens. > > Greg, lee@uhccux.uhcc.hawaii.edu I tracked down a problem like this with our twm, xterm and server. It seemed as though keystrokes were heading for the bitbucket. I localized the problem down the .twmrc file. It was that I had line like: "Clear" = : window : f.winrefresh when twm would parse this line, it would request the keysym and keycode for the "Clear" key. Unfortunatly, when I had defined the keytab for the server, I didn't define any key as the "Clear" key. In menus.c, the function AddFuncKey() calls XStringToKeysym() to get the keysym from from the string "Clear". I think that you get a good keysym, but when you call XKeysymToKeycode() a few lines down, since there is no keycode associated with the keysym, you get a zero back. Later, twm calls GrabKeys() which in turn calls XGrabKey() passing a zero as the keycode to grab. The problem is that XGrabKey() accepts 0 (#define AnyKey 0L) to be an indication that you want to grab all of the keys. Oops. I didn't have the time to try and come up with a patch for this nasty. Any takers. I guess I can go back and try if even Tom doesn't want to take a stab at it ;-). ...m (easier to find than fix) young --- ingr!myoung!myoung@uunet.uu.net | mark allan young | where {uunet,ihnp4}!ingr!myoung!myoung | intergraph corp, cr1105 | do I | one madison industrial pk | put the "Ask me about our Intergraph | huntsville, al 35807 | usual CLIPPER-based Workstations." | (205) 772-6094 | disclaimer
davep@ginsu.apple.COM (11/12/88)
I posted a patch for this problem. If you haven't received it via news yet, here it is. Return-Path: apple!ginsu.apple.com!davep Received: by ginsu.apple (5.51/SMI-3.2) id AA00138; Wed, 9 Nov 88 06:01:44 PST From: apple!ginsu.apple.com!davep Received: from EXPO.LCS.MIT.EDU by apple.com (5.59/25-eef) id AA24856; Wed, 9 Nov 88 04:24:34 PST Received: by expo.lcs.mit.edu; Wed, 9 Nov 88 04:47:30 EST Received: by ATHENA.MIT.EDU (5.45/4.7) id AA24479; Wed, 9 Nov 88 04:48:32 EST Received: by apple.com (5.59/25-eef) id AA22040; Wed, 9 Nov 88 01:41:19 PST Received: by ginsu.apple (5.51/SMI-3.2) id AA02668; Wed, 9 Nov 88 01:30:54 PST Message-Id: <8811090930.AA02668@ginsu.apple> To: xpert@athena.mit.edu Cc: uhccux!xacct@humu.nosc.mil (X-Windows Account), davep@apple.com Organization: Apple Computer, Inc., Cupertino, CA Subject: Re: twm 4.0 grabbing all keys In-Reply-To: Your message of 08 Nov 88 14:23:26 +0000. <2593@uhccux.uhcc.hawaii.edu> Date: Wed, 09 Nov 88 01:30:52 -0800 In article <2593@uhccux.uhcc.hawaii.edu>, lee@uhccux.uhcc.hawaii.edu (Greg) writes: > Running twm 4.0, the version that appeared in comp.sources.x in > September, under R2, SunOs 3.5, I find I cannot type into a window. > Keys are pressed -- nothing happens. I think the problem is with > grabbing keys, since: (1) the twm event handler is receiving > events for every keypress, not just for keys that have actions > associated in the .twmrc file, and (2) when I disable the call > to XGrabKey for window contexts in add_window.c, then twm works > ok. Yes, you're right, it's a problem with grabbing keys. It's still a problem in twm 5.0 (which is included on the R3 tape). In twm 4.0, Tom added the ability to bind functions to keys on the keyboard. The .twmrc file you're using probably references a key for which your server does not have a keycode. In the .twmrc file, you specify a key string name; this gets converted into a keysym, of which there are many, and gives an error if the keysym doesn't exist. The keysym then gets converted to an actual keycode, of which a much smaller number generally exist. There is no error checking here; if there is no corresponding keycode, a 0 is returned. This value is passed as the keycode to XGrabKey, but 0 means AnyKey to XGrabKey, so it grabs all keys. Here's a patch for this problem. The line numbers match twm 5.0, but it succeeds in patching twm 4.0 also. *** /tmp/,RCSt1a00790 Wed Nov 9 01:20:05 1988 --- menus.c Wed Nov 9 01:20:11 1988 *************** *** 137,144 **** { FuncKey *tmp; KeySym keysym; ! if ((keysym = XStringToKeysym(name)) == NoSymbol) { fprintf(stderr, "twm: unknown key name \"%s\"\n", name); return; --- 137,150 ---- { FuncKey *tmp; KeySym keysym; + KeyCode keycode; ! /* ! * Don't let a 0 keycode go through, since that means AnyKey to the ! * XGrabKey call in GrabKeys(). ! */ ! if ((keysym = XStringToKeysym(name)) == NoSymbol || ! (keycode = XKeysymToKeycode(dpy, keysym)) == 0) { fprintf(stderr, "twm: unknown key name \"%s\"\n", name); return; *************** *** 162,168 **** tmp->name = name; tmp->keysym = keysym; ! tmp->keycode = XKeysymToKeycode(dpy, keysym); tmp->cont = cont; tmp->mods = mods; tmp->func = func; --- 168,174 ---- tmp->name = name; tmp->keysym = keysym; ! tmp->keycode = keycode; tmp->cont = cont; tmp->mods = mods; tmp->func = func; -- Dave Payne Apple Computer, A/UX Engineering Group davep@apple.com Cupertino, CA