wmclockmon: update change-log
[dockapps.git] / ascd / ascd / mixer_handlers.c
blob5f8f94de66ef04933ed8abbcbdba878246e5a379
1 /* ===========================================================================
2 * AScd: mixer_handlers.c
3 * mouse events <-> integrated commands with mixer module
4 * ===========================================================================
5 * Copyright (c) 1999 Denis Bourez and Rob Malda. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Denis Bourez & Rob Malda
19 * 4. Neither the name of the author nor the names of any co-contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY DENIS BOUREZ AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL DENIS BOUREZ, ROB MALDA OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 * ===========================================================================
37 #include "ext.h"
39 #ifdef MIXER
41 int check_mixer()
43 int fd;
44 if ((fd = open(mixer_device,0))) {
45 close(fd);
46 } else {
47 return FALSE;
49 return TRUE;
52 int getvol(int control)
54 int fd;
55 int status = 0;
57 if (mixer_ok) {
58 if ((fd = open(mixer_device,0))) {
59 ioctl(fd, MIXER_READ(control), &mixer_vol);
60 mixer_vol = mixer_vol >> 8;
61 close(fd);
62 return mixer_vol;
65 return 0;
68 void setvol(int control, int setto, int maximum)
70 int fd;
72 if (setto > maximum) setto = maximum;
73 if (setto < 0) setto = 0;
75 if ((fd = open(mixer_device, 0))) {
76 mixer_vol = ((float)setto / (float)maximum) * 100;
77 mixer_old = mixer_vol << 8;
78 mixer_vol = mixer_old | mixer_vol;
79 ioctl(fd, MIXER_WRITE(control), &mixer_vol);
80 close(fd);
84 void mixer_event_handle(int event, XEvent Event)
86 int value;
88 if (!mixer_ok) return;
90 switch (event) {
91 case FAK_MIXER_SET:
92 if ((thdata[but_current].xpm.attributes.width > 0) && (max_volume > 0)) {
93 if (thdata[but_current].type == FAK_MIXER_BAR) {
94 value = (int)((float)(Event.xbutton.x - thdata[but_current].x) / (float)thdata[but_current].xpm.attributes.width * 100.0);
95 } else if (thdata[but_current].type == FAK_VMIXER_BAR) {
96 value = (int)((float)(Event.xbutton.y - thdata[but_current].y) / (float)thdata[but_current].xpm.attributes.height * 100.0);
97 } else {
98 value = (int)((float)(Event.xbutton.y - thdata[but_current].y) / (float)thdata[but_current].xpm.attributes.height * 100.0);
99 value = 100 - value;
101 setvol(thdata[but_current].arg, value, 100);
102 redraw = TRUE;
103 fak_redraw();
105 break;
106 case FAK_MIXER_0:
107 setvol(thdata[but_current].arg, 0, 100);
108 redraw = TRUE;
109 fak_redraw();
110 break;
111 case FAK_MIXER_50:
112 setvol(thdata[but_current].arg, 50, 100);
113 redraw = TRUE;
114 fak_redraw();
115 break;
116 case FAK_MIXER_75:
117 setvol(thdata[but_current].arg, 75, 100);
118 redraw = TRUE;
119 fak_redraw();
120 break;
121 case FAK_MIXER_100:
122 setvol(thdata[but_current].arg, 100, 100);
123 redraw = TRUE;
124 fak_redraw();
125 break;
126 default:
127 break;
130 redraw = TRUE;
131 fak_singlemask(but_current);
134 #endif