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