1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2002 Red Hat Inc., Durham, North Carolina.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * All Rights Reserved.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining
7*4882a593Smuzhiyun * a copy of this software and associated documentation files (the
8*4882a593Smuzhiyun * "Software"), to deal in the Software without restriction, including
9*4882a593Smuzhiyun * without limitation on the rights to use, copy, modify, merge,
10*4882a593Smuzhiyun * publish, distribute, sublicense, and/or sell copies of the Software,
11*4882a593Smuzhiyun * and to permit persons to whom the Software is furnished to do so,
12*4882a593Smuzhiyun * subject to the following conditions:
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * The above copyright notice and this permission notice (including the
15*4882a593Smuzhiyun * next paragraph) shall be included in all copies or substantial
16*4882a593Smuzhiyun * portions of the Software.
17*4882a593Smuzhiyun *
18*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19*4882a593Smuzhiyun * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20*4882a593Smuzhiyun * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21*4882a593Smuzhiyun * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22*4882a593Smuzhiyun * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23*4882a593Smuzhiyun * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24*4882a593Smuzhiyun * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25*4882a593Smuzhiyun * SOFTWARE.
26*4882a593Smuzhiyun */
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /*
29*4882a593Smuzhiyun * Authors:
30*4882a593Smuzhiyun * Rickard E. (Rik) Faith <faith@redhat.com>
31*4882a593Smuzhiyun *
32*4882a593Smuzhiyun */
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #include <stdio.h>
35*4882a593Smuzhiyun #include <stdlib.h>
36*4882a593Smuzhiyun #include <X11/Xlib.h>
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun static void
pkc(XKeyboardControl * kc,unsigned long vm)39*4882a593Smuzhiyun pkc(XKeyboardControl * kc, unsigned long vm)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun if (vm & KBKeyClickPercent)
42*4882a593Smuzhiyun printf(" key_click_percent = %d\n", kc->key_click_percent);
43*4882a593Smuzhiyun if (vm & KBBellPercent)
44*4882a593Smuzhiyun printf(" bell_percent = %d\n", kc->bell_percent);
45*4882a593Smuzhiyun if (vm & KBBellPitch)
46*4882a593Smuzhiyun printf(" bell_pitch = %d\n", kc->bell_pitch);
47*4882a593Smuzhiyun if (vm & KBBellDuration)
48*4882a593Smuzhiyun printf(" bell_duration = %d\n", kc->bell_duration);
49*4882a593Smuzhiyun if (vm & KBLed)
50*4882a593Smuzhiyun printf(" led = 0x%x\n", kc->led);
51*4882a593Smuzhiyun if (vm & KBLedMode)
52*4882a593Smuzhiyun printf(" led_mode = %d\n", kc->led_mode);
53*4882a593Smuzhiyun if (vm & KBKey)
54*4882a593Smuzhiyun printf(" key = %d\n", kc->key);
55*4882a593Smuzhiyun if (vm & KBAutoRepeatMode)
56*4882a593Smuzhiyun printf(" auto_repeat_mode = %d\n", kc->auto_repeat_mode);
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun static void
pks(XKeyboardState * ks)60*4882a593Smuzhiyun pks(XKeyboardState * ks)
61*4882a593Smuzhiyun {
62*4882a593Smuzhiyun printf(" key_click_percent = %d\n", ks->key_click_percent);
63*4882a593Smuzhiyun printf(" bell_percent = %d\n", ks->bell_percent);
64*4882a593Smuzhiyun printf(" bell_pitch = %u\n", ks->bell_pitch);
65*4882a593Smuzhiyun printf(" bell_duration = %u\n", ks->bell_duration);
66*4882a593Smuzhiyun printf(" led_mask = 0x%lx\n", ks->led_mask);
67*4882a593Smuzhiyun printf(" global_auto_repeat = %d\n", ks->global_auto_repeat);
68*4882a593Smuzhiyun }
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun int
main(int argc,char ** argv)71*4882a593Smuzhiyun main(int argc, char **argv)
72*4882a593Smuzhiyun {
73*4882a593Smuzhiyun Display *display = XOpenDisplay(NULL);
74*4882a593Smuzhiyun XKeyboardControl kc;
75*4882a593Smuzhiyun XKeyboardState ks;
76*4882a593Smuzhiyun unsigned long vm;
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun if (argc != 5) {
79*4882a593Smuzhiyun printf("Usage: xbell percent baseVolume pitch duration\n");
80*4882a593Smuzhiyun return 1;
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun vm = (KBBellPercent | KBBellPitch | KBBellDuration);
84*4882a593Smuzhiyun kc.key_click_percent = atoi(argv[1]);
85*4882a593Smuzhiyun kc.bell_percent = atoi(argv[2]);
86*4882a593Smuzhiyun kc.bell_pitch = atoi(argv[3]);
87*4882a593Smuzhiyun kc.bell_duration = atoi(argv[4]);
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun printf("Setting:\n");
90*4882a593Smuzhiyun pkc(&kc, vm);
91*4882a593Smuzhiyun XChangeKeyboardControl(display, vm, &kc);
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun printf("Have:\n");
94*4882a593Smuzhiyun XGetKeyboardControl(display, &ks);
95*4882a593Smuzhiyun pks(&ks);
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun XBell(display, 100);
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun XCloseDisplay(display);
100*4882a593Smuzhiyun return 0;
101*4882a593Smuzhiyun }
102