mac_hid.c 3.2 KB

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