mac_hid.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * drivers/macintosh/mac_hid.c
  3. *
  4. * HID support stuff for Macintosh computers.
  5. *
  6. * Copyright (C) 2000 Franz Sirl.
  7. *
  8. * This file will soon be removed in favor of an uinput userspace tool.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/proc_fs.h>
  12. #include <linux/sysctl.h>
  13. #include <linux/input.h>
  14. #include <linux/module.h>
  15. static struct input_dev *emumousebtn;
  16. static int emumousebtn_input_register(void);
  17. static int mouse_emulate_buttons = 0;
  18. static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */
  19. static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */
  20. static int mouse_last_keycode = 0;
  21. #if defined(CONFIG_SYSCTL)
  22. /* file(s) in /proc/sys/dev/mac_hid */
  23. ctl_table mac_hid_files[] = {
  24. {
  25. .ctl_name = DEV_MAC_HID_MOUSE_BUTTON_EMULATION,
  26. .procname = "mouse_button_emulation",
  27. .data = &mouse_emulate_buttons,
  28. .maxlen = sizeof(int),
  29. .mode = 0644,
  30. .proc_handler = &proc_dointvec,
  31. },
  32. {
  33. .ctl_name = DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE,
  34. .procname = "mouse_button2_keycode",
  35. .data = &mouse_button2_keycode,
  36. .maxlen = sizeof(int),
  37. .mode = 0644,
  38. .proc_handler = &proc_dointvec,
  39. },
  40. {
  41. .ctl_name = DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE,
  42. .procname = "mouse_button3_keycode",
  43. .data = &mouse_button3_keycode,
  44. .maxlen = sizeof(int),
  45. .mode = 0644,
  46. .proc_handler = &proc_dointvec,
  47. },
  48. { .ctl_name = 0 }
  49. };
  50. /* dir in /proc/sys/dev */
  51. ctl_table mac_hid_dir[] = {
  52. {
  53. .ctl_name = DEV_MAC_HID,
  54. .procname = "mac_hid",
  55. .maxlen = 0,
  56. .mode = 0555,
  57. .child = mac_hid_files,
  58. },
  59. { .ctl_name = 0 }
  60. };
  61. /* /proc/sys/dev itself, in case that is not there yet */
  62. ctl_table mac_hid_root_dir[] = {
  63. {
  64. .ctl_name = CTL_DEV,
  65. .procname = "dev",
  66. .maxlen = 0,
  67. .mode = 0555,
  68. .child = mac_hid_dir,
  69. },
  70. { .ctl_name = 0 }
  71. };
  72. static struct ctl_table_header *mac_hid_sysctl_header;
  73. #endif /* endif CONFIG_SYSCTL */
  74. int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down)
  75. {
  76. switch (caller) {
  77. case 1:
  78. /* Called from keyboard.c */
  79. if (mouse_emulate_buttons
  80. && (keycode == mouse_button2_keycode
  81. || keycode == mouse_button3_keycode)) {
  82. if (mouse_emulate_buttons == 1) {
  83. input_report_key(emumousebtn,
  84. keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT,
  85. down);
  86. input_sync(emumousebtn);
  87. return 1;
  88. }
  89. mouse_last_keycode = down ? keycode : 0;
  90. }
  91. break;
  92. }
  93. return 0;
  94. }
  95. EXPORT_SYMBOL(mac_hid_mouse_emulate_buttons);
  96. static int emumousebtn_input_register(void)
  97. {
  98. emumousebtn = input_allocate_device();
  99. if (!emumousebtn)
  100. return -ENOMEM;
  101. emumousebtn->name = "Macintosh mouse button emulation";
  102. emumousebtn->id.bustype = BUS_ADB;
  103. emumousebtn->id.vendor = 0x0001;
  104. emumousebtn->id.product = 0x0001;
  105. emumousebtn->id.version = 0x0100;
  106. emumousebtn->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
  107. emumousebtn->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
  108. emumousebtn->relbit[0] = BIT(REL_X) | BIT(REL_Y);
  109. input_register_device(emumousebtn);
  110. return 0;
  111. }
  112. int __init mac_hid_init(void)
  113. {
  114. int err;
  115. err = emumousebtn_input_register();
  116. if (err)
  117. return err;
  118. #if defined(CONFIG_SYSCTL)
  119. mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir, 1);
  120. #endif /* CONFIG_SYSCTL */
  121. return 0;
  122. }
  123. device_initcall(mac_hid_init);