buttonmapping.h 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef LIBRAZER_BUTTONMAPPING_H_
  2. #define LIBRAZER_BUTTONMAPPING_H_
  3. #include "razer_private.h"
  4. /* enum razer_button_function_id - Logical function IDs */
  5. enum razer_button_function_id {
  6. RAZER_BUTFUNC_LEFT = 0x01, /* Left button */
  7. RAZER_BUTFUNC_RIGHT = 0x02, /* Right button */
  8. RAZER_BUTFUNC_MIDDLE = 0x03, /* Middle button */
  9. RAZER_BUTFUNC_DBLCLICK = 0x04, /* Left button double click */
  10. RAZER_BUTFUNC_ADVANCED = 0x05, /* Advanced function */
  11. RAZER_BUTFUNC_MACRO = 0x06, /* Macro function */
  12. RAZER_BUTFUNC_PROFDOWN = 0x0A, /* Profile down */
  13. RAZER_BUTFUNC_PROFUP = 0x0B, /* Profile up */
  14. RAZER_BUTFUNC_DPIUP = 0x0C, /* DPI down */
  15. RAZER_BUTFUNC_DPIDOWN = 0x0D, /* DPI down */
  16. RAZER_BUTFUNC_DPI1 = 0x0E, /* Select first DPI mapping */
  17. RAZER_BUTFUNC_DPI2 = 0x0F, /* Select second DPI mapping */
  18. RAZER_BUTFUNC_DPI3 = 0x10, /* Select third DPI mapping */
  19. RAZER_BUTFUNC_DPI4 = 0x11, /* Select fourth DPI mapping */
  20. RAZER_BUTFUNC_DPI5 = 0x12, /* Select fifth DPI mapping */
  21. RAZER_BUTFUNC_WIN5 = 0x1A, /* Windows button 5 */
  22. RAZER_BUTFUNC_WIN4 = 0x1B, /* Windows button 4 */
  23. RAZER_BUTFUNC_SCROLLUP = 0x30, /* Scroll wheel up */
  24. RAZER_BUTFUNC_SCROLLDWN = 0x31, /* Scroll wheel down */
  25. };
  26. /* Define a struct razer_button_function element */
  27. #define DEFINE_RAZER_BUTFUNC(_id, _name) \
  28. { .id = RAZER_BUTFUNC_##_id, .name = _name, }
  29. #define BUTTONFUNC_LEFT DEFINE_RAZER_BUTFUNC(LEFT, "Leftclick")
  30. #define BUTTONFUNC_RIGHT DEFINE_RAZER_BUTFUNC(RIGHT, "Rightclick")
  31. #define BUTTONFUNC_MIDDLE DEFINE_RAZER_BUTFUNC(MIDDLE, "Middleclick")
  32. #define BUTTONFUNC_DBLCLICK DEFINE_RAZER_BUTFUNC(DBLCLICK, "Doubleclick")
  33. #define BUTTONFUNC_ADVANCED DEFINE_RAZER_BUTFUNC(ADVANCED, "Advanced")
  34. #define BUTTONFUNC_MACRO DEFINE_RAZER_BUTFUNC(MACRO, "Macro")
  35. #define BUTTONFUNC_PROFDOWN DEFINE_RAZER_BUTFUNC(PROFDOWN, "Profile switch down")
  36. #define BUTTONFUNC_PROFUP DEFINE_RAZER_BUTFUNC(PROFUP, "Profile switch up")
  37. #define BUTTONFUNC_DPIUP DEFINE_RAZER_BUTFUNC(DPIUP, "DPI mapping up")
  38. #define BUTTONFUNC_DPIDOWN DEFINE_RAZER_BUTFUNC(DPIDOWN, "DPI mapping down")
  39. #define BUTTONFUNC_DPI1 DEFINE_RAZER_BUTFUNC(DPI1, "1st DPI mapping")
  40. #define BUTTONFUNC_DPI2 DEFINE_RAZER_BUTFUNC(DPI2, "2nd DPI mapping")
  41. #define BUTTONFUNC_DPI3 DEFINE_RAZER_BUTFUNC(DPI3, "3rd DPI mapping")
  42. #define BUTTONFUNC_DPI4 DEFINE_RAZER_BUTFUNC(DPI4, "4th DPI mapping")
  43. #define BUTTONFUNC_DPI5 DEFINE_RAZER_BUTFUNC(DPI5, "5th DPI mapping")
  44. #define BUTTONFUNC_WIN5 DEFINE_RAZER_BUTFUNC(WIN5, "Windows button 5")
  45. #define BUTTONFUNC_WIN4 DEFINE_RAZER_BUTFUNC(WIN4, "Windows button 4")
  46. #define BUTTONFUNC_SCROLLUP DEFINE_RAZER_BUTFUNC(SCROLLUP, "Scroll wheel up")
  47. #define BUTTONFUNC_SCROLLDWN DEFINE_RAZER_BUTFUNC(SCROLLDWN, "Scroll wheel down")
  48. /* struct razer_buttonmapping - physical-logical mapping for one button.
  49. * This is the wire-protocol data structure. */
  50. struct razer_buttonmapping {
  51. uint8_t physical;
  52. uint8_t logical;
  53. };
  54. /** razer_create_buttonmap - Create an on-wire button map. */
  55. int razer_create_buttonmap(void *buffer, size_t bufsize,
  56. struct razer_buttonmapping *mappings, size_t nr_mappings,
  57. unsigned int struct_spacing);
  58. /** razer_parse_buttonmap - Parse an on-wire button map. */
  59. int razer_parse_buttonmap(void *rawdata, size_t rawsize,
  60. struct razer_buttonmapping *mappings, size_t nr_mappings,
  61. unsigned int struct_spacing);
  62. /** razer_get_buttonfunction_by_id - find a function in a list, by ID */
  63. struct razer_button_function * razer_get_buttonfunction_by_id(
  64. struct razer_button_function *functions, size_t nr_functions,
  65. uint8_t logical_id);
  66. /** razer_get_buttonfunction_by_button - find a function in a list, by button */
  67. struct razer_button_function * razer_get_buttonfunction_by_button(
  68. struct razer_buttonmapping *mappings, size_t nr_mappings,
  69. struct razer_button_function *functions, size_t nr_functions,
  70. const struct razer_button *button);
  71. /** razer_get_buttonmapping_by_physid - find a button mapping by physical ID */
  72. struct razer_buttonmapping * razer_get_buttonmapping_by_physid(
  73. struct razer_buttonmapping *mappings, size_t nr_mappings,
  74. uint8_t physical_id);
  75. #endif /* LIBRAZER_BUTTONMAPPING_H_ */