|
|
1.1 ! root 1: /************************************************************ ! 2: Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA. ! 3: ! 4: All Rights Reserved ! 5: ! 6: Permission to use, copy, modify, and distribute this ! 7: software and its documentation for any purpose and without ! 8: fee is hereby granted, provided that the above copyright no- ! 9: tice appear in all copies and that both that copyright no- ! 10: tice and this permission notice appear in supporting docu- ! 11: mentation, and that the names of Sun or MIT not be used in ! 12: advertising or publicity pertaining to distribution of the ! 13: software without specific prior written permission. Sun and ! 14: M.I.T. make no representations about the suitability of this ! 15: software for any purpose. It is provided "as is" without any ! 16: express or implied warranty. ! 17: ! 18: SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, ! 19: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- ! 20: NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- ! 21: ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ! 22: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR ! 23: PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR ! 24: OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH ! 25: THE USE OR PERFORMANCE OF THIS SOFTWARE. ! 26: ! 27: ********************************************************/ ! 28: ! 29: /* $Header: xmodmap.c,v 1.4 87/09/13 22:03:20 toddb Exp $ */ ! 30: #include <stdio.h> ! 31: #include <ctype.h> ! 32: #include "X11/Xlib.h" ! 33: #include "X11/Xutil.h" ! 34: #include "X11/Xatom.h" ! 35: ! 36: extern char *XKeysymToString(); ! 37: ! 38: Display *dpy; ! 39: ! 40: static update_map = 0; ! 41: static output_map = 0; ! 42: static FILE *fout = stdout; ! 43: ! 44: StartConnectionToServer(argc, argv) ! 45: int argc; ! 46: char *argv[]; ! 47: { ! 48: char *display; ! 49: int i; ! 50: ! 51: display = NULL; ! 52: for(i = 1; i < argc; i++) ! 53: { ! 54: if(index(argv[i], ':') != NULL) ! 55: display = argv[i]; ! 56: } ! 57: if (!(dpy = XOpenDisplay(display))) ! 58: { ! 59: perror("Cannot open display\n"); ! 60: exit(0); ! 61: } ! 62: } ! 63: UpdateModifierMapping(map) ! 64: XModifierKeymap *map; ! 65: { ! 66: int i = 5, res, tim = 2; ! 67: ! 68: while (i--) { ! 69: res = XSetModifierMapping(dpy, map); ! 70: fprintf(stderr, "res %d\n", res); ! 71: switch (res) { ! 72: case 0: /* Success */ ! 73: return (0); ! 74: case 1: /* Busy */ ! 75: fprintf (stderr, "You have %d seconds to lift your hands\n", ! 76: tim); ! 77: sleep(tim); ! 78: tim <<= 1; ! 79: break; ! 80: case 2: ! 81: fprintf(stderr, "Re-map failed\n"); ! 82: return (1); ! 83: default: ! 84: fprintf(stderr, "bad return %d\n", res); ! 85: } ! 86: } ! 87: fprintf(stderr, "I warned you\n"); ! 88: return (1); ! 89: } ! 90: ! 91: SetMod(argc, argv, map, mod) ! 92: int argc; ! 93: char **argv; ! 94: XModifierKeymap *map; ! 95: int mod; ! 96: { ! 97: if (argc) { ! 98: int keycode = 0; ! 99: ! 100: argv++; ! 101: if (isdigit(**argv)) { ! 102: keycode = atoi(*argv); ! 103: } else { ! 104: KeySym ks = XStringToKeysym(*argv); ! 105: ! 106: if (ks != NoSymbol) ! 107: keycode = XKeysymToKeycode(dpy, ks); ! 108: } ! 109: fprintf(stderr, "%s: 0x%x\n", *argv, keycode); ! 110: if (keycode) { ! 111: int i; ! 112: ! 113: for (i = 0; i < map->max_keypermod; i++) { ! 114: int index = mod*map->max_keypermod + i; ! 115: if (map->modifiermap[index] == 0) { ! 116: map->modifiermap[index] = (unsigned char) keycode; ! 117: return (1); ! 118: } ! 119: } ! 120: } ! 121: } ! 122: return (0); ! 123: } ! 124: ! 125: ClearMod(map, mod) ! 126: XModifierKeymap *map; ! 127: int mod; ! 128: { ! 129: int i; ! 130: ! 131: for (i = 0; i < map->max_keypermod; i++) ! 132: map->modifiermap[mod * map->max_keypermod + i] = '\0'; ! 133: } ! 134: ! 135: DecodeArgs(argc, argv, map) ! 136: int argc; ! 137: char **argv; ! 138: XModifierKeymap *map; ! 139: { ! 140: while (--argc > 0) { ! 141: argv++; ! 142: if (**argv == '-') { ! 143: switch (*++*argv) { ! 144: case '1': ! 145: case '2': ! 146: case '3': ! 147: case '4': ! 148: case '5': ! 149: ClearMod(map, **argv - '0' + 2); ! 150: update_map++; ! 151: fout = NULL; ! 152: break; ! 153: case 'S': ! 154: case 's': ! 155: ClearMod(map, 0); ! 156: update_map++; ! 157: fout = NULL; ! 158: break; ! 159: case 'C': ! 160: case 'c': ! 161: ClearMod(map, 2); ! 162: update_map++; ! 163: fout = NULL; ! 164: break; ! 165: case 'L': ! 166: case 'l': ! 167: ClearMod(map, 1); ! 168: update_map++; ! 169: fout = NULL; ! 170: break; ! 171: } ! 172: } ! 173: else if (**argv == '+') { ! 174: switch (*++*argv) { ! 175: case '1': ! 176: case '2': ! 177: case '3': ! 178: case '4': ! 179: case '5': ! 180: SetMod(argc, argv, map, **argv - '0' + 2); ! 181: argc--; argv++; ! 182: update_map++; ! 183: fout = NULL; ! 184: break; ! 185: case 'S': ! 186: case 's': ! 187: SetMod(argc, argv, map, 0); ! 188: argc--; argv++; ! 189: update_map++; ! 190: fout = NULL; ! 191: break; ! 192: case 'C': ! 193: case 'c': ! 194: SetMod(argc, argv, map, 2); ! 195: argc--; argv++; ! 196: update_map++; ! 197: fout = NULL; ! 198: break; ! 199: case 'L': ! 200: case 'l': ! 201: SetMod(argc, argv, map, 1); ! 202: argc--; argv++; ! 203: update_map++; ! 204: fout = NULL; ! 205: break; ! 206: } ! 207: } ! 208: } ! 209: } ! 210: ! 211: static char *modType[] = { ! 212: "Shift", ! 213: "Lock", ! 214: "Ctrl", ! 215: "One", ! 216: "Two", ! 217: "Three", ! 218: "Four", ! 219: "Five", ! 220: }; ! 221: ! 222: PrintModifierMapping(map, fout) ! 223: XModifierKeymap *map; ! 224: FILE *fout; ! 225: { ! 226: int i, k = 0; ! 227: ! 228: for (i = 0; i < 8; i++) { ! 229: int j; ! 230: ! 231: fprintf(fout, "%s:", modType[i]); ! 232: for (j = 0; j < map->max_keypermod; j++) { ! 233: if (map->modifiermap[k]) { ! 234: KeySym ks = XKeycodeToKeysym(dpy, map->modifiermap[k], 0); ! 235: char *nm = XKeysymToString(ks); ! 236: ! 237: if (nm) { ! 238: fprintf(fout, "\t%s", nm); ! 239: } else { ! 240: fprintf(fout, "\tBadKey"); ! 241: } ! 242: } ! 243: k++; ! 244: } ! 245: fprintf(fout, "\n"); ! 246: } ! 247: } ! 248: ! 249: main(argc, argv) ! 250: int argc; ! 251: char **argv; ! 252: { ! 253: XModifierKeymap *map; ! 254: ! 255: StartConnectionToServer(argc, argv); ! 256: ! 257: map = XGetModifierMapping(dpy); ! 258: ! 259: DecodeArgs(argc, argv, map); ! 260: ! 261: if (fout) ! 262: PrintModifierMapping(map, fout); ! 263: ! 264: if (update_map) ! 265: UpdateModifierMapping(map); ! 266: } ! 267:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.