Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!usc!venera.isi.edu!raveling From: raveling@venera.isi.edu (Paul Raveling) Newsgroups: gnu.emacs Subject: Input remapping, Part 1 of 8: x11fns.c Message-ID: <8718@venera.isi.edu> Date: 22 Jun 89 20:09:53 GMT Reply-To: raveling@venera.isi.edu (Paul Raveling) Distribution: gnu Organization: USC-Information Sciences Institute Lines: 161 HP/ISI input remapping files: Part 1 of 8 These are differences relative to the original src/x11fns.c in GNU emacs version 18.54. Changes are to add function x-rebind-keysym, which allows changing the keysym-to-string binding for X11 keyboard input. ------------------------------ Cut Here -------------------------------- 24a25,26 > /* Modified by Paul Raveling @ ISI to add keysym rebinding */ > 110a113,256 > extern char *keysymtostring (); /* In x11term.c */ > extern KeySym stringtokeysym (); /* In x11term.c */ > > /* Alternative modifier lists; */ > > static KeySym noshifts[2] = {0, 0}; > static KeySym shiftshifts[2] = {XK_Shift_L, XK_Shift_R}; > static KeySym ctlshifts[2] = {XK_Control_L, XK_Control_R}; > static KeySym metashifts[2] = {XK_Meta_L, XK_Meta_R}; > > > > > /*------------------ x-rebind-keysym -------------------*/ > > DEFUN ("x-rebind-keysym", Fx_rebind_keysym, Sx_rebind_keysym, 3, 3, > "sKey to rebind (KeySym, without \"XK_\"): \n\ > sShift key ([nil], None, Shift, Ctl, Meta): \n\ > sNew string bound to key: ", > "Rebind KEYSYM, with SHIFT-KEY, to NEWSTRING.\n\ > KEYSYM is the key's name as given in /usr/include/X11/keysymdef.h,\n\ > but without the \"XK_\" prefix.\n\ > SHIFT-KEY is nil, \"NONE\", \"SHIFT\", \"CTL\", or \"META\";\n\ > nil selects all combinations of shift keys.\n\ > NEWSTRING is an arbitrary string of keystrokes.\n\ > \n") > > (keysym, shift_key, newstring) > register Lisp_Object keysym; > register Lisp_Object shift_key; > register Lisp_Object newstring; > { > char *keysymstring, *shiftstring, *mapstring; > int keysymslen, shiftslen, mapslen; > KeySym target_key; > KeySym *modlist; > int num_mods; > > int i; > char *cp; > > > > CHECK_STRING (keysym, 1); > if (!NULL (shift_key)) > CHECK_STRING (shift_key,2); > CHECK_STRING (newstring, 3); > > #define setstring(src,dst,len) { \ > len = XSTRING (src) -> size; \ > dst = (char *) xmalloc (len+1); \ > bcopy (XSTRING (src) -> data, dst, len); \ > dst[len] = 0; } > > setstring (keysym, keysymstring, keysymslen) > if ( !NULL (shift_key) ) > setstring (shift_key,shiftstring, shiftslen) > else > shiftslen = 0; > setstring (newstring, mapstring, mapslen) > > > > /*------------------------------*/ > /* Identify key to remap */ > /*------------------------------*/ > > target_key = stringtokeysym ( keysymstring ); > > if ( target_key == 0 ) > { > error ("Keysym \"%s\" is not defined", keysymstring); > return Qnil; > } > > > > /*----------------------------------------------*/ > /* Identify modifier list(s) to use */ > /*----------------------------------------------*/ > > if ( shiftslen != 0 ) > { > cp = shiftstring; > i = shiftslen; > while ( i-- > 0 ) /* Fold string to upper case */ > { > if ((*cp >= 'a') && (*cp <= 'z')) > *cp -= 'a' - 'A'; > ++ cp; > } > } > > if ( shiftslen == 0 ) > num_mods = -1; > else if ( strcmp (shiftstring, "NONE") == 0 ) > { > modlist = noshifts; > num_mods = 0; > } > else if ( strcmp (shiftstring, "SHIFT") == 0 ) > { > modlist = shiftshifts; > num_mods = 2; > } > else if ( strcmp (shiftstring, "CTL") == 0 ) > { > modlist = ctlshifts; > num_mods = 2; > } > else if ( strcmp (shiftstring, "META") == 0 ) > { > modlist = metashifts; > num_mods = 2; > } > else > { > error ( "Shift key \"%s\" not recognized", shiftstring ); > return Qnil; > } > > > /*----------------------*/ > /* Map the key */ > /*----------------------*/ > > if ( num_mods != -1 ) > XRebindKeysym ( XXdisplay, target_key, modlist, num_mods, > mapstring, mapslen ); > else > { > XRebindKeysym ( XXdisplay, target_key, noshifts, 0, > mapstring, mapslen ); > XRebindKeysym ( XXdisplay, target_key, shiftshifts, 2, > mapstring, mapslen ); > XRebindKeysym ( XXdisplay, target_key, ctlshifts, 2, > mapstring, mapslen ); > XRebindKeysym ( XXdisplay, target_key, metashifts, 2, > mapstring, mapslen ); > } > > return Qt; > } > 847a994 > defsubr (&Sx_rebind_keysym);