aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2024-06-01 13:53:37 +0800
committerPo Lu2024-06-01 13:53:37 +0800
commitb1692e23edc32ce8938d3af200c0c42c8aa6b313 (patch)
tree091eed974b2f34ae49d4611b4c3af2a5ebac7292 /src
parent0cb511b33bc96fc30d8e5286a474b4eea54817e3 (diff)
downloademacs-b1692e23edc32ce8938d3af200c0c42c8aa6b313.tar.gz
emacs-b1692e23edc32ce8938d3af200c0c42c8aa6b313.zip
On X, avoid reporting unrepresentable touch IDs to Lisp
* src/xterm.c (xi_link_touch_point): Assign a Lisp-representable identifier to the new touch point and return the same. (xi_unlink_touch_point): New arg LOCAL_DETAIL. Return such an identifier if there is a matching touch point record. (handle_one_xevent): Adjust as is proper. * src/xterm.h (struct xi_touch_point_t) <local_detail>: New field. Reorder fields for alignment.
Diffstat (limited to 'src')
-rw-r--r--src/xterm.c44
-rw-r--r--src/xterm.h15
2 files changed, 40 insertions, 19 deletions
diff --git a/src/xterm.c b/src/xterm.c
index 11ef9a4bd94..2f5e54f63d5 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -5820,37 +5820,50 @@ xi_device_from_id (struct x_display_info *dpyinfo, int deviceid)
5820#ifdef HAVE_XINPUT2_2 5820#ifdef HAVE_XINPUT2_2
5821 5821
5822/* Record a touch sequence with the identifier DETAIL from the given 5822/* Record a touch sequence with the identifier DETAIL from the given
5823 FRAME on the specified DEVICE. Round X and Y and record them as 5823 FRAME on the specified DEVICE. Round X and Y and record them as its
5824 its current position. */ 5824 current position, assign an identifier to the touch sequence suitable
5825 for reporting to Lisp, and return the same. */
5825 5826
5826static void 5827static EMACS_INT
5827xi_link_touch_point (struct xi_device_t *device, 5828xi_link_touch_point (struct xi_device_t *device,
5828 int detail, double x, double y, 5829 int detail, double x, double y,
5829 struct frame *frame) 5830 struct frame *frame)
5830{ 5831{
5831 struct xi_touch_point_t *touchpoint; 5832 struct xi_touch_point_t *touchpoint;
5833 static EMACS_INT local_detail;
5834
5835 /* Assign an identifier suitable for reporting to Lisp. On builds
5836 with 64-bit Lisp_Object, this is largely a theoretical problem, but
5837 CARD32s easily overflow 32-bit systems, as they are not specific to
5838 X clients (e.g. Emacs) but grow uniformly across all of them. */
5839
5840 if (FIXNUM_OVERFLOW_P (local_detail))
5841 local_detail = 0;
5832 5842
5833 touchpoint = xmalloc (sizeof *touchpoint); 5843 touchpoint = xmalloc (sizeof *touchpoint);
5834 touchpoint->next = device->touchpoints; 5844 touchpoint->next = device->touchpoints;
5835 touchpoint->x = lrint (x); 5845 touchpoint->x = lrint (x);
5836 touchpoint->y = lrint (y); 5846 touchpoint->y = lrint (y);
5837 touchpoint->number = detail; 5847 touchpoint->number = detail;
5848 touchpoint->local_detail = local_detail++;
5838 touchpoint->frame = frame; 5849 touchpoint->frame = frame;
5839 touchpoint->ownership = TOUCH_OWNERSHIP_NONE; 5850 touchpoint->ownership = TOUCH_OWNERSHIP_NONE;
5840
5841 device->touchpoints = touchpoint; 5851 device->touchpoints = touchpoint;
5852 return touchpoint->local_detail;
5842} 5853}
5843 5854
5844/* Free and remove the touch sequence with the identifier DETAIL. 5855/* Free and remove the touch sequence with the identifier DETAIL.
5845 DEVICE is the device in which the touch sequence should be 5856 DEVICE is the device in which the touch sequence should be
5846 recorded. 5857 recorded. If such a touch sequence exists, return its local
5858 identifier in *LOCAL_DETAIL.
5847 5859
5848 Value is 0 if no touch sequence by that identifier exists inside 5860 Value is 0 if no touch sequence by that identifier exists inside
5849 DEVICE, 1 if a touch sequence has been found but is not owned by 5861 DEVICE, 1 if a touch sequence has been found but is not owned by
5850 Emacs, and 2 otherwise. */ 5862 Emacs, and 2 otherwise. */
5851 5863
5852static int 5864static int
5853xi_unlink_touch_point (int detail, struct xi_device_t *device) 5865xi_unlink_touch_point (int detail, struct xi_device_t *device,
5866 EMACS_INT *local_detail)
5854{ 5867{
5855 struct xi_touch_point_t *last, *tem; 5868 struct xi_touch_point_t *last, *tem;
5856 enum xi_touch_ownership ownership; 5869 enum xi_touch_ownership ownership;
@@ -5866,6 +5879,7 @@ xi_unlink_touch_point (int detail, struct xi_device_t *device)
5866 last->next = tem->next; 5879 last->next = tem->next;
5867 5880
5868 ownership = tem->ownership; 5881 ownership = tem->ownership;
5882 *local_detail = tem->local_detail;
5869 xfree (tem); 5883 xfree (tem);
5870 5884
5871 if (ownership == TOUCH_OWNERSHIP_SELF) 5885 if (ownership == TOUCH_OWNERSHIP_SELF)
@@ -24781,6 +24795,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
24781#ifdef HAVE_GTK3 24795#ifdef HAVE_GTK3
24782 GdkRectangle test_rect; 24796 GdkRectangle test_rect;
24783#endif 24797#endif
24798 EMACS_INT local_detail;
24784 device = xi_device_from_id (dpyinfo, xev->deviceid); 24799 device = xi_device_from_id (dpyinfo, xev->deviceid);
24785 source = xi_device_from_id (dpyinfo, xev->sourceid); 24800 source = xi_device_from_id (dpyinfo, xev->sourceid);
24786 x_display_set_last_user_time (dpyinfo, xev->time, 24801 x_display_set_last_user_time (dpyinfo, xev->time,
@@ -24905,16 +24920,17 @@ handle_one_xevent (struct x_display_info *dpyinfo,
24905 24920
24906 if (!x_had_errors_p (dpyinfo->display)) 24921 if (!x_had_errors_p (dpyinfo->display))
24907 { 24922 {
24908 xi_link_touch_point (device, xev->detail, 24923 local_detail
24909 xev->event_x, 24924 = xi_link_touch_point (device, xev->detail,
24910 xev->event_y, f); 24925 xev->event_x,
24926 xev->event_y, f);
24911 24927
24912 inev.ie.kind = TOUCHSCREEN_BEGIN_EVENT; 24928 inev.ie.kind = TOUCHSCREEN_BEGIN_EVENT;
24913 inev.ie.timestamp = xev->time; 24929 inev.ie.timestamp = xev->time;
24914 XSETFRAME (inev.ie.frame_or_window, f); 24930 XSETFRAME (inev.ie.frame_or_window, f);
24915 XSETINT (inev.ie.x, lrint (xev->event_x)); 24931 XSETINT (inev.ie.x, lrint (xev->event_x));
24916 XSETINT (inev.ie.y, lrint (xev->event_y)); 24932 XSETINT (inev.ie.y, lrint (xev->event_y));
24917 XSETINT (inev.ie.arg, xev->detail); 24933 XSETINT (inev.ie.arg, local_detail);
24918 24934
24919 if (source) 24935 if (source)
24920 inev.ie.device = source->name; 24936 inev.ie.device = source->name;
@@ -25032,7 +25048,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
25032 { 25048 {
25033 if (touchpoint->frame == f) 25049 if (touchpoint->frame == f)
25034 arg = Fcons (list3i (touchpoint->x, touchpoint->y, 25050 arg = Fcons (list3i (touchpoint->x, touchpoint->y,
25035 lrint (touchpoint->number)), 25051 touchpoint->local_detail),
25036 arg); 25052 arg);
25037 } 25053 }
25038 25054
@@ -25049,6 +25065,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
25049 { 25065 {
25050 struct xi_device_t *device, *source; 25066 struct xi_device_t *device, *source;
25051 int state; 25067 int state;
25068 EMACS_INT local_detail;
25052 25069
25053 device = xi_device_from_id (dpyinfo, xev->deviceid); 25070 device = xi_device_from_id (dpyinfo, xev->deviceid);
25054 source = xi_device_from_id (dpyinfo, xev->sourceid); 25071 source = xi_device_from_id (dpyinfo, xev->sourceid);
@@ -25064,7 +25081,8 @@ handle_one_xevent (struct x_display_info *dpyinfo,
25064 if (!device || device->use == XIMasterPointer) 25081 if (!device || device->use == XIMasterPointer)
25065 goto XI_OTHER; 25082 goto XI_OTHER;
25066 25083
25067 state = xi_unlink_touch_point (xev->detail, device); 25084 state = xi_unlink_touch_point (xev->detail, device,
25085 &local_detail);
25068 25086
25069 if (state) 25087 if (state)
25070 { 25088 {
@@ -25079,7 +25097,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
25079 XSETFRAME (inev.ie.frame_or_window, f); 25097 XSETFRAME (inev.ie.frame_or_window, f);
25080 XSETINT (inev.ie.x, lrint (xev->event_x)); 25098 XSETINT (inev.ie.x, lrint (xev->event_x));
25081 XSETINT (inev.ie.y, lrint (xev->event_y)); 25099 XSETINT (inev.ie.y, lrint (xev->event_y));
25082 XSETINT (inev.ie.arg, xev->detail); 25100 XSETINT (inev.ie.arg, local_detail);
25083 25101
25084 if (source) 25102 if (source)
25085 inev.ie.device = source->name; 25103 inev.ie.device = source->name;
diff --git a/src/xterm.h b/src/xterm.h
index bf402de326b..8d5c9917749 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -305,6 +305,15 @@ enum xi_touch_ownership
305 305
306struct xi_touch_point_t 306struct xi_touch_point_t
307{ 307{
308 /* The detail code reported to Lisp. */
309 EMACS_INT local_detail;
310
311 /* The frame associated with this touch point. */
312 struct frame *frame;
313
314 /* The next touch point in this list. */
315 struct xi_touch_point_t *next;
316
308 /* The touchpoint detail. */ 317 /* The touchpoint detail. */
309 int number; 318 int number;
310 319
@@ -314,12 +323,6 @@ struct xi_touch_point_t
314 323
315 /* The last known rounded X and Y positions of the touchpoint. */ 324 /* The last known rounded X and Y positions of the touchpoint. */
316 int x, y; 325 int x, y;
317
318 /* The frame associated with this touch point. */
319 struct frame *frame;
320
321 /* The next touch point in this list. */
322 struct xi_touch_point_t *next;
323}; 326};
324 327
325#endif 328#endif