~diwic/ubuntu/lucid/pulseaudio/bugfixes

« back to all changes in this revision

Viewing changes to src/modules/module-mmkbd-evdev.c

  • Committer: Bazaar Package Importer
  • Author(s): Sjoerd Simons
  • Date: 2009-07-28 14:00:27 UTC
  • mfrom: (1.5.1 upstream)
  • mto: (1.4.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 65.
  • Revision ID: james.westby@ubuntu.com-20090728140027-wts8ya37tyrh4ww5
Tags: upstream-0.9.16~test2~20090726git59659e1db
ImportĀ upstreamĀ versionĀ 0.9.16~test2~20090726git59659e1db

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
 
53
53
#define DEFAULT_DEVICE "/dev/input/event0"
54
54
 
55
 
/*
56
 
 * This isn't defined in older kernel headers and there is no way of
57
 
 * detecting it.
58
 
 */
59
 
struct _input_id {
60
 
    __u16 bustype;
61
 
    __u16 vendor;
62
 
    __u16 product;
63
 
    __u16 version;
64
 
};
65
 
 
66
55
static const char* const valid_modargs[] = {
67
56
    "device",
68
57
    "sink",
113
102
                    pa_log("Failed to get sink '%s'", u->sink_name);
114
103
                else {
115
104
                    int i;
116
 
                    pa_cvolume cv = *pa_sink_get_volume(s, FALSE);
 
105
                    pa_cvolume cv = *pa_sink_get_volume(s, FALSE, FALSE);
117
106
 
118
107
#define DELTA (PA_VOLUME_NORM/20)
119
108
 
120
109
                    switch (volchange) {
121
110
                        case UP:
122
111
                            for (i = 0; i < cv.channels; i++) {
123
 
                                cv.values[i] += DELTA;
124
 
 
125
 
                                if (cv.values[i] > PA_VOLUME_NORM)
126
 
                                    cv.values[i] = PA_VOLUME_NORM;
 
112
                                if (cv.values[i] < PA_VOLUME_MAX - DELTA)
 
113
                                    cv.values[i] += DELTA;
 
114
                                else
 
115
                                    cv.values[i] = PA_VOLUME_MAX;
127
116
                            }
128
117
 
129
 
                            pa_sink_set_volume(s, &cv, TRUE, TRUE);
 
118
                            pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE, TRUE);
130
119
                            break;
131
120
 
132
121
                        case DOWN:
133
122
                            for (i = 0; i < cv.channels; i++) {
134
 
                                if (cv.values[i] >= DELTA)
 
123
                                if (cv.values[i] > DELTA)
135
124
                                    cv.values[i] -= DELTA;
136
125
                                else
137
126
                                    cv.values[i] = PA_VOLUME_MUTED;
138
127
                            }
139
128
 
140
 
                            pa_sink_set_volume(s, &cv, TRUE, TRUE);
 
129
                            pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE, TRUE);
141
130
                            break;
142
131
 
143
132
                        case MUTE_TOGGLE:
144
133
 
145
 
                            pa_sink_set_mute(s, !pa_sink_get_mute(s, FALSE));
 
134
                            pa_sink_set_mute(s, !pa_sink_get_mute(s, FALSE), TRUE);
146
135
                            break;
147
136
 
148
137
                        case INVALID:
149
 
                            ;
 
138
                            pa_assert_not_reached();
150
139
                    }
151
140
                }
152
141
            }
169
158
    pa_modargs *ma = NULL;
170
159
    struct userdata *u;
171
160
    int version;
172
 
    struct _input_id input_id;
 
161
    struct input_id input_id;
173
162
    char name[256];
174
163
    uint8_t evtype_bitmask[EV_MAX/8 + 1];
175
164
 
180
169
        goto fail;
181
170
    }
182
171
 
183
 
    m->userdata = u = pa_xnew(struct userdata,1);
 
172
    m->userdata = u = pa_xnew(struct userdata, 1);
184
173
    u->module = m;
185
174
    u->io = NULL;
186
175
    u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
187
176
    u->fd = -1;
188
177
    u->fd_type = 0;
189
178
 
190
 
    if ((u->fd = open(pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), O_RDONLY)) < 0) {
191
 
        pa_log("failed to open evdev device: %s", pa_cstrerror(errno));
 
179
    if ((u->fd = open(pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), O_RDONLY|O_NOCTTY)) < 0) {
 
180
        pa_log("Failed to open evdev device: %s", pa_cstrerror(errno));
192
181
        goto fail;
193
182
    }
194
183
 
208
197
                input_id.vendor, input_id.product, input_id.version, input_id.bustype);
209
198
 
210
199
    memset(name, 0, sizeof(name));
211
 
    if(ioctl(u->fd, EVIOCGNAME(sizeof(name)), name) < 0) {
 
200
    if (ioctl(u->fd, EVIOCGNAME(sizeof(name)), name) < 0) {
212
201
        pa_log("EVIOCGNAME failed: %s", pa_cstrerror(errno));
213
202
        goto fail;
214
203
    }