|
|
1.1 root 1: /*
2: * $header: xset.c,v 1.18 87/07/11 08:47:46 dkk Locked $
3: * $Locker: $
4: */
5: #include <X11/copyright.h>
6:
7: /* Copyright Massachusetts Institute of Technology 1985 */
8:
9: #ifndef lint
10: static char *rcsid_xset_c = "$Header: xset.c,v 1.22 87/09/12 23:14:10 toddb Exp $";
11: #endif
12:
13: #include <X11/X.h> /* Should be transplanted to X11/Xlibwm.h %*/
14: #include <X11/Xlib.h>
15: /* #include <X11/Xlibwm.h> [Doesn't exist yet 5-14-87] %*/
16: #include <X11/keysym.h>
17: #include <stdio.h>
18: #include <strings.h>
19: #include <ctype.h>
20:
21: #define ON 1
22: #define OFF 0
23:
24: #define DONT_CHANGE -2
25:
26: #define ALL -1
27: #define TIMEOUT 1
28: #define INTERVAL 2
29: #define PREFER_BLANK 3
30: #define ALLOW_EXP 4
31:
32: #define nextarg(i, argv) \
33: argv[i]; \
34: if (i >= argc) \
35: break; \
36:
37: char *progName;
38:
39: main(argc, argv)
40: int argc;
41: char **argv;
42: {
43: register char *arg;
44: register int i;
45: int percent;
46: int acc_num, acc_denom, threshold;
47: XKeyboardControl values;
48: unsigned long pixels[512];
49: caddr_t colors[512];
50: XColor def;
51: int numpixels = 0;
52: char *disp = '\0';
53: Display *dpy;
54: if (argc == 1) usage(argv[0]); /* To be replaced by window-interface */
55: progName = argv[0];
56: for (i = 1; i < argc; ) {
57: arg = argv[i++];
58: if (index(arg, ':')) { /* Set display name if given by user. */
59: disp = arg;
60: }
61: }
62: dpy = XOpenDisplay(disp); /* Open display and check for success */
63: if (dpy == NULL) {
64: fprintf(stderr, "%s: Can't open display '%s'\n",
65: argv[0], XDisplayName(disp ? disp : NULL ));
66: exit(1);
67: }
68: for (i = 1; i < argc; ) {
69: arg = argv[i++];
70: if (index(arg, ':')) { /* Set display name if given by user. */
71: ; /* forget this */
72: } else if (*arg == '-' && *(arg + 1) == 'c'){ /* Does arg start with "-c"? */
73: set_click(dpy, 0); /* If so, turn click off and */
74: }
75: else if (*arg == 'c') { /* Well, does it start with "c", then? */
76: percent = -1; /* Default click volume. */
77: arg = nextarg(i, argv);
78: if (strcmp(arg, "on") == 0) { /* Let click be default. */
79: i++;
80: }
81: else if (strcmp(arg, "off") == 0) {
82: percent = 0; /* Turn it off. */
83: i++;
84: }
85: else if (isnumber(arg, 100)) {
86: percent = atoi(arg); /* Set to spec. volume */
87: i++;
88: }
89: set_click(dpy, percent);
90: }
91: else if (*arg == '-' && *(arg + 1) == 'b') { /* Does arg start w/ "-b" */
92: set_bell_vol(dpy, 0); /* Then turn off bell. */
93: }
94: else if (*arg == 'b') { /* Does it start w/ "b". */
95: percent = -1; /* Set bell to default. */
96: arg = nextarg(i, argv);
97: if (strcmp(arg, "on") == 0) { /* Let it stay that way. */
98: set_bell_vol(dpy, percent);
99: i++;
100: }
101: else if (strcmp(arg, "off") == 0) {
102: percent = 0; /* Turn the bell off. */
103: set_bell_vol(dpy, percent);
104: i++;
105: }
106: else if (isnumber(arg, 100)) { /* If volume is given: */
107: percent = atoi(arg); /* set bell appropriately.*/
108: set_bell_vol(dpy, percent);
109: i++;
110: arg = nextarg(i, argv);
111:
112: if (isnumber(arg, 20000)) { /* If pitch is given: */
113: set_bell_pitch(dpy, atoi(arg)); /* set the bell. */
114: i++;
115:
116: arg = nextarg(i, argv);
117: if (isnumber(arg, 1000)) { /* If duration is given: */
118: set_bell_dur(dpy, atoi(arg)); /* set the bell. */
119: i++;
120: }
121: }
122: }
123: }
124: else if (strcmp(arg, "fp") == 0) { /* set font path */
125: arg = nextarg(i, argv);
126: set_font_path(dpy, arg);
127: i++;
128: }
129: else if (strcmp(arg, "-led") == 0) { /* Turn off one or all LEDs */
130: values.led_mode = OFF;
131: values.led = ALL; /* None specified */
132: arg = nextarg(i, argv);
133: if (isnumber(arg, 32) && atoi(arg) > 0) {
134: values.led = atoi(arg);
135: i++;
136: }
137: set_led(dpy, values.led, values.led_mode);
138: }
139: else if (strcmp(arg, "led") == 0) { /* Turn on one or all LEDs */
140: values.led_mode = ON;
141: values.led = ALL;
142: arg = nextarg(i, argv);
143: if (strcmp(arg, "on") == 0) {
144: i++;
145: }
146: else if (strcmp(arg, "off") == 0) { /* ...except in this case. */
147: values.led_mode = OFF;
148: i++;
149: }
150: else if (isnumber(arg, 32) && atoi(arg) > 0) {
151: values.led = atoi(arg);
152: i++;
153: }
154: set_led(dpy, values.led, values.led_mode);
155: }
156: /* Set pointer (mouse) settings: Acceleration and Threshold. */
157: else if (strcmp(arg, "m") == 0 || strcmp(arg, "mouse") == 0) {
158: acc_num = -1;
159: acc_denom = -1; /* Defaults */
160: threshold = -1;
161: if (i >= argc){
162: set_mouse(dpy, acc_num, acc_denom, threshold);
163: break;
164: }
165: arg = argv[i];
166: if (strcmp(arg, "default") == 0) {
167: i++;
168: }
169: else if (*arg >= '0' && *arg <= '9') {
170: acc_num = atoi(arg); /* Set acceleration to user's tastes. */
171: i++;
172: if (i >= argc) {
173: set_mouse(dpy, acc_num, acc_denom, threshold);
174: break;
175: }
176: arg = argv[i];
177: if (*arg >= '0' && *arg <= '9') {
178: threshold = atoi(arg); /* Set threshold as user specified. */
179: i++;
180: }
181: }
182: set_mouse(dpy, acc_num, acc_denom, threshold);
183: }
184: else if (*arg == 's') { /* If arg starts with "s". */
185: if (i >= argc) {
186: set_saver(dpy, ALL, 0); /* Set everything to default */
187: break;
188: }
189: arg = argv[i];
190: if (strcmp(arg, "blank") == 0) { /* Alter blanking preference. */
191: set_saver(dpy, PREFER_BLANK, PreferBlanking);
192: i++;
193: }
194: else if (strcmp(arg, "noblank") == 0) { /* Ditto. */
195: set_saver(dpy, PREFER_BLANK, DontPreferBlanking);
196: i++;
197: }
198: else if (strcmp(arg, "off") == 0) {
199: set_saver(dpy, TIMEOUT, 0); /* Turn off screen saver. */
200: i++;
201: if (i >= argc)
202: break;
203: arg = argv[i];
204: if (strcmp(arg, "off") == 0) {
205: set_saver(dpy, INTERVAL, 0);
206: i++;
207: }
208: }
209: else if (strcmp(arg, "default") == 0) { /* Leave as default. */
210: set_saver(dpy, ALL, 0);
211: i++;
212: }
213: else if (*arg >= '0' && *arg <= '9') { /* Set as user wishes. */
214: set_saver(dpy, TIMEOUT, atoi(arg));
215: i++;
216: if (i >= argc)
217: break;
218: arg = argv[i];
219: if (*arg >= '0' && *arg <= '9') {
220: set_saver(dpy, INTERVAL, atoi(arg));
221: i++;
222: }
223: }
224: }
225: else if(*arg == '-' && *(arg + 1) == 'r'){ /* If arg starts w/ "-r" */
226: set_repeat(dpy, ALL, OFF);
227: }
228: else if (*arg == 'r') { /* If it starts with "r" */
229: if (i >= argc) {
230: set_repeat(dpy, ALL, ON);
231: break;
232: }
233: arg = argv[i]; /* Check next argument. */
234: if (strcmp(arg, "on") == 0) {
235: set_repeat(dpy, ALL, ON);
236: i++;
237: }
238: else if (strcmp(arg, "off") == 0) {
239: set_repeat(dpy, ALL, OFF);
240: i++;
241: }
242: }
243: else if (*arg == 'p') { /* If arg starts with "p" */
244: if (i + 1 >= argc)
245: usage(argv[0]);
246: arg = argv[i];
247: if (*arg >= '0' && *arg <= '9')
248: pixels[numpixels] = atoi(arg);
249: else
250: usage(argv[0]);
251: i++;
252: colors[numpixels] = argv[i];
253: i++;
254: numpixels++;
255: set_pixels(dpy, pixels, colors, numpixels);
256: }
257: else if (*arg == '-' && *(arg + 1) == 'k') {
258: set_lock(dpy, OFF);
259: }
260: else if (*arg == 'k') { /* Set modifier keys. */
261: set_lock(dpy, ON);
262: }
263: else if (*arg == 'q') { /* Give status to user. */
264: query(dpy);
265: }
266: else
267: usage(argv[0]);
268: }
269:
270: XFlush(dpy);
271:
272: exit(0); /* Done. We can go home now. */
273: }
274:
275:
276: isnumber(arg, maximum)
277: char *arg;
278: int maximum;
279: {
280: register char *p;
281:
282: if (arg[0] == '-' && arg[1] == '1' && arg[2] == '\0')
283: return(1);
284: for (p=arg; isdigit(*p); p++);
285: if (*p || atoi(arg) > maximum)
286: return(0);
287: return(1);
288: }
289:
290: /* These next few functions do the real work (xsetting things).
291: */
292: set_click(dpy, percent)
293: Display *dpy;
294: int percent;
295: {
296: XKeyboardControl values;
297: values.key_click_percent = percent;
298: XChangeKeyboardControl(dpy, KBKeyClickPercent, &values);
299: return;
300: }
301:
302: set_bell_vol(dpy, percent)
303: Display *dpy;
304: int percent;
305: {
306: XKeyboardControl values;
307: values.bell_percent = percent;
308: XChangeKeyboardControl(dpy, KBBellPercent, &values);
309: return;
310: }
311:
312: set_bell_pitch(dpy, pitch)
313: Display *dpy;
314: int pitch;
315: {
316: XKeyboardControl values;
317: values.bell_pitch = pitch;
318: XChangeKeyboardControl(dpy, KBBellPitch, &values);
319: return;
320: }
321:
322: set_bell_dur(dpy, duration)
323: Display *dpy;
324: int duration;
325: {
326: XKeyboardControl values;
327: values.bell_duration = duration;
328: XChangeKeyboardControl(dpy, KBBellDuration, &values);
329: return;
330: }
331:
332: set_font_path(dpy, path)
333: Display *dpy;
334: char *path;
335: {
336: char **directoryList = NULL; int ndirs = 0;
337: char *directories;
338: char *pDir;
339:
340: if (strcmp(path, "default")!=0) {
341: if (((directories = (char *)malloc( strlen(path) )) == NULL) ||
342: ((directoryList = (char **)malloc(sizeof(char *))) == NULL))
343: error( "out of memory" );
344:
345: strcpy( directories, path );
346: *directoryList = pDir = directories;
347: ndirs++;
348: while( (pDir = index(pDir, ',')) != NULL) {
349: *pDir++ = '\0';
350: directoryList = (char **)realloc(directoryList,
351: (ndirs+1)*sizeof(char *));
352: if (directoryList == NULL) error( "out of memory" );
353: directoryList[ndirs++] = pDir;
354: }
355: }
356:
357: XSetFontPath( dpy, directoryList, ndirs );
358: }
359:
360: set_led(dpy, led, led_mode)
361: Display *dpy;
362: int led, led_mode;
363: {
364: XKeyboardControl values;
365: values.led_mode = led_mode;
366: if (led != ALL) {
367: values.led = led;
368: XChangeKeyboardControl(dpy, KBLed | KBLedMode, &values);
369: }
370: else {
371: XChangeKeyboardControl(dpy, KBLedMode, &values);
372: }
373: return;
374: }
375:
376: set_mouse(dpy, acc_num, acc_denom, threshold)
377: Display *dpy;
378: int acc_num, acc_denom, threshold;
379: {
380: int do_accel = True, do_threshold = True;
381: if (acc_num == DONT_CHANGE)
382: do_accel = False;
383: if (threshold == DONT_CHANGE)
384: do_threshold = False;
385: XChangePointerControl(dpy, do_accel, do_threshold, acc_num,
386: acc_denom, threshold);
387: return;
388: }
389:
390: set_saver(dpy, mask, value)
391: Display *dpy;
392: int mask, value;
393: {
394: int timeout, interval, prefer_blank, allow_exp;
395: XGetScreenSaver(dpy, &timeout, &interval, &prefer_blank,
396: &allow_exp);
397: if (mask == TIMEOUT) timeout = value;
398: if (mask == INTERVAL) interval = value;
399: if (mask == PREFER_BLANK) prefer_blank = value;
400: if (mask == ALLOW_EXP) allow_exp = value;
401: if (mask == ALL) { /* "value" is ignored in this case. (defaults) */
402: timeout = -1;
403: interval = -1;
404: prefer_blank = DefaultBlanking;
405: allow_exp = DefaultExposures;
406: }
407: XSetScreenSaver(dpy, timeout, interval, prefer_blank,
408: allow_exp);
409: return;
410: }
411:
412: set_repeat(dpy, key, auto_repeat_mode)
413: Display *dpy;
414: int key, auto_repeat_mode;
415: {
416: XKeyboardControl values;
417: values.auto_repeat_mode = auto_repeat_mode;
418: if (key != ALL) {
419: values.key = key;
420: XChangeKeyboardControl(dpy, KBKey | KBAutoRepeatMode, &values);
421: }
422: else {
423: XChangeKeyboardControl(dpy, KBAutoRepeatMode, &values);
424: }
425: return;
426: }
427:
428: set_pixels(dpy, pixels, colors, numpixels)
429: Display *dpy;
430: unsigned long pixels[512];
431: caddr_t colors[512];
432: int numpixels;
433: {
434: char *spec; /*%%%%%*/
435: XColor def;
436: if(DisplayCells(dpy, DefaultScreen(dpy)) >= 2) {
437: while (--numpixels >= 0) {
438: def.pixel = pixels[numpixels];
439: if (XParseColor(dpy, colors[numpixels], spec, &def))
440: XStoreColor(&def);
441: else
442: fprintf(stderr, "%s: No such color\n", colors[numpixels]);
443: }
444: }
445: return;
446: }
447:
448: set_lock(dpy, onoff)
449: Display *dpy;
450: Bool onoff;
451: {
452: XModifierKeymap *mods;
453: mods = XGetModifierMapping(dpy);
454:
455: if (onoff)
456: mods = XInsertModifiermapEntry(mods, XK_Caps_Lock, LockMapIndex);
457: else
458: mods = XDeleteModifiermapEntry(mods, XK_Caps_Lock, LockMapIndex);
459: XSetModifierMapping(dpy, mods);
460: return;
461: }
462:
463: /* This is the information-getting function for telling the user what the
464: * current "xsettings" are.
465: */
466: query(dpy)
467: Display *dpy;
468: {
469: XKeyboardState values;
470: int acc_num, acc_denom, threshold;
471: int timeout, interval, prefer_blank, allow_exp;
472: char **font_path; int npaths;
473:
474: XGetKeyboardControl(dpy, &values);
475: XGetPointerControl(dpy, &acc_num, &acc_denom, &threshold);
476: XGetScreenSaver(dpy, &timeout, &interval, &prefer_blank, &allow_exp);
477: font_path = XGetFontPath(dpy, &npaths);
478:
479: printf ("Keyboard Control Values:\n");
480: /*printf ("Auto Repeat: %d \t\t", values.auto_repeat_mode); %%*/
481: /*printf ("Key: %d \n\n", values.key); %%*/
482: printf ("Key Click Volume (%%): %d \n", values.key_click_percent);
483: printf ("Bell Volume (%%): %d \t", values.bell_percent);
484: printf ("Bell Pitch (Hz): %d \t", values.bell_pitch);
485: printf ("Bell Duration (msec): %d \n", values.bell_duration);
486: /*printf ("LED: %d \t\t\t", values.led);
487: printf ("LED Mode: %o \t\t", values.led_mode); %%*/
488:
489: printf ("Pointer (Mouse) Control Values:\n");
490: printf ("Acceleration: %d \t", acc_num / acc_denom);
491: printf ("Threshold: %d \n", threshold);
492: printf ("Screen Saver: (yes = %d, no = %d, default = %d)\n",
493: PreferBlanking, DontPreferBlanking, DefaultBlanking);
494: printf ("Prefer Blanking: %d \t", prefer_blank);
495: printf ("Time-out: %d \t Cycle: %d\n", timeout, interval);
496: if (npaths) {
497: printf( "Font Path: %s", *font_path++ );
498: for( --npaths; npaths; npaths-- )
499: printf( ",%s", *font_path++ );
500: printf( "\n" );
501: }
502: return;
503: }
504:
505:
506: /* This is the usage function */
507:
508: usage(prog)
509: char *prog;
510: {
511: printf("usage: %s option [option ...] [host:vs]\n", prog);
512: printf(" To turn bell off:\n");
513: printf("\t-b b off b 0\n");
514: printf(" To set bell volume, pitch and duration:\n");
515: printf("\t b [vol [pitch [dur]]] b on\n");
516: printf(" To turn keyclick off:\n");
517: printf("\t-c c off c 0\n");
518: printf(" To set keyclick volume:\n");
519: printf("\t c [0-100] c on\n");
520: printf(" To set the font path:\n" );
521: printf("\t fp path[,path...]\n" );
522: printf(" To restore the default font path:\n" );
523: printf("\t fp default\n" );
524: printf(" To set LED states off or on:\n");
525: printf("\t-led [1-32] led off\n");
526: printf("\t led [1-32] led on\n");
527: printf(" To set mouse acceleration and threshold:\n");
528: printf("\t m [acc [thr]] m default\n");
529: printf(" To set pixel colors:\n");
530: printf("\t p pixel_value color_name\n");
531: printf(" To turn auto-repeat off or on:\n");
532: printf("\t-r r off r r on\n");
533: printf(" For screen-saver control:\n");
534: printf("\t s [timeout [cycle]] s default\n");
535: printf("\t s blank s noblank\n");
536: printf(" For status information: q or query\n");
537: exit(0);
538: }
539:
540: error( message )
541: char *message;
542: {
543: fprintf( stderr, "%s: %s\n", progName, message );
544: exit( 1 );
545: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.