touchpad.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /* Elan HID-over-I2C touchpad on the Braswell LPSS I2C bus.
  2. *
  3. * The HP Chromebook 11 G5 EE (setzer) wires its touchpad to LPSS I2C6 at
  4. * 0xD1327000, slave address 0x15. The LPSS I2C functions are hidden from
  5. * PCI in ACPI mode, so the driver scans the two firmware BAR windows for
  6. * DesignWare component types instead of enumerating PCI.
  7. *
  8. * The report line is a GPIO we have no driver for, so the input register is
  9. * polled. A read with no pending report returns a zero length immediately.
  10. * Reading the register back-to-back stalls the device: 25 ms (40 Hz) is the
  11. * rate it keeps up with, and the pointer still moves smoothly.
  12. *
  13. * Init follows Linux's elan_i2c: reset, consume the 2-byte reset
  14. * acknowledgement, read the HID descriptor and the max-X/Y commands, select
  15. * absolute mode (0x0300) and wake the device (0x0800).
  16. *
  17. * The clickpad has no right button, so a short stationary tap is turned into
  18. * a synthetic click: two fingers (or one finger in the bottom-right corner)
  19. * is a right click, one finger elsewhere is a left click. The press is held
  20. * briefly so ring-3 commands polling SYS_WIN_POINTER sample it. Resetting
  21. * last leaves the device silent until the next power cycle.
  22. */
  23. #include "touchpad.h"
  24. #include "i2c.h"
  25. #include "io.h"
  26. #include "paging.h"
  27. #include "timer.h"
  28. #define TP_ADDR 0x15
  29. #define TP_CTRL_MAX 16
  30. #define TP_CTRL_STEP 0x1000u
  31. #define TP_HID_DESC_REG 0x0001
  32. #define TP_HID_DESC_LEN 30
  33. #define TP_CMD_REG 0x0005
  34. #define TP_CMD_RESET 0x0100
  35. #define TP_CMD_WAKE 0x0800
  36. #define TP_MODE_REG 0x0300
  37. #define TP_MODE_ABS 0x0001
  38. #define TP_DW_COMP_TYPE 0x44570140u
  39. #define TP_REPORT_ID 0x5d
  40. #define TP_MAX_X_REG 0x0106
  41. #define TP_MAX_Y_REG 0x0107
  42. #define TP_ABS_MAX 4095
  43. #define TP_MAX_INPUT 64
  44. #define TP_POLL_MS 25
  45. /* Tap gestures. The report is polled at 40 Hz, so a tap must last at least
  46. * two samples to be seen; the movement cap keeps a swipe from clicking. */
  47. #define TP_TAP_MIN_MS 40
  48. #define TP_TAP_MAX_MS 300
  49. #define TP_TAP_MOVE 60
  50. #define TP_CLICK_HOLD_MS 120
  51. /* Software right button zones: right 25% x bottom 25% of the pad. The raw
  52. * Elan Y axis grows upwards, so the bottom is the low end. */
  53. #define TP_CORNER_X_PCT 75
  54. #define TP_CORNER_Y_PCT 25
  55. enum {
  56. TP_RC_OFF = 0,
  57. TP_RC_TAP = 1,
  58. TP_RC_CORNER = 2,
  59. TP_RC_BOTH = TP_RC_TAP | TP_RC_CORNER
  60. };
  61. static unsigned int tp_base;
  62. static unsigned int tp_addr = TP_ADDR;
  63. static int tp_present;
  64. static unsigned int tp_in_reg = 0x0003;
  65. static unsigned int tp_max_in = 34;
  66. static unsigned int tp_cmd_reg = TP_CMD_REG;
  67. static unsigned short tp_vendor;
  68. static unsigned short tp_product;
  69. static int tp_max_x = TP_ABS_MAX;
  70. static int tp_max_y = TP_ABS_MAX;
  71. static const char *tp_err;
  72. static unsigned int tp_err_val;
  73. static int tp_last_x, tp_last_y, tp_acc_x, tp_acc_y;
  74. static int tp_down, tp_last_buttons;
  75. static unsigned int tp_next_poll;
  76. /* Gesture configuration and synthesized-click state. */
  77. static unsigned int tp_rc_mode = TP_RC_BOTH;
  78. static int tp_tapclick = 1;
  79. static int tp_phys_raw; /* clickpad bit from the last report */
  80. static int tp_phys_btn; /* latched button: 0, 0x01 or 0x02 */
  81. static unsigned int tp_click_btn;
  82. static unsigned int tp_click_release_ms;
  83. static unsigned int tp_synth_left, tp_synth_right;
  84. /* One contact sequence: from the first finger down to the last finger up. */
  85. static int tp_gesture_active;
  86. static unsigned int tp_gesture_t0;
  87. static int tp_gesture_x0, tp_gesture_y0;
  88. static int tp_gesture_started;
  89. static int tp_gesture_moved;
  90. static int tp_gesture_two;
  91. static int tp_gesture_phys;
  92. /* Last report, for the `touchpad` status command. */
  93. static int tp_stat_fingers, tp_stat_f1, tp_stat_x, tp_stat_y;
  94. static void put_dec(unsigned int v);
  95. static const char *rc_name(void);
  96. static void put_hex16(unsigned int v)
  97. {
  98. static const char hex[] = "0123456789ABCDEF";
  99. io_putchar(hex[(v >> 12) & 0xf]);
  100. io_putchar(hex[(v >> 8) & 0xf]);
  101. io_putchar(hex[(v >> 4) & 0xf]);
  102. io_putchar(hex[v & 0xf]);
  103. }
  104. static void print_summary(void)
  105. {
  106. io_putstr("touchpad: elan ");
  107. put_hex16(tp_vendor);
  108. io_putchar(':');
  109. put_hex16(tp_product);
  110. io_putstr(" i2c 0x");
  111. io_puthex(tp_base);
  112. io_putstr(" addr 0x");
  113. io_puthex(tp_addr);
  114. io_putstr(" max ");
  115. put_dec((unsigned int)tp_max_x);
  116. io_putchar('x');
  117. put_dec((unsigned int)tp_max_y);
  118. io_putchar('\n');
  119. }
  120. static void print_status(void)
  121. {
  122. print_summary();
  123. io_putstr("touchpad: rightclick ");
  124. io_putstr(rc_name());
  125. io_putstr(" tapclick ");
  126. io_putstr(tp_tapclick ? "on" : "off");
  127. io_putstr(" corner x>=");
  128. put_dec((unsigned int)(tp_max_x * TP_CORNER_X_PCT / 100));
  129. io_putstr(" y<=");
  130. put_dec((unsigned int)(tp_max_y * TP_CORNER_Y_PCT / 100));
  131. io_putstr("\n");
  132. io_putstr("touchpad: last f=");
  133. put_dec((unsigned int)tp_stat_fingers);
  134. if (tp_stat_f1) {
  135. io_putstr(" x=");
  136. put_dec((unsigned int)tp_stat_x);
  137. io_putstr(" y=");
  138. put_dec((unsigned int)tp_stat_y);
  139. }
  140. io_putstr(" taps left=");
  141. put_dec(tp_synth_left);
  142. io_putstr(" right=");
  143. put_dec(tp_synth_right);
  144. io_putchar('\n');
  145. }
  146. static void msleep(unsigned int ms)
  147. {
  148. unsigned int t0 = get_ticks_ms();
  149. while (get_ticks_ms() - t0 < ms)
  150. ;
  151. }
  152. static unsigned int get16(const unsigned char *p)
  153. {
  154. return (unsigned int)p[0] | ((unsigned int)p[1] << 8);
  155. }
  156. static void put_dec(unsigned int v)
  157. {
  158. char buf[11];
  159. unsigned int i = 0;
  160. if (!v) {
  161. io_putchar('0');
  162. return;
  163. }
  164. while (v) {
  165. buf[i++] = (char)('0' + v % 10);
  166. v /= 10;
  167. }
  168. while (i)
  169. io_putchar(buf[--i]);
  170. }
  171. /* Match one whitespace-delimited word at s (end or space after it). */
  172. static int word_is(const char *s, const char *word)
  173. {
  174. while (*word) {
  175. if (*s != *word)
  176. return 0;
  177. s++;
  178. word++;
  179. }
  180. return *s == '\0' || *s == ' ';
  181. }
  182. static const char *skip_spaces(const char *s)
  183. {
  184. while (*s == ' ')
  185. s++;
  186. return s;
  187. }
  188. static unsigned int word_len(const char *s)
  189. {
  190. unsigned int n = 0;
  191. while (s[n] && s[n] != ' ')
  192. n++;
  193. return n;
  194. }
  195. static int finger_count(unsigned int ti)
  196. {
  197. unsigned int mask = (ti >> 3) & 0x1f;
  198. int n = 0;
  199. while (mask) {
  200. n += (int)(mask & 1);
  201. mask >>= 1;
  202. }
  203. return n;
  204. }
  205. static int in_corner(int x, int y)
  206. {
  207. return x >= tp_max_x * TP_CORNER_X_PCT / 100 &&
  208. y <= tp_max_y * TP_CORNER_Y_PCT / 100;
  209. }
  210. static const char *rc_name(void)
  211. {
  212. switch (tp_rc_mode) {
  213. case TP_RC_OFF: return "off";
  214. case TP_RC_TAP: return "tap";
  215. case TP_RC_CORNER: return "corner";
  216. default: return "both";
  217. }
  218. }
  219. static int hid_read_reg(unsigned int addr, unsigned int reg,
  220. unsigned char *buf, unsigned int len)
  221. {
  222. unsigned char r[2];
  223. r[0] = (unsigned char)(reg & 0xff);
  224. r[1] = (unsigned char)(reg >> 8);
  225. if (i2c_dw_transfer(tp_base, addr, r, 2, buf, len) == 0)
  226. return 0;
  227. /* Some devices do not answer the combined write+read (repeated
  228. * start). Retry with a STOP between the register address and the
  229. * data read. */
  230. if (i2c_dw_transfer(tp_base, addr, r, 2, 0, 0) != 0)
  231. return -1;
  232. return i2c_dw_transfer(tp_base, addr, 0, 0, buf, len);
  233. }
  234. static int hid_write_reg(unsigned int addr, unsigned int reg, unsigned int val)
  235. {
  236. unsigned char b[4];
  237. b[0] = (unsigned char)(reg & 0xff);
  238. b[1] = (unsigned char)(reg >> 8);
  239. b[2] = (unsigned char)(val & 0xff);
  240. b[3] = (unsigned char)(val >> 8);
  241. return i2c_dw_transfer(tp_base, addr, b, 4, 0, 0);
  242. }
  243. /* Native Elan max-coordinate commands (the same read-cmd path Linux
  244. * elan_i2c uses). They give the corner zone a physical frame instead of
  245. * assuming the full 12-bit range; on failure keep the 4095 fallback. */
  246. static void query_limits(void)
  247. {
  248. unsigned char v[2];
  249. if (hid_read_reg(tp_addr, TP_MAX_X_REG, v, 2) == 0) {
  250. unsigned int m = get16(v) & 0x0fff;
  251. if (m >= 256)
  252. tp_max_x = (int)m;
  253. }
  254. if (hid_read_reg(tp_addr, TP_MAX_Y_REG, v, 2) == 0) {
  255. unsigned int m = get16(v) & 0x0fff;
  256. if (m >= 256)
  257. tp_max_y = (int)m;
  258. }
  259. }
  260. static int probe_controller(unsigned int base)
  261. {
  262. unsigned char desc[TP_HID_DESC_LEN + 2];
  263. unsigned char ack[2];
  264. unsigned int off, len, ver;
  265. if (!i2c_dw_present(base))
  266. return 0;
  267. if (i2c_dw_init(base) != 0) {
  268. tp_err = "i2c init failed";
  269. return 0;
  270. }
  271. tp_base = base;
  272. /* The Elan address is fixed; a plain read is a harmless ACK check. */
  273. if (i2c_dw_transfer(base, TP_ADDR, 0, 0, ack, 1) != 0) {
  274. tp_err = "no device at 0x15";
  275. return 0;
  276. }
  277. /* Reset first and consume the acknowledgement, then read the HID
  278. * descriptor. The descriptor read is prefixed with two status
  279. * bytes and the 2-byte length, so accept either offset. */
  280. hid_write_reg(TP_ADDR, TP_CMD_REG, TP_CMD_RESET);
  281. msleep(150);
  282. (void)i2c_dw_transfer(base, TP_ADDR, 0, 0, ack, 2);
  283. if (hid_read_reg(TP_ADDR, TP_HID_DESC_REG, desc, sizeof(desc)) != 0) {
  284. tp_err = "descriptor read failed";
  285. tp_err_val = i2c_last_abort;
  286. return 0;
  287. }
  288. off = 0;
  289. if (get16(desc + 0) != TP_HID_DESC_LEN ||
  290. get16(desc + 2) != 0x0100) {
  291. if (get16(desc + 2) == TP_HID_DESC_LEN &&
  292. get16(desc + 4) == 0x0100)
  293. off = 2;
  294. }
  295. len = get16(desc + off);
  296. ver = get16(desc + off + 2);
  297. if (len != TP_HID_DESC_LEN || ver != 0x0100) {
  298. tp_err = "bad hid descriptor";
  299. return 0;
  300. }
  301. tp_in_reg = get16(desc + off + 8);
  302. tp_max_in = get16(desc + off + 10);
  303. tp_cmd_reg = get16(desc + off + 16);
  304. tp_vendor = (unsigned short)get16(desc + off + 20);
  305. tp_product = (unsigned short)get16(desc + off + 22);
  306. if (tp_max_in < 12 || tp_max_in > TP_MAX_INPUT)
  307. tp_max_in = 34;
  308. /* Absolute reporting, then wake: after the reset the Elan stays
  309. * quiet until the host selects a mode. */
  310. hid_write_reg(TP_ADDR, TP_MODE_REG, TP_MODE_ABS);
  311. msleep(40);
  312. hid_write_reg(TP_ADDR, tp_cmd_reg, TP_CMD_WAKE);
  313. msleep(60);
  314. /* Query the limits with the device awake (Linux reads them after
  315. * initialize()/wake and before enabling reports). */
  316. query_limits();
  317. tp_present = 1;
  318. tp_err = 0;
  319. print_summary();
  320. return 1;
  321. }
  322. int touchpad_init(void)
  323. {
  324. /* The ACPI _CRS address for the LPSS I2C blocks is 0x9132xxxx on
  325. * coreboot, but this firmware maps them at 0xD132xxxx. Both
  326. * windows are scanned; page 7 (I2C6) is tried first. */
  327. static const unsigned int ranges[2] = { 0x91320000u, 0xd1320000u };
  328. unsigned int r, k;
  329. if (tp_present)
  330. return 1;
  331. for (r = 0; r < 2; r++) {
  332. for (k = 0; k < TP_CTRL_MAX; k++) {
  333. unsigned int i = (k + 7) % TP_CTRL_MAX;
  334. unsigned int base = ranges[r] + i * TP_CTRL_STEP;
  335. paging_map_mmio(base, 0x1000);
  336. /* A block left in functional reset keeps its
  337. * register file but never clocks the I2C FSM. */
  338. i2c_dw_reset_release(base);
  339. if (probe_controller(base))
  340. return 1;
  341. }
  342. }
  343. return 0;
  344. }
  345. int touchpad_present(void)
  346. {
  347. return tp_present;
  348. }
  349. unsigned int touchpad_addr(void)
  350. {
  351. return tp_addr;
  352. }
  353. unsigned short touchpad_vendor(void)
  354. {
  355. return tp_vendor;
  356. }
  357. unsigned short touchpad_product(void)
  358. {
  359. return tp_product;
  360. }
  361. /* Track one contact sequence and turn a short, stationary tap into a
  362. * synthetic button press. The Elan report packs the touch info byte
  363. * (f5..f1 at bits 7..3, clickpad at bit 0) and five bytes per finger, so
  364. * the finger mask alone tells us whether this was a one- or two-finger
  365. * tap. Only finger 1 drives the pointer, and its data is valid only while
  366. * its presence bit is set. */
  367. static void touchpad_gesture(unsigned int ti, int x, int y, unsigned int now)
  368. {
  369. int fingers = finger_count(ti);
  370. int f1 = (ti & 0x08) != 0;
  371. unsigned int duration;
  372. tp_stat_fingers = fingers;
  373. tp_stat_f1 = f1;
  374. if (f1) {
  375. tp_stat_x = x;
  376. tp_stat_y = y;
  377. }
  378. if (fingers) {
  379. if (!tp_gesture_active) {
  380. tp_gesture_active = 1;
  381. tp_gesture_t0 = now;
  382. tp_gesture_started = 0;
  383. tp_gesture_moved = 0;
  384. tp_gesture_two = 0;
  385. tp_gesture_phys = 0;
  386. }
  387. if (f1) {
  388. if (!tp_gesture_started) {
  389. tp_gesture_started = 1;
  390. tp_gesture_x0 = x;
  391. tp_gesture_y0 = y;
  392. } else {
  393. int ddx = x - tp_gesture_x0;
  394. int ddy = y - tp_gesture_y0;
  395. if (ddx < 0)
  396. ddx = -ddx;
  397. if (ddy < 0)
  398. ddy = -ddy;
  399. if (ddx > TP_TAP_MOVE || ddy > TP_TAP_MOVE)
  400. tp_gesture_moved = 1;
  401. }
  402. }
  403. if (fingers >= 2)
  404. tp_gesture_two = 1;
  405. if (ti & 0x01)
  406. tp_gesture_phys = 1;
  407. return;
  408. }
  409. if (!tp_gesture_active)
  410. return;
  411. tp_gesture_active = 0;
  412. duration = now - tp_gesture_t0;
  413. if (duration < TP_TAP_MIN_MS || duration > TP_TAP_MAX_MS ||
  414. tp_gesture_moved || tp_gesture_phys)
  415. return;
  416. if (tp_gesture_two) {
  417. if (!(tp_rc_mode & TP_RC_TAP))
  418. return;
  419. tp_click_btn = 0x02;
  420. tp_synth_right++;
  421. } else if (tp_gesture_started &&
  422. (tp_rc_mode & TP_RC_CORNER) &&
  423. in_corner(tp_gesture_x0, tp_gesture_y0)) {
  424. tp_click_btn = 0x02;
  425. tp_synth_right++;
  426. } else if (tp_tapclick) {
  427. tp_click_btn = 0x01;
  428. tp_synth_left++;
  429. } else {
  430. return;
  431. }
  432. /* Hold the synthetic press long enough for a ring-3 app polling
  433. * SYS_WIN_POINTER (typically every 10-16 ms) to sample it. */
  434. tp_click_release_ms = now + TP_CLICK_HOLD_MS;
  435. }
  436. int touchpad_poll(int *buttons, int *dx, int *dy)
  437. {
  438. unsigned char buf[TP_MAX_INPUT];
  439. unsigned int now, b;
  440. if (!tp_present)
  441. return 0;
  442. now = get_ticks_ms();
  443. /* The synthetic tap press is released by time, whether or not a new
  444. * report arrives (the finger is already up). */
  445. if (tp_click_btn && (int)(now - tp_click_release_ms) >= 0) {
  446. tp_click_btn = 0;
  447. *buttons = (unsigned int)tp_phys_btn;
  448. tp_last_buttons = *buttons;
  449. return 1;
  450. }
  451. if ((int)(now - tp_next_poll) < 0)
  452. return 0;
  453. tp_next_poll = now + TP_POLL_MS;
  454. if (hid_read_reg(tp_addr, tp_in_reg, buf, tp_max_in) != 0)
  455. return 0;
  456. /* The addressed read returns two status bytes, the 2-byte length
  457. * and then the report, so locate the 0x5D report ID instead of
  458. * trusting a fixed offset. Layout after it (Linux hid-elan.c):
  459. * touch info (f5..f1 at bits 7..3, clickpad at bit 0), then 5
  460. * bytes per active finger: x11:8/y11:9, x7:0, y7:0, size,
  461. * pressure. */
  462. for (b = 0; b < 6 && b + 4 < tp_max_in; b++)
  463. if (buf[b] == TP_REPORT_ID)
  464. break;
  465. if (b >= 6 || b + 4 >= tp_max_in)
  466. return 0;
  467. {
  468. unsigned int ti = buf[b + 1];
  469. unsigned int xh = buf[b + 2];
  470. int x = ((int)(xh & 0xf0) << 4) | buf[b + 3];
  471. int y = ((int)(xh & 0x0f) << 8) | buf[b + 4];
  472. {
  473. int raw = (ti & 0x01) != 0;
  474. int f1 = (ti & 0x08) != 0;
  475. if (raw) {
  476. /* Latch at the leading edge: a physical
  477. * clickpad press in the bottom-right zone is
  478. * the right button, anywhere else the left
  479. * button, for the whole press (so a corner
  480. * drag stays a right drag). */
  481. if (!tp_phys_raw) {
  482. tp_phys_btn = 0x01;
  483. if ((tp_rc_mode & TP_RC_CORNER) && f1 &&
  484. in_corner(x, y))
  485. tp_phys_btn = 0x02;
  486. }
  487. } else {
  488. tp_phys_btn = 0;
  489. }
  490. tp_phys_raw = raw;
  491. }
  492. touchpad_gesture(ti, x, y, now);
  493. *buttons = (unsigned int)tp_phys_btn | tp_click_btn;
  494. if (!(ti & 0x08)) { /* finger 1 lifted */
  495. tp_down = 0;
  496. tp_acc_x = 0;
  497. tp_acc_y = 0;
  498. if (tp_last_buttons != *buttons) {
  499. tp_last_buttons = *buttons;
  500. return 1;
  501. }
  502. return 0;
  503. }
  504. if (!tp_down) {
  505. tp_down = 1;
  506. tp_last_x = x;
  507. tp_last_y = y;
  508. *dx = 0;
  509. *dy = 0;
  510. } else {
  511. tp_acc_x += x - tp_last_x;
  512. /* The Elan's Y axis increases upwards, already the
  513. * PS/2 convention: dragging up gives a positive dy. */
  514. tp_acc_y += y - tp_last_y;
  515. tp_last_x = x;
  516. tp_last_y = y;
  517. *dx = tp_acc_x / 2;
  518. tp_acc_x -= *dx * 2;
  519. *dy = tp_acc_y / 2;
  520. tp_acc_y -= *dy * 2;
  521. }
  522. if (*dx > 64)
  523. *dx = 64;
  524. if (*dx < -64)
  525. *dx = -64;
  526. if (*dy > 64)
  527. *dy = 64;
  528. if (*dy < -64)
  529. *dy = -64;
  530. if (tp_last_buttons != *buttons) {
  531. tp_last_buttons = *buttons;
  532. return 1;
  533. }
  534. return *dx || *dy;
  535. }
  536. }
  537. void program_touchpad_main(const char *arg)
  538. {
  539. if (!tp_present) {
  540. io_putstr("touchpad: absent (");
  541. io_putstr(tp_err ? tp_err : "unknown");
  542. if (tp_err_val) {
  543. io_putstr(" ab=");
  544. io_puthex(tp_err_val);
  545. }
  546. io_putstr(")\n");
  547. return;
  548. }
  549. arg = arg ? skip_spaces(arg) : 0;
  550. if (!arg || !*arg) {
  551. print_status();
  552. return;
  553. }
  554. while (*arg) {
  555. if (word_is(arg, "rightclick")) {
  556. const char *v = skip_spaces(arg + 10);
  557. if (!*v) {
  558. io_putstr("touchpad: rightclick ");
  559. io_putstr(rc_name());
  560. io_putchar('\n');
  561. return;
  562. }
  563. if (word_is(v, "off"))
  564. tp_rc_mode = TP_RC_OFF;
  565. else if (word_is(v, "tap"))
  566. tp_rc_mode = TP_RC_TAP;
  567. else if (word_is(v, "corner"))
  568. tp_rc_mode = TP_RC_CORNER;
  569. else if (word_is(v, "both"))
  570. tp_rc_mode = TP_RC_BOTH;
  571. else {
  572. io_putstr("touchpad: rightclick off|tap|corner|both\n");
  573. return;
  574. }
  575. io_putstr("touchpad: rightclick ");
  576. io_putstr(rc_name());
  577. io_putchar('\n');
  578. arg = skip_spaces(v + word_len(v));
  579. } else if (word_is(arg, "tapclick")) {
  580. const char *v = skip_spaces(arg + 8);
  581. if (!*v) {
  582. io_putstr("touchpad: tapclick ");
  583. io_putstr(tp_tapclick ? "on" : "off");
  584. io_putchar('\n');
  585. return;
  586. }
  587. if (word_is(v, "on"))
  588. tp_tapclick = 1;
  589. else if (word_is(v, "off"))
  590. tp_tapclick = 0;
  591. else {
  592. io_putstr("touchpad: tapclick on|off\n");
  593. return;
  594. }
  595. io_putstr("touchpad: tapclick ");
  596. io_putstr(tp_tapclick ? "on" : "off");
  597. io_putchar('\n');
  598. arg = skip_spaces(v + word_len(v));
  599. } else {
  600. io_putstr("touchpad: usage: touchpad [rightclick off|tap|corner|both | tapclick on|off]\n");
  601. return;
  602. }
  603. }
  604. }