aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2022-11-06 19:37:02 +0800
committerPo Lu2022-11-06 19:39:01 +0800
commitf305d1ab3a913ce30cfb28fdce48d99d65caf256 (patch)
treed11ed5a30ae446b44731ee2b08c54fa20ce41915
parentcd296e19a2b1f77268a142977424c54cb94e633f (diff)
downloademacs-f305d1ab3a913ce30cfb28fdce48d99d65caf256.tar.gz
emacs-f305d1ab3a913ce30cfb28fdce48d99d65caf256.zip
Write more commentary on XI2 device management
* src/xterm.c (xi_populate_device_from_info): Take dpyinfo. Describe what master and slave devices are, how they represent seats, and how they are used to multiplex user input. Also simplify ifdefs and avoid looping over scroll classes on XI 2.0. (x_cache_xi_devices, handle_one_xevent): Adjust accordingly. (x_term_init): Set dpyinfo->xi2_version before calling x_cache_xi_devices.
-rw-r--r--src/xterm.c86
1 files changed, 73 insertions, 13 deletions
diff --git a/src/xterm.c b/src/xterm.c
index 545a95f7b24..abe9c7304e8 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -5317,7 +5317,8 @@ struct xi_known_valuator
5317#endif 5317#endif
5318 5318
5319static void 5319static void
5320xi_populate_device_from_info (struct xi_device_t *xi_device, 5320xi_populate_device_from_info (struct x_display_info *dpyinfo,
5321 struct xi_device_t *xi_device,
5321 XIDeviceInfo *device) 5322 XIDeviceInfo *device)
5322{ 5323{
5323#ifdef HAVE_XINPUT2_1 5324#ifdef HAVE_XINPUT2_1
@@ -5335,26 +5336,85 @@ xi_populate_device_from_info (struct xi_device_t *xi_device,
5335 USE_SAFE_ALLOCA; 5336 USE_SAFE_ALLOCA;
5336#endif 5337#endif
5337 5338
5339 /* Initialize generic information about the device: its ID, which
5340 buttons are currently pressed and thus presumably actively
5341 grabbing the device, what kind of device it is (master pointer,
5342 master keyboard, slave pointer, slave keyboard, or floating
5343 slave), and its attachment.
5344
5345 Here is a brief description of what device uses and attachments
5346 are. Under XInput 2, user input from individual input devices is
5347 multiplexed into specific seats before being delivered, with each
5348 seat corresponding to a single on-screen mouse pointer and having
5349 its own keyboard focus. Each seat consists of two virtual
5350 devices: the master keyboard and the master pointer, the first of
5351 which is used to report all keyboard input, with the other used
5352 to report all other input.
5353
5354 Input from each physical device (mouse, trackpad or keyboard) is
5355 then associated with that slave device's paired master device.
5356 For example, moving the device "Logitech USB Optical Mouse",
5357 enslaved by the master pointer device "Virtual core pointer",
5358 will result in movement of the mouse pointer associated with that
5359 master device's seat. If the pointer moves over an Emacs frame,
5360 then the frame will receive XI_Enter and XI_Motion events from
5361 that master pointer.
5362
5363 Likewise, keyboard input from the device "AT Translated Set 2
5364 keyboard", enslaved by the master keyboard device "Virtual core
5365 keyboard", will be reported to its seat's input focus window.
5366
5367 The device use describes what the device is. The meanings of
5368 MasterPointer, MasterKeyboard, SlavePointer and SlaveKeyboard
5369 should be obvious. FloatingSlave means the device is a slave
5370 device that is not associated with any seat, and thus generates
5371 no input.
5372
5373 The device attachment is a device ID whose meaning varies
5374 depending on the device use. If the device is a master device,
5375 then the attachment is the device ID of the other device in its
5376 seat (the master keyboard for master pointer devices, and vice
5377 versa). Otherwise, it is the ID of the master device the slave
5378 device is attached to. For slave devices not attached to any
5379 seat, its value is undefined. */
5380
5338 xi_device->device_id = device->deviceid; 5381 xi_device->device_id = device->deviceid;
5339 xi_device->grab = 0; 5382 xi_device->grab = 0;
5340
5341#ifdef HAVE_XINPUT2_1
5342 actual_valuator_count = 0;
5343 xi_device->valuators = xnmalloc (device->num_classes,
5344 sizeof *xi_device->valuators);
5345 values = NULL;
5346#endif
5347
5348 xi_device->use = device->use; 5383 xi_device->use = device->use;
5349 xi_device->name = build_string (device->name); 5384 xi_device->name = build_string (device->name);
5350 xi_device->attachment = device->attachment; 5385 xi_device->attachment = device->attachment;
5351 5386
5387 /* Clear the list of active touch points on the device, which are
5388 individual touches tracked by a touchscreen. */
5389
5352#ifdef HAVE_XINPUT2_2 5390#ifdef HAVE_XINPUT2_2
5353 xi_device->touchpoints = NULL; 5391 xi_device->touchpoints = NULL;
5354 xi_device->direct_p = false; 5392 xi_device->direct_p = false;
5355#endif 5393#endif
5356 5394
5357#ifdef HAVE_XINPUT2_1 5395#ifdef HAVE_XINPUT2_1
5396 if (!dpyinfo->xi2_version)
5397 {
5398 /* Skip everything below as there are no classes of interest on
5399 XI 2.0 servers. */
5400 xi_device->valuators = NULL;
5401 xi_device->scroll_valuator_count = 0;
5402
5403 return;
5404 }
5405
5406 actual_valuator_count = 0;
5407 xi_device->valuators = xnmalloc (device->num_classes,
5408 sizeof *xi_device->valuators);
5409 values = NULL;
5410
5411 /* Initialize device info based on a list of "device classes".
5412 Device classes are little pieces of information associated with a
5413 device. Emacs is interested in scroll valuator information and
5414 touch handling information, which respectively describe the axes
5415 (if any) along which the device's scroll wheel rotates, and how
5416 the device reports touch input. */
5417
5358 for (c = 0; c < device->num_classes; ++c) 5418 for (c = 0; c < device->num_classes; ++c)
5359 { 5419 {
5360 switch (device->classes[c]->type) 5420 switch (device->classes[c]->type)
@@ -5474,7 +5534,8 @@ x_cache_xi_devices (struct x_display_info *dpyinfo)
5474 for (i = 0; i < ndevices; ++i) 5534 for (i = 0; i < ndevices; ++i)
5475 { 5535 {
5476 if (infos[i].enabled) 5536 if (infos[i].enabled)
5477 xi_populate_device_from_info (&dpyinfo->devices[actual_devices++], 5537 xi_populate_device_from_info (dpyinfo,
5538 &dpyinfo->devices[actual_devices++],
5478 &infos[i]); 5539 &infos[i]);
5479 } 5540 }
5480 5541
@@ -23607,7 +23668,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
23607 memset (dpyinfo->devices + dpyinfo->num_devices - 1, 23668 memset (dpyinfo->devices + dpyinfo->num_devices - 1,
23608 0, sizeof *dpyinfo->devices); 23669 0, sizeof *dpyinfo->devices);
23609 device = &dpyinfo->devices[dpyinfo->num_devices - 1]; 23670 device = &dpyinfo->devices[dpyinfo->num_devices - 1];
23610 xi_populate_device_from_info (device, info); 23671 xi_populate_device_from_info (dpyinfo, device, info);
23611 } 23672 }
23612 23673
23613 if (info) 23674 if (info)
@@ -29608,11 +29669,10 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
29608 xi_select_hierarchy_events (dpyinfo); 29669 xi_select_hierarchy_events (dpyinfo);
29609#endif 29670#endif
29610 29671
29672 dpyinfo->xi2_version = minor;
29611 x_cache_xi_devices (dpyinfo); 29673 x_cache_xi_devices (dpyinfo);
29612 } 29674 }
29613 } 29675 }
29614
29615 dpyinfo->xi2_version = minor;
29616 skip_xi_setup: 29676 skip_xi_setup:
29617 ; 29677 ;
29618#endif 29678#endif