summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile14
-rw-r--r--fdi/11-multitouch.fdi40
-rw-r--r--src/dbus-abi.h34
-rw-r--r--src/glib-abi.h19
-rw-r--r--src/hal-abi.h28
-rw-r--r--src/multitouch.c364
6 files changed, 173 insertions, 326 deletions
diff --git a/Makefile b/Makefile
index c387266..b8c7ec6 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ MODULES = src
4 4
5o_src = multitouch 5o_src = multitouch
6 6
7TARGETS = $(addsuffix /test,$(MODULES)) 7TARGETS = #$(addsuffix /test,$(MODULES))
8 8
9OBJECTS = $(addsuffix .o,\ 9OBJECTS = $(addsuffix .o,\
10 $(foreach mod,$(MODULES),\ 10 $(foreach mod,$(MODULES),\
@@ -15,12 +15,12 @@ TLIB = $(addprefix obj/,$(LIBRARY))
15TOBJ = $(addprefix obj/,$(addsuffix .o,$(TARGETS))) 15TOBJ = $(addprefix obj/,$(addsuffix .o,$(TARGETS)))
16TFDI = $(addprefix fdi/,$(FDIS)) 16TFDI = $(addprefix fdi/,$(FDIS))
17OBJS = $(addprefix obj/,$(OBJECTS)) 17OBJS = $(addprefix obj/,$(OBJECTS))
18LIBS = #-lhal -ldbus-glib-1 18LIBS = -lX11 -lpixman-1
19 19
20DLIB = usr/lib/xorg/modules/input 20DLIB = usr/lib/xorg/modules/input
21DFDI = usr/share/hal/fdi/policy/20thirdparty 21DFDI = usr/share/hal/fdi/policy/20thirdparty
22 22
23INCLUDE = -I. 23INCLUDE = -I. -I/usr/include/xorg -I/usr/include/pixman-1
24OPTS = -O3 24OPTS = -O3
25 25
26.PHONY: all clean 26.PHONY: all clean
@@ -30,7 +30,7 @@ all: $(OBJS) $(TLIB) $(TOBJ) $(TBIN)
30 30
31bin/%: obj/%.o 31bin/%: obj/%.o
32 @mkdir -p $(@D) 32 @mkdir -p $(@D)
33 gcc $(INCLUDE) $(OPTS) $< $(TLIB) $(LIBS) -o $@ 33 gcc $< $(TLIB) $(LIBS) -o $@
34 34
35$(TLIB): $(OBJS) 35$(TLIB): $(OBJS)
36 @rm -f $(TLIB) 36 @rm -f $(TLIB)
@@ -38,11 +38,11 @@ $(TLIB): $(OBJS)
38 38
39obj/%.o: %.c 39obj/%.o: %.c
40 @mkdir -p $(@D) 40 @mkdir -p $(@D)
41 gcc -c $< -o $@ 41 gcc $(INCLUDE) $(OPTS) -c $< -o $@
42 42
43obj/%.o: %.cc 43obj/%.o: %.cc
44 @mkdir -p $(@D) 44 @mkdir -p $(@D)
45 gcc -c $< -o $@ 45 gcc $(INCLUDE) $(OPTS) -c $< -o $@
46 46
47clean: 47clean:
48 rm -rf bin obj 48 rm -rf bin obj
@@ -53,5 +53,5 @@ distclean: clean
53install: $(TLIB) $(TFDI) 53install: $(TLIB) $(TFDI)
54 install -d "$(DESTDIR)/$(DLIB)" 54 install -d "$(DESTDIR)/$(DLIB)"
55 install -d "$(DESTDIR)/$(DFDI)" 55 install -d "$(DESTDIR)/$(DFDI)"
56 install -m 755 $(TBIN) "$(DESTDIR)/$(DLIB)" 56 install -m 755 $(TLIB) "$(DESTDIR)/$(DLIB)"
57 install -m 644 $(TFDI) "$(DESTDIR)/$(DFDI)" 57 install -m 644 $(TFDI) "$(DESTDIR)/$(DFDI)"
diff --git a/fdi/11-multitouch.fdi b/fdi/11-multitouch.fdi
index 1c82a22..215b866 100644
--- a/fdi/11-multitouch.fdi
+++ b/fdi/11-multitouch.fdi
@@ -1,40 +1,10 @@
1<?xml version="1.0" encoding="UTF-8"?> 1<?xml version="1.0" encoding="ISO-8859-1"?>
2
3<deviceinfo version="0.2"> 2<deviceinfo version="0.2">
4
5 <device> 3 <device>
6 <match key="platform.id" contains="applesmc"> 4 <match key="info.capabilities" contains="input.touchpad">
7 <spawn udi="/org/freedesktop/Hal/devices/applesmc_keyboard_backlight"/> 5 <match key="info.product" contains="bcm5974">
8<!-- 6 <merge key="input.x11_driver" type="string">multitouch</merge>
9 <spawn udi="/org/freedesktop/Hal/devices/applesmc_light_sensor"/> 7 </match>
10-->
11 </match> 8 </match>
12 </device> 9 </device>
13
14 <device>
15 <match key="info.udi" string="/org/freedesktop/Hal/devices/applesmc_keyboard_backlight">
16 <append key="info.capabilities" type="strlist">keyboard_backlight</append>
17 <merge key="info.product" type="string">Applesmc Keyboard Backlight</merge>
18 <merge key="keyboard_backlight.num_levels" type="int">256</merge>
19 <merge key="keyboard_backlight.access_method" type="string">custom</merge>
20 <merge key="linux.sysfs_path" type="string">/sys/class/leds/smc::kbd_backlight</merge>
21 <append key="info.addons" type="strlist">hald-addon-generic-kbd-backlight</append>
22 </match>
23 </device>
24
25<!--
26 <device>
27 <match key="info.udi" string="/org/freedesktop/Hal/devices/applesmc_light_sensor">
28 <append key="info.capabilities" type="strlist">light_sensor</append>
29 <merge key="info.product" type="string">Applesmc Light Sensor</merge>
30 <merge key="light_sensor.num_sensors" type="int">1</merge>
31 <merge key="light_sensor.num_levels" type="int">64</merge>
32 <append key="light_sensor.sensor_locations" type="strlist">left</append>
33 <merge key="light_sensor.access_method" type="string">custom</merge>
34 <merge key="linux.sysfs_path" type="string">/sys/devices/platform/applesmc.768/light</merge>
35 <append key="info.addons" type="strlist">hald-addon-generic-light-sensor</append>
36 </match>
37 </device>
38-->
39
40</deviceinfo> 10</deviceinfo>
diff --git a/src/dbus-abi.h b/src/dbus-abi.h
deleted file mode 100644
index ed406f1..0000000
--- a/src/dbus-abi.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/*
2 * DBUS ABI
3 *
4 * The following is all dbus information needed in order to compile
5 * a hald-addon.
6 */
7
8/* Structure declarations */
9struct DBusMessage;
10
11/* Allocate 32 bytes for the error structure. */
12struct DBusError {
13 char bytes[32];
14};
15
16/* Define DBus arguments types */
17const int DBUS_TYPE_INVALID;
18const int DBUS_TYPE_INT32 = 'i';
19const int DBUS_TYPE_ARRAY = 'a';
20
21/* Define DBus handler results */
22typedef enum {
23 DBUS_HANDLER_RESULT_HANDLED,
24 DBUS_HANDLER_RESULT_NOT_YET_HANDLED,
25 DBUS_HANDLER_RESULT_NEED_MEMORY
26} DBusHandlerResult;
27
28/* Function declarations */
29struct DBusMessage *
30dbus_message_new_error(struct DBusMessage *reply_to, const char *error_name,
31 const char *error_message);
32struct DBusMessage *
33dbus_message_new_method_return(struct DBusMessage *method_call);
34
diff --git a/src/glib-abi.h b/src/glib-abi.h
deleted file mode 100644
index 62b85d5..0000000
--- a/src/glib-abi.h
+++ /dev/null
@@ -1,19 +0,0 @@
1/*
2 * GLIB ABI
3 *
4 * The following is all glib information needed in order to compile
5 * a hald-addon.
6 */
7
8/* logical values */
9const int TRUE = 1;
10const int FALSE;
11
12/* Structure declarations */
13struct GMainContext;
14struct GMainLoop;
15
16/* Function declarations */
17struct GMainLoop *g_main_loop_new(struct GMainContext *context, int is_running);
18void g_main_loop_run(struct GMainLoop *loop);
19
diff --git a/src/hal-abi.h b/src/hal-abi.h
deleted file mode 100644
index 277580f..0000000
--- a/src/hal-abi.h
+++ /dev/null
@@ -1,28 +0,0 @@
1/*
2 * HAL ABI
3 *
4 * The following is all hal information needed in order to compile
5 * a hald-addon.
6 */
7
8/* Structure declarations */
9struct LibHalContext;
10struct DBusConnection;
11
12/* Simple error handling */
13#define setup_logger()
14#define eprintf(...) (fprintf(stderr, __VA_ARGS__), fprintf(stderr, "\n"))
15#define WARNING(...) eprintf("addon-warning: " __VA_ARGS__)
16#define DEBUG(...) eprintf("addon-debug: " __VA_ARGS__)
17#define ERROR(...) eprintf("addon-error: " __VA_ARGS__)
18#define HAL_WARNING(x) WARNING x
19#define HAL_DEBUG(x) DEBUG x
20#define HAL_ERROR(x) ERROR x
21
22/* Function declarations */
23struct LibHalContext *
24libhal_ctx_init_direct(struct DBusError *error);
25
26struct DBusConnection *
27libhal_ctx_get_dbus_connection(struct LibHalContext *ctx);
28
diff --git a/src/multitouch.c b/src/multitouch.c
index 537ab69..2c9b98a 100644
--- a/src/multitouch.c
+++ b/src/multitouch.c
@@ -1,11 +1,8 @@
1/*************************************************************************** 1/***************************************************************************
2 * 2 *
3 * addon-generic-kbd-backlight.c: 3 * Multitouch X driver
4 * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se> 4 * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
5 * 5 *
6 * Based on addon-generic-backlight.c:
7 * Copyright (C) 2008 Danny Kukawka <danny.kukawka@web.de>
8 *
9 * Licensed under the Academic Free License version 2.1 6 * Licensed under the Academic Free License version 2.1
10 * 7 *
11 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
@@ -24,218 +21,179 @@
24 * 21 *
25 **************************************************************************/ 22 **************************************************************************/
26 23
27#include <string.h> 24#include "xorg-server.h"
28#include <sys/types.h> 25#include <xf86.h>
29#include <sys/stat.h> 26#include <xf86_OSproc.h>
30#include <fcntl.h> 27#include <xf86Xinput.h>
31#include <unistd.h> 28#include <exevents.h>
32#include <stdio.h> 29#include <linux/input.h>
33#include <stdlib.h> 30
34 31////////////////////////////////////////////////////////////////////////////
35#include "glib-abi.h" 32
36#include "dbus-abi.h" 33//#define BTN_MT_RAW_DATA 0x210 /* multitouch device */
37#include "hal-abi.h" 34#define BTN_TOOL_PRESS 0x148 /* The trackpad is a physical button */
38 35#define BTN_MT_RAW_DATA 0x14b /* multitouch device */
39#define HAL_PROPERTY "org.freedesktop.Hal.Device.KeyboardBacklight" 36#define BTN_MT_RAW_FINGER 0x14c /* multitouch device */
40 37#define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */
41static const char prop_name[] = HAL_PROPERTY; 38
42static const char prop_invalid[] = HAL_PROPERTY ".Invalid"; 39#define ABS_MT_TOUCH 0x30
43static const char prop_set[] = "SetBrightness"; 40#define ABS_MT_TOUCH_MAJOR 0x30
44static const char prop_get[] = "GetBrightness"; 41#define ABS_MT_TOUCH_MINOR 0x31
45 42#define ABS_MT_WIDTH 0x32
46static struct GMainLoop *main_loop; 43#define ABS_MT_WIDTH_MAJOR 0x32
47static struct LibHalContext *halctx; 44#define ABS_MT_WIDTH_MINOR 0x33
48static struct DBusConnection *conn; 45#define ABS_MT_ORIENTATION 0x34
49 46#define ABS_MT_POSITION_X 0x35
50static char sysfs_path[512]; 47#define ABS_MT_POSITION_Y 0x36
51static int levels; 48
52 49typedef int bool;
53/** 50
54 * Get keyboard backlight level 51#define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "")
55 * 52
56 * Tries to read from the specified sysfs device, and if successful, 53////////////////////////////////////////////////////////////////////////////
57 * updates the internal keyboard backlight state. Warns if the device 54
58 * cannot be opened or be read from. Always returns the last succesful 55struct Capabilities {
59 * read. 56 bool has_left, has_middle;
60 */ 57 bool has_right, has_mtdata;
61static int get_kbd_backlight() 58 bool has_touch_major, has_touch_minor;
59 bool has_width_major, has_width_minor;
60 bool has_orientation, has_dummy;
61 bool has_position_x, has_position_y;
62 struct input_absinfo abs_touch_major;
63 struct input_absinfo abs_touch_minor;
64 struct input_absinfo abs_width_major;
65 struct input_absinfo abs_width_minor;
66 struct input_absinfo abs_orientation;
67 struct input_absinfo abs_position_x;
68 struct input_absinfo abs_position_y;
69};
70
71////////////////////////////////////////////////////////////////////////////
72
73static int read_capabilities(struct Capabilities *cap, int fd)
62{ 74{
63 static int level; 75 unsigned long evbits[NBITS(EV_MAX)];
64 int fd; 76 unsigned long absbits[NBITS(ABS_MAX)];
65 char buf[64]; 77 unsigned long keybits[NBITS(KEY_MAX)];
66 78 int rc;
67 fd = open(sysfs_path, O_RDONLY); 79
68 if (fd < 0) { 80 memset(cap, 0, sizeof(struct Capabilities));
69 HAL_WARNING(("Could not open '%s'", sysfs_path)); 81
70 return level; 82 SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_SYN, sizeof(evbits)), evbits));
71 } 83 if (rc < 0)
72 84 return rc;
73 memset(buf, 0, sizeof(buf)); 85 SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits));
74 if (read(fd, buf, sizeof(buf)) < 0) 86 if (rc < 0)
75 HAL_WARNING(("Could not read from '%s'", sysfs_path)); 87 return rc;
76 else 88 SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits));
77 level = atoi(buf); 89 if (rc < 0)
78 90 return rc;
79 close(fd); 91
80 return level; 92 cap->has_left = TEST_BIT(BTN_LEFT, keybits);
93 cap->has_middle = TEST_BIT(BTN_MIDDLE, keybits);
94 cap->has_right = TEST_BIT(BTN_RIGHT, keybits);
95 cap->has_mtdata = TEST_BIT(BTN_MT_RAW_DATA, keybits);
96
97 SYSCALL(rc = ioctl(fd, EVIOCGABS(ABS_MT_TOUCH_MAJOR),
98 &cap->abs_touch_major));
99 cap->has_touch_major = rc >= 0;
81} 100}
82 101
83/** 102static int output_capabilities(const struct Capabilities *cap)
84 * Set keyboard backlight level
85 *
86 * Warns if the device cannot be opened or be written to.
87 * Returns bytes written on success, negative value on failure.
88 */
89static int set_kbd_backlight(int level)
90{ 103{
91 int fd, ret; 104 char line[1024];
92 char buf[64]; 105 ADDCAP(line, cap, left);
93 106 ADDCAP(line, cap, middle);
94 sprintf(buf, "%d", level); 107 ADDCAP(line, cap, right);
95 108 ADDCAP(line, cap, mtdata);
96 fd = open(sysfs_path, O_WRONLY); 109 ADDCAP(line, cap, touch_major);
97 if (fd < 0) { 110 ADDCAP(line, cap, touch_minor);
98 HAL_WARNING(("Could not open '%s'", sysfs_path)); 111 ADDCAP(line, cap, width_major);
99 return -1; 112 ADDCAP(line, cap, width_minor);
100 } 113 ADDCAP(line, cap, orientation);
101 114 ADDCAP(line, cap, position_x);
102 ret = write(fd, buf, strlen(buf)); 115 ADDCAP(line, cap, position_y);
103 if (ret < 0) 116 xf86Msg(X_INFO, "multitouch: caps:%s\n", line);
104 HAL_WARNING(("Could not write '%s' to '%s'", buf, sysfs_path));
105
106 close(fd);
107 return ret;
108} 117}
109 118
110/* DBus set keyboard backlight level */ 119static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags)
111static struct DBusMessage *dbus_get_kbd_backlight(struct DBusMessage *msg)
112{ 120{
113 struct DBusError err; 121 InputInfoPtr local = xf86AllocateInput(drv, 0);
114 struct DBusMessage *reply; 122 if (!local)
115 int level; 123 goto error;
116 124
117 dbus_error_init(&err); 125 local->name = dev->identifier;
118 if (!dbus_message_get_args(msg, &err, DBUS_TYPE_INVALID)) 126 local->type_name = XI_TOUCHPAD;
119 return dbus_message_new_error(msg, prop_invalid, 127 local->device_control = 0;//DeviceControl;
120 "Invalid message"); 128 local->read_input = 0;//ReadInput;
121 129 local->control_proc = 0;//ControlProc;
122 level = get_kbd_backlight(); 130 local->close_proc = 0;//CloseProc;
123 131 local->switch_mode = 0;//SwitchMode;
124 reply = dbus_message_new_method_return(msg); 132 local->conversion_proc = 0;//ConvertProc;
125 if (reply) 133 local->reverse_conversion_proc = NULL;
126 dbus_message_append_args(reply, DBUS_TYPE_INT32, &level, 134 local->dev = NULL;
127 DBUS_TYPE_INVALID); 135 local->private = 0;//priv;
128 136 local->private_flags = 0;
129 return reply; 137 local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
138 local->conf_idev = dev;
139 //local->motion_history_proc = xf86GetMotionEvents;
140 //local->history_size = 0;
141 local->always_core_feedback = 0;
142
143 xf86CollectInputOptions(local, NULL, NULL);
144 xf86OptionListReport(local->options);
145
146 local->fd = xf86OpenSerial(local->options);
147 if (local->fd < 0) {
148 xf86Msg(X_ERROR, "multitouch: cannot open device\n");
149 goto error;
150 }
151 struct Capabilities cap;
152 read_capabilities(&cap, local->fd);
153 output_capabilities(&cap);
154 xf86CloseSerial(local->fd);
155 local->fd = -1;
156 local->flags |= XI86_CONFIGURED;
157 error:
158 return local;
130} 159}
131 160
132/* DBus set keyboard backlight level */ 161static void uninit(InputDriverPtr drv, InputInfoPtr local, int flags)
133static struct DBusMessage *dbus_set_kbd_backlight(struct DBusMessage *msg)
134{ 162{
135 struct DBusError err; 163 xf86DeleteInput(local, 0);
136 int level;
137
138 dbus_error_init(&err);
139 if (!dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &level,
140 DBUS_TYPE_INVALID))
141 return dbus_message_new_error(msg, prop_invalid,
142 "Brightness level argument missing");
143
144 if (level < 0 || level > levels - 1)
145 return dbus_message_new_error(msg, prop_invalid,
146 "Brightness level is invalid");
147
148 set_kbd_backlight(level);
149
150 return dbus_message_new_method_return(msg);
151} 164}
152 165
153/* DBus filter function */ 166////////////////////////////////////////////////////////////////////////////
154static DBusHandlerResult filter_function(struct DBusConnection *connection, 167
155 struct DBusMessage *message, 168static InputDriverRec MULTITOUCH = {
156 void *userdata) 169 1,
170 "multitouch",
171 NULL,
172 preinit,
173 uninit,
174 NULL,
175 0
176};
177
178static XF86ModuleVersionInfo VERSION = {
179 "multitouch",
180 MODULEVENDORSTRING,
181 MODINFOSTRING1,
182 MODINFOSTRING2,
183 XORG_VERSION_CURRENT,
184 0, 1, 0,
185 ABI_CLASS_XINPUT,
186 ABI_XINPUT_VERSION,
187 MOD_CLASS_XINPUT,
188 {0, 0, 0, 0}
189};
190
191static pointer setup(pointer module, pointer options, int *errmaj, int *errmin)
157{ 192{
158 struct DBusMessage *reply = NULL; 193 xf86AddInputDriver(&MULTITOUCH, module, 0);
159 194 return module;
160 if (dbus_message_is_method_call(message, prop_name, prop_get))
161 reply = dbus_get_kbd_backlight(message);
162 else if (dbus_message_is_method_call(message, prop_name, prop_set))
163 reply = dbus_set_kbd_backlight(message);
164
165 if (reply) {
166 dbus_connection_send(connection, reply, NULL);
167 dbus_message_unref(reply);
168 }
169
170 return DBUS_HANDLER_RESULT_HANDLED;
171} 195}
172 196
173int main(int argc, char *argv[]) 197XF86ModuleData multitouchModuleData = {&VERSION, &setup, NULL };
174{
175 struct DBusError err;
176 struct stat fs;
177
178 char *udi = getenv("UDI");
179 char *path = getenv("HAL_PROP_LINUX_SYSFS_PATH");
180 char *level_str = getenv("HAL_PROP_KEYBOARD_BACKLIGHT_NUM_LEVELS");
181
182 setup_logger();
183
184 if (udi == NULL) {
185 HAL_ERROR(("No device specified"));
186 return -2;
187 }
188 if (path == NULL) {
189 HAL_ERROR(("No sysfs path specified"));
190 return -2;
191 }
192 if (level_str == NULL) {
193 HAL_ERROR(("No keyboard_backlight.num_levels defined"));
194 return -2;
195 }
196
197 levels = atoi(level_str);
198 snprintf(sysfs_path, sizeof(sysfs_path), "%s/brightness", path);
199
200 HAL_DEBUG(("udi='%s', path='%s', levels='%d'", udi, path, levels));
201
202 if (stat(sysfs_path, &fs)) {
203 HAL_ERROR(("The sysfs property path does not exist"));
204 return -2;
205 }
206
207 dbus_error_init(&err);
208 halctx = libhal_ctx_init_direct(&err);
209
210 if (halctx == NULL) {
211 HAL_ERROR(("Cannot connect to hald"));
212 return -3;
213 }
214
215 conn = libhal_ctx_get_dbus_connection(halctx);
216 dbus_connection_setup_with_g_main(conn, NULL);
217
218 dbus_connection_add_filter(conn, filter_function, NULL, NULL);
219
220 if (!libhal_device_claim_interface(halctx, udi, prop_name,
221 " <method name=\"GetBrightness\">\n"
222 " <arg name=\"brightness_value\" direction=\"out\" type=\"i\"/>\n"
223 " </method>\n"
224 " <method name=\"SetBrightness\">\n"
225 " <arg name=\"brightness_value\" direction=\"in\" type=\"i\"/>\n"
226 " </method>\n",
227 &err)) {
228 HAL_ERROR(("Cannot claim interface '" HAL_PROPERTY "'"));
229 return -4;
230 }
231
232 dbus_error_init(&err);
233 if (!libhal_device_addon_is_ready(halctx, udi, &err))
234 return -4;
235
236 main_loop = g_main_loop_new(NULL, FALSE);
237 g_main_loop_run(main_loop);
238
239 return 0;
240}
241 198
199////////////////////////////////////////////////////////////////////////////