13 #include <linux/sysctl.h>
14 #include <linux/input.h>
15 #include <linux/module.h>
16 #include <linux/slab.h>
20 static int mouse_emulate_buttons;
24 static struct input_dev *mac_hid_emumouse_dev;
28 static int mac_hid_create_emumouse(
void)
34 mac_hid_emumouse_dev = input_allocate_device();
35 if (!mac_hid_emumouse_dev)
39 &mac_hid_emumouse_dev_event_class);
41 &mac_hid_emumouse_dev_mutex_class);
43 mac_hid_emumouse_dev->name =
"Macintosh mouse button emulation";
44 mac_hid_emumouse_dev->id.bustype =
BUS_ADB;
45 mac_hid_emumouse_dev->id.vendor = 0x0001;
46 mac_hid_emumouse_dev->id.product = 0x0001;
47 mac_hid_emumouse_dev->id.version = 0x0100;
54 err = input_register_device(mac_hid_emumouse_dev);
56 input_free_device(mac_hid_emumouse_dev);
57 mac_hid_emumouse_dev =
NULL;
64 static void mac_hid_destroy_emumouse(
void)
66 input_unregister_device(mac_hid_emumouse_dev);
67 mac_hid_emumouse_dev =
NULL;
70 static bool mac_hid_emumouse_filter(
struct input_handle *
handle,
71 unsigned int type,
unsigned int code,
79 if (code == mouse_button2_keycode)
81 else if (code == mouse_button3_keycode)
86 input_report_key(mac_hid_emumouse_dev, btn, value);
87 input_sync(mac_hid_emumouse_dev);
92 static int mac_hid_emumouse_connect(
struct input_handler *handler,
93 struct input_dev *
dev,
96 struct input_handle *
handle;
100 if (dev == mac_hid_emumouse_dev)
103 handle = kzalloc(
sizeof(
struct input_handle),
GFP_KERNEL);
108 handle->handler = handler;
109 handle->name =
"mac-button-emul";
111 error = input_register_handle(handle);
114 "mac_hid: Failed to register button emulation handle, "
115 "error %d\n", error);
119 error = input_open_device(handle);
122 "mac_hid: Failed to open input device, error %d\n",
130 input_unregister_handle(handle);
136 static void mac_hid_emumouse_disconnect(
struct input_handle *handle)
138 input_close_device(handle);
139 input_unregister_handle(handle);
153 static struct input_handler mac_hid_emumouse_handler = {
154 .filter = mac_hid_emumouse_filter,
155 .connect = mac_hid_emumouse_connect,
156 .disconnect = mac_hid_emumouse_disconnect,
157 .name =
"mac-button-emul",
158 .id_table = mac_hid_emumouse_ids,
161 static int mac_hid_start_emulation(
void)
165 err = mac_hid_create_emumouse();
169 err = input_register_handler(&mac_hid_emumouse_handler);
171 mac_hid_destroy_emumouse();
178 static void mac_hid_stop_emulation(
void)
180 input_unregister_handler(&mac_hid_emumouse_handler);
181 mac_hid_destroy_emumouse();
185 void __user *
buffer,
size_t *lenp,
188 int *valp = table->
data;
198 if (rc == 0 && write && *valp != old_val) {
200 rc = mac_hid_start_emulation();
202 mac_hid_stop_emulation();
219 .
procname =
"mouse_button_emulation",
220 .data = &mouse_emulate_buttons,
221 .maxlen =
sizeof(
int),
226 .procname =
"mouse_button2_keycode",
227 .data = &mouse_button2_keycode,
228 .maxlen =
sizeof(
int),
233 .procname =
"mouse_button3_keycode",
234 .data = &mouse_button3_keycode,
235 .maxlen =
sizeof(
int),
248 .child = mac_hid_files,
259 .child = mac_hid_dir,
266 static int __init mac_hid_init(
void)
269 if (!mac_hid_sysctl_header)
276 static void __exit mac_hid_exit(
void)
280 if (mouse_emulate_buttons)
281 mac_hid_stop_emulation();