1
0

shared.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Copyright © 2014 Red Hat, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. */
  23. #ifndef _SHARED_H_
  24. #define _SHARED_H_
  25. #include "config.h"
  26. #include <getopt.h>
  27. #include <libinput.h>
  28. #include <limits.h>
  29. #include <quirks.h>
  30. #include <stdbool.h>
  31. #include "util-strings.h"
  32. #define EXIT_INVALID_USAGE 2
  33. extern uint32_t log_serial;
  34. enum configuration_options {
  35. OPT_TAP_ENABLE = 256,
  36. OPT_TAP_DISABLE,
  37. OPT_TAP_MAP,
  38. OPT_DRAG_ENABLE,
  39. OPT_DRAG_DISABLE,
  40. OPT_DRAG_LOCK_ENABLE,
  41. OPT_DRAG_LOCK_DISABLE,
  42. OPT_NATURAL_SCROLL_ENABLE,
  43. OPT_NATURAL_SCROLL_DISABLE,
  44. OPT_LEFT_HANDED_ENABLE,
  45. OPT_LEFT_HANDED_DISABLE,
  46. OPT_MIDDLEBUTTON_ENABLE,
  47. OPT_MIDDLEBUTTON_DISABLE,
  48. OPT_DWT_ENABLE,
  49. OPT_DWT_DISABLE,
  50. OPT_DWTP_ENABLE,
  51. OPT_DWTP_DISABLE,
  52. OPT_CLICK_METHOD,
  53. OPT_CLICKFINGER_MAP,
  54. OPT_SCROLL_METHOD,
  55. OPT_SCROLL_BUTTON,
  56. OPT_SCROLL_BUTTON_LOCK_ENABLE,
  57. OPT_SCROLL_BUTTON_LOCK_DISABLE,
  58. OPT_SPEED,
  59. OPT_PROFILE,
  60. OPT_DISABLE_SENDEVENTS,
  61. OPT_APPLY_TO,
  62. OPT_CUSTOM_POINTS,
  63. OPT_CUSTOM_STEP,
  64. OPT_CUSTOM_TYPE,
  65. OPT_ROTATION_ANGLE,
  66. OPT_PRESSURE_RANGE,
  67. OPT_CALIBRATION,
  68. OPT_AREA,
  69. OPT_3FG_DRAG,
  70. OPT_SENDEVENTS,
  71. OPT_ERASER_BUTTON_MODE,
  72. OPT_ERASER_BUTTON_BUTTON,
  73. OPT_PLUGINS_DISABLE,
  74. OPT_PLUGINS_ENABLE,
  75. OPT_PLUGIN_PATH,
  76. };
  77. #define CONFIGURATION_OPTIONS \
  78. { "disable-sendevents", required_argument, 0, OPT_DISABLE_SENDEVENTS }, \
  79. { "enable-plugins", no_argument, 0, OPT_PLUGINS_ENABLE }, \
  80. { "disable-plugins", no_argument, 0, OPT_PLUGINS_DISABLE }, \
  81. { "enable-tap", no_argument, 0, OPT_TAP_ENABLE }, \
  82. { "disable-tap", no_argument, 0, OPT_TAP_DISABLE }, \
  83. { "enable-drag", no_argument, 0, OPT_DRAG_ENABLE }, \
  84. { "disable-drag", no_argument, 0, OPT_DRAG_DISABLE }, \
  85. { "enable-drag-lock", optional_argument, 0, OPT_DRAG_LOCK_ENABLE }, \
  86. { "disable-drag-lock", no_argument, 0, OPT_DRAG_LOCK_DISABLE }, \
  87. { "enable-natural-scrolling", no_argument, 0, OPT_NATURAL_SCROLL_ENABLE }, \
  88. { "disable-natural-scrolling", no_argument, 0, OPT_NATURAL_SCROLL_DISABLE }, \
  89. { "enable-left-handed", no_argument, 0, OPT_LEFT_HANDED_ENABLE }, \
  90. { "disable-left-handed", no_argument, 0, OPT_LEFT_HANDED_DISABLE }, \
  91. { "enable-middlebutton", no_argument, 0, OPT_MIDDLEBUTTON_ENABLE }, \
  92. { "disable-middlebutton", no_argument, 0, OPT_MIDDLEBUTTON_DISABLE }, \
  93. { "enable-dwt", no_argument, 0, OPT_DWT_ENABLE }, \
  94. { "disable-dwt", no_argument, 0, OPT_DWT_DISABLE }, \
  95. { "enable-dwtp", no_argument, 0, OPT_DWTP_ENABLE }, \
  96. { "disable-dwtp", no_argument, 0, OPT_DWTP_DISABLE }, \
  97. { "enable-scroll-button-lock", no_argument, 0, OPT_SCROLL_BUTTON_LOCK_ENABLE }, \
  98. { "disable-scroll-button-lock",no_argument, 0, OPT_SCROLL_BUTTON_LOCK_DISABLE }, \
  99. { "enable-3fg-drag", required_argument, 0, OPT_3FG_DRAG }, \
  100. { "set-click-method", required_argument, 0, OPT_CLICK_METHOD }, \
  101. { "set-clickfinger-map", required_argument, 0, OPT_CLICKFINGER_MAP }, \
  102. { "set-scroll-method", required_argument, 0, OPT_SCROLL_METHOD }, \
  103. { "set-scroll-button", required_argument, 0, OPT_SCROLL_BUTTON }, \
  104. { "set-profile", required_argument, 0, OPT_PROFILE }, \
  105. { "set-tap-map", required_argument, 0, OPT_TAP_MAP }, \
  106. { "set-speed", required_argument, 0, OPT_SPEED },\
  107. { "set-sendevents", required_argument, 0, OPT_SENDEVENTS },\
  108. { "apply-to", required_argument, 0, OPT_APPLY_TO },\
  109. { "set-custom-points", required_argument, 0, OPT_CUSTOM_POINTS },\
  110. { "set-custom-step", required_argument, 0, OPT_CUSTOM_STEP },\
  111. { "set-custom-type", required_argument, 0, OPT_CUSTOM_TYPE },\
  112. { "set-rotation-angle", required_argument, 0, OPT_ROTATION_ANGLE }, \
  113. { "set-pressure-range", required_argument, 0, OPT_PRESSURE_RANGE }, \
  114. { "set-calibration", required_argument, 0, OPT_CALIBRATION }, \
  115. { "set-area", required_argument, 0, OPT_AREA }, \
  116. { "set-eraser-button-mode", required_argument, 0, OPT_ERASER_BUTTON_MODE }, \
  117. { "set-eraser-button-button", required_argument, 0, OPT_ERASER_BUTTON_BUTTON },\
  118. { "set-plugin-path", required_argument, 0, OPT_PLUGIN_PATH }
  119. /* Note: New arguments should be added to shell completions */
  120. static inline void
  121. tools_print_usage_option_list(struct option *opts)
  122. {
  123. printf("Options:\n");
  124. struct option *o = opts;
  125. while (o && o->name) {
  126. if (strstartswith(o->name, "enable-") &&
  127. strstartswith((o + 1)->name, "disable-")) {
  128. printf(" --%s/--%s\n", o->name, (o + 1)->name);
  129. o++;
  130. } else {
  131. printf(" --%s\n", o->name);
  132. }
  133. o++;
  134. }
  135. }
  136. enum tools_backend { BACKEND_NONE, BACKEND_DEVICE, BACKEND_UDEV };
  137. struct tools_options {
  138. char match[256];
  139. int plugins;
  140. char **plugin_paths;
  141. int tapping;
  142. int drag;
  143. int drag_lock;
  144. int natural_scroll;
  145. int left_handed;
  146. int middlebutton;
  147. enum libinput_config_click_method click_method;
  148. enum libinput_config_clickfinger_button_map clickfinger_map;
  149. enum libinput_config_scroll_method scroll_method;
  150. enum libinput_config_tap_button_map tap_map;
  151. int scroll_button;
  152. int scroll_button_lock;
  153. double speed;
  154. int dwt;
  155. int dwtp;
  156. enum libinput_config_accel_profile profile;
  157. char disable_pattern[64];
  158. enum libinput_config_accel_type custom_type;
  159. double custom_step;
  160. size_t custom_npoints;
  161. double *custom_points;
  162. unsigned int angle;
  163. double pressure_range[2];
  164. float calibration[6];
  165. struct libinput_config_area_rectangle area;
  166. enum libinput_config_3fg_drag_state drag_3fg;
  167. enum libinput_config_send_events_mode sendevents;
  168. enum libinput_config_eraser_button_mode eraser_button_mode;
  169. unsigned int eraser_button_button;
  170. };
  171. void
  172. tools_init_options(struct tools_options *options);
  173. int
  174. tools_parse_option(int option, const char *optarg, struct tools_options *options);
  175. struct libinput *
  176. tools_open_backend(enum tools_backend which,
  177. const char **seat_or_devices,
  178. bool verbose,
  179. bool *grab,
  180. bool with_plugins,
  181. char **plugin_paths);
  182. void
  183. tools_device_apply_config(struct libinput_device *device,
  184. struct tools_options *options);
  185. void
  186. tools_tablet_tool_apply_config(struct libinput_tablet_tool *tool,
  187. struct tools_options *options);
  188. int
  189. tools_exec_command(const char *prefix, int argc, char **argv);
  190. bool
  191. find_touchpad_device(char *path, size_t path_len);
  192. bool
  193. is_touchpad_device(const char *devnode);
  194. void
  195. tools_list_device_quirks(struct quirks_context *ctx,
  196. struct udev_device *device,
  197. void (*callback)(void *userdata, const char *str),
  198. void *userdata);
  199. void
  200. tools_dispatch(struct libinput *libinput);
  201. #endif