[comp.windows.x] function key binding to strings under X11.3

epb@ux1.lbl.gov (EPB Group) (01/11/89)

It seems that there is no way to define strings for the function
keys on a global scale (all clients connected to the server).

There is the Xlib function XRebindKeysym to rebind a keysym to a string,
but that is on an application-by-application basis.

What I want is a global binding, so that, for example, some function
keys have strings defined (e.g.) for vi, some for dbx, etc.

I have hacked xterm to read a .funkey file to do just that, but if anybody
knows of a more "correct" way to do this, I would be most pleased if
you could share that information.

The window manager, twm will allow binding of function keys (any key, 
actually) to FUNCTIONS or input to a shell, but not to a simple string.

Thanks.

Brian Smith
Lawrence Berkeley Laboratory, Berkeley

jim@EXPO.LCS.MIT.EDU (Jim Fulton) (01/11/89)

> It seems that there is no way to define strings for the function
> keys on a global scale (all clients connected to the server).

You mean "strings for *textual* applications that translate key presses into
some character set (perhaps ISO Latin-1)".


> 
> ...
> 
> What I want is a global binding, so that, for example, some function
> keys have strings defined (e.g.) for vi, some for dbx, etc.

But none of these programs (vi, dbx, etc.) are clients connected to the server!
Instead, you are asking for a way for all clients of class XTerm to insert
particular strings when particular keys are pressed.  

I know it sounds trivial, but the distinction is important.  For example, 
would you want the same things to be inserted in an editor?  Or in a text
widget?  In some cases you might, but probably not very many.


> I have hacked xterm to read a .funkey file to do just that, but if anybody
> knows of a more "correct" way to do this, I would be most pleased if
> you could share that information.

Yes, use the translation manager!  The string() action was added in R3
specifically to support insertion of strings.  

From the xterm man page:

        KEY TRANSLATIONS
             It is possible to rebind keys  (or  sequences  of  keys)  to
             arbitrary  strings  for  input, by changing the translations
             for the vt100 or tek4014 widgets.  Changing the translations
             for events other than key and button events is not expected,
             and will cause unpredictable behavior.
        
             ...
        
             string(string) Rebinds the key or key sequence to the string
                            value;  that  is, inserts the string argument
                            into the input stream.  Quotation  is  neces-
                            sary  if  the  string  contains whitespace or
                            non-alphanumeric characters.  If  the  string
                            argument  begins  with the characters ``0x'',
                            it is interpreted as a hex character constant
                            and  the  corresponding  character is sent in
                            the normal way.
        
             ...
        
        
             For example, a debugging session might benefit from the fol-
             lowing bindings:

                 *VT100.Translations: #override <Key>F13: keymap(dbx)
                 *VT100.dbxKeymap.translations: \
                      <Key>F14: keymap(None) \n\
                      <Key>F17: string("next") string(0x0d) \n\
                      <Key>F18: string("step") string(0x0d) \n\
                      <Key>F19: string("continue") string(0x0d) \n\
                      <Key>F20: string("print ") insert-selection(PRIMARY, CUT_BUFFER0)

Kimbrough@dsg.csc.ti.COM (Kerry Kimbrough) (01/11/89)

   > What I want is a global binding, so that, for example, some function
   > keys have strings defined (e.g.) for vi, some for dbx, etc.

Off the top of my head, the alternative that occurs to me is to use the keysyms
defined for function keys (see R3 Protocol, Appendix A, pp 98-99), interning
these as atoms which name properties of the server's (default) root window. Any
client which receives a keyboard event containing a function key keysym can then
get the string which is currently the value of the corresponding root property.
Some issues to work out include interaction with Xlib, transformation of keysym
to atom, and appropriate client-side caching mechanism.