@@ -1682,7 +1682,79 @@ namespace platf {
1682
1682
*/
1683
1683
void
1684
1684
pen (client_input_t *input, const touch_port_t &touch_port, const pen_input_t &pen) {
1685
- // Unimplemented feature - platform_caps::pen_touch
1685
+ int id;
1686
+
1687
+ auto raw = (client_input_raw_t *) input;
1688
+
1689
+ auto global = raw->global ;
1690
+
1691
+ auto touchscreen = global->touch_input .get ();
1692
+
1693
+
1694
+ switch (pen.eventType ) {
1695
+ case LI_TOUCH_EVENT_UP:
1696
+ id = -1 ;
1697
+ break ;
1698
+ case LI_TOUCH_EVENT_CANCEL:
1699
+ id = -1 ;
1700
+ break ;
1701
+ case LI_TOUCH_EVENT_CANCEL_ALL :
1702
+ for (int i; i < 10 ; i++) {
1703
+ libevdev_uinput_write_event (touchscreen, EV_ABS, ABS_MT_SLOT, i);
1704
+ libevdev_uinput_write_event (touchscreen, EV_ABS, ABS_MT_TRACKING_ID, -1 );
1705
+ }
1706
+ libevdev_uinput_write_event (touchscreen, EV_SYN, SYN_REPORT, 0 );
1707
+ return ;
1708
+ case LI_TOUCH_EVENT_DOWN:
1709
+ id = 9 ;
1710
+ break ;
1711
+ case LI_TOUCH_EVENT_MOVE:
1712
+ id = 9 ;
1713
+ break ;
1714
+ default :
1715
+ return ;
1716
+ }
1717
+
1718
+
1719
+ float x = pen.x * touch_port.width ;
1720
+ float y = pen.y * touch_port.height ;
1721
+ float major = pen.contactAreaMajor * touch_port.width ;
1722
+ float minor = pen.contactAreaMinor * touch_port.width ;
1723
+ int pressure = pen.pressureOrDistance * 1024 ;
1724
+ int orientation = standardize_rotation (pen.rotation );
1725
+ if (pen.rotation != LI_ROT_UNKNOWN) {
1726
+ libevdev_uinput_write_event (touchscreen, EV_ABS, ABS_MT_ORIENTATION, orientation);
1727
+ }
1728
+
1729
+
1730
+ auto scaled_x = (int ) std::lround ((x + touch_port.offset_x ) * ((float ) target_touch_port.width / (float ) touch_port.width ));
1731
+ auto scaled_y = (int ) std::lround ((y + touch_port.offset_y ) * ((float ) target_touch_port.height / (float ) touch_port.height ));
1732
+
1733
+
1734
+ // This reports touch events as a type B uinput touchscreen/tablet
1735
+ libevdev_uinput_write_event (touchscreen, EV_ABS, ABS_MT_SLOT, id);
1736
+ libevdev_uinput_write_event (touchscreen, EV_ABS, ABS_MT_TRACKING_ID, 99 );
1737
+ libevdev_uinput_write_event (touchscreen, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PEN);
1738
+ libevdev_uinput_write_event (touchscreen, EV_ABS, ABS_MT_POSITION_X, scaled_x);
1739
+ libevdev_uinput_write_event (touchscreen, EV_ABS, ABS_MT_POSITION_Y, scaled_y);
1740
+ libevdev_uinput_write_event (touchscreen, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
1741
+ libevdev_uinput_write_event (touchscreen, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
1742
+ libevdev_uinput_write_event (touchscreen, EV_ABS, ABS_MT_PRESSURE, pressure);
1743
+
1744
+ switch (pen.toolType ) {
1745
+ default :
1746
+ case LI_TOOL_TYPE_PEN:
1747
+ libevdev_uinput_write_event (touchscreen, EV_KEY, BTN_STYLUS, id != -1 ? 0 : 1 );
1748
+ break ;
1749
+ case LI_TOOL_TYPE_ERASER:
1750
+ libevdev_uinput_write_event (touchscreen, EV_KEY, BTN_STYLUS, id != -1 ? 0 : 1 );
1751
+ break ;
1752
+ case LI_TOOL_TYPE_UNKNOWN:
1753
+ // Leave tool flags alone
1754
+ break ;
1755
+ }
1756
+
1757
+ libevdev_uinput_write_event (touchscreen, EV_SYN, SYN_REPORT, 0 );
1686
1758
}
1687
1759
1688
1760
/* *
@@ -1817,6 +1889,8 @@ namespace platf {
1817
1889
libevdev_enable_property (dev.get (), INPUT_PROP_DIRECT);
1818
1890
1819
1891
libevdev_enable_event_type (dev.get (), EV_KEY);
1892
+ libevdev_enable_event_code (dev.get (), EV_KEY, BTN_STYLUS, nullptr );
1893
+ libevdev_enable_event_code (dev.get (), EV_KEY, BTN_STYLUS2, nullptr );
1820
1894
libevdev_enable_event_code (dev.get (), EV_KEY, BTN_TOUCH, nullptr );
1821
1895
1822
1896
input_absinfo mtslot {
0 commit comments