aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/dmx/examples/xbell.c
blob: 79419d3243ccbae12761d8cba7cf0c405eefe2a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * Copyright 2002 Red Hat Inc., Durham, North Carolina.
 *
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation on the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/*
 * Authors:
 *   Rickard E. (Rik) Faith <faith@redhat.com>
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>

static void pkc(XKeyboardControl *kc, unsigned long vm)
{
    if (vm&KBKeyClickPercent)
        printf("   key_click_percent  = %d\n", kc->key_click_percent);
    if (vm&KBBellPercent)
        printf("   bell_percent       = %d\n", kc->bell_percent);
    if (vm&KBBellPitch)
        printf("   bell_pitch         = %d\n", kc->bell_pitch);
    if (vm&KBBellDuration)
        printf("   bell_duration      = %d\n", kc->bell_duration);
    if (vm&KBLed)
        printf("   led                = 0x%x\n", kc->led);
    if (vm&KBLedMode)
        printf("   led_mode           = %d\n", kc->led_mode);
    if (vm&KBKey)
        printf("   key                = %d\n", kc->key);
    if (vm&KBAutoRepeatMode)
        printf("   auto_repeat_mode   = %d\n", kc->auto_repeat_mode);
}

static void pks(XKeyboardState *ks)
{
    printf("   key_click_percent  = %d\n", ks->key_click_percent);
    printf("   bell_percent       = %d\n", ks->bell_percent);
    printf("   bell_pitch         = %u\n", ks->bell_pitch);
    printf("   bell_duration      = %u\n", ks->bell_duration);
    printf("   led_mask           = 0x%lx\n", ks->led_mask);
    printf("   global_auto_repeat = %d\n", ks->global_auto_repeat);
}

int main(int argc, char **argv)
{
    Display          *display = XOpenDisplay(NULL);
    XKeyboardControl kc;
    XKeyboardState   ks;
    unsigned long    vm;

    if (argc != 5) {
        printf("Usage: xbell percent baseVolume pitch duration\n");
        return 1;
    }
    
    vm               = (KBBellPercent
                        | KBBellPitch
                        | KBBellDuration);
    kc.key_click_percent = atoi(argv[1]);
    kc.bell_percent  = atoi(argv[2]);
    kc.bell_pitch    = atoi(argv[3]);
    kc.bell_duration = atoi(argv[4]);

    printf("Setting:\n");
    pkc(&kc, vm);
    XChangeKeyboardControl(display, vm, &kc);

    printf("Have:\n");
    XGetKeyboardControl(display, &ks);
    pks(&ks);
    
    XBell(display, 100);
    
    XCloseDisplay(display);
    return 0;
}