aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2022-04-08 09:47:25 +0800
committerPo Lu2022-04-08 09:47:25 +0800
commit1a1c5a6884a60ef2ffa98f3ee4af793eac985f80 (patch)
tree2697c3f6bd928783dff1e214fdf2d26e91819f17
parent6ac7fa7e78b84a6fbdf12a63d927ad55bacd8d91 (diff)
downloademacs-1a1c5a6884a60ef2ffa98f3ee4af793eac985f80.tar.gz
emacs-1a1c5a6884a60ef2ffa98f3ee4af793eac985f80.zip
Add code for determining the type of an input device
* doc/lispref/commands.texi (Command Loop Info): * etc/NEWS: Update documentation and announce `device-class'. * lisp/frame.el (x-device-class): (device-class): * lisp/term/x-win.el (x-device-class): New functions.
-rw-r--r--doc/lispref/commands.texi76
-rw-r--r--etc/NEWS7
-rw-r--r--lisp/frame.el61
-rw-r--r--lisp/term/x-win.el32
4 files changed, 173 insertions, 3 deletions
diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi
index 74bf0f48692..ace0c025512 100644
--- a/doc/lispref/commands.texi
+++ b/doc/lispref/commands.texi
@@ -1127,6 +1127,23 @@ frame, the value is the frame to which the event was redirected.
1127If the last event came from a keyboard macro, the value is @code{macro}. 1127If the last event came from a keyboard macro, the value is @code{macro}.
1128@end defvar 1128@end defvar
1129 1129
1130@cindex input devices
1131@cindex device names
1132Input events must come from somewhere; sometimes, that is a keyboard
1133macro, a signal, or `unread-command-events', but it is usually a
1134physical input device connected to a computer that is controlled by
1135the user. Those devices are referred to as @dfn{input devices}, and
1136Emacs associates each input event with the input device from which it
1137originated. They are identified by a name that is unique to each
1138input device.
1139
1140The ability to determine the precise input device used depends on the
1141details of each system. When that information is unavailable, Emacs
1142reports keyboard events as originating from the @samp{"Virtual core
1143keyboard"}, and other events as originating from the @samp{"Virtual
1144core pointer"}. (These values are used on every platform because the
1145X server reports them when detailed device information is not known.)
1146
1130@defvar last-event-device 1147@defvar last-event-device
1131This variable records the name of the input device from which the last 1148This variable records the name of the input device from which the last
1132input event read was generated. It is @code{nil} if no such device 1149input event read was generated. It is @code{nil} if no such device
@@ -1141,6 +1158,65 @@ keyboard"}, depending on whether the event was generated by a pointing
1141device (such as a mouse) or a keyboard. 1158device (such as a mouse) or a keyboard.
1142@end defvar 1159@end defvar
1143 1160
1161@defun device-class frame name
1162There are various different types of devices, which can be determined
1163from their names. This function can be used to determined the correct
1164type of the device @var{name} for an event originating from
1165@var{frame}.
1166
1167The return value is one of the following symbols (``device classes''):
1168
1169@table @code
1170@item core-keyboard
1171The core keyboard; this is means the device is a keyboard-like device,
1172but no other characteristics are unknown.
1173
1174@item core-pointer
1175The core pointer; this means the device is a pointing device, but no
1176other characteristics are known.
1177
1178@item mouse
1179A computer mouse.
1180
1181@item trackpoint
1182A trackpoint or joystick (or other similar control.)
1183
1184@item eraser
1185The other end of a stylus on a graphics tablet, or a standalone
1186eraser.
1187
1188@item pen
1189The pointed end of a pen on a graphics tablet, a stylus, or some other
1190similar device.
1191
1192@item puck
1193A device that looks like a computer mouse, but reports absolute
1194coordinates relative to some other surface.
1195
1196@item power-button
1197A power button or volume button (or other similar control.)
1198
1199@item keyboard
1200A computer keyboard.
1201
1202@item touchscreen
1203A computer touchpad.
1204
1205@item pad
1206A collection of sensitive buttons, rings, and strips commonly found
1207around a drawing tablet.
1208
1209@item touchpad
1210An indirect touch device such as a touchpad.
1211
1212@item piano
1213A musical instrument such as an electronic keyboard.
1214
1215@item test
1216A device used by the XTEST extension to report input.
1217@end table
1218@end defun
1219
1144@node Adjusting Point 1220@node Adjusting Point
1145@section Adjusting Point After Commands 1221@section Adjusting Point After Commands
1146@cindex adjusting point 1222@cindex adjusting point
diff --git a/etc/NEWS b/etc/NEWS
index 1043873f2d7..2fac893cc52 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1360,9 +1360,10 @@ functions.
1360* Lisp Changes in Emacs 29.1 1360* Lisp Changes in Emacs 29.1
1361 1361
1362+++ 1362+++
1363** New variable 'last-event-device'. 1363** New variable 'last-event-device' and new function 'device-class'.
1364On X Windows, this specifies the input extension device from which the 1364On X Windows, 'last-event-device' specifies the input extension device
1365last input event originated. 1365from which the last input event originated, and 'device-class' can be
1366used to determine the type of an input device.
1366 1367
1367+++ 1368+++
1368** 'track-mouse' can be a new value 'drag-source'. 1369** 'track-mouse' can be a new value 'drag-source'.
diff --git a/lisp/frame.el b/lisp/frame.el
index b681a971aa3..395fe8daad8 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -2433,6 +2433,67 @@ monitors."
2433 ,(display-mm-height display))) 2433 ,(display-mm-height display)))
2434 (frames . ,(frames-on-display-list display))))))))) 2434 (frames . ,(frames-on-display-list display)))))))))
2435 2435
2436(declare-function x-device-class (name) "x-win.el")
2437
2438(defun device-class (frame name)
2439 "Return the class of the device NAME for an event generated on FRAME.
2440NAME is a string that can be the value of `last-event-device', or
2441nil. FRAME is a window system frame, typically the value of
2442`last-event-frame' when `last-event-device' was set. On some
2443window systems, it can also be a display name or a terminal.
2444
2445The class of a device is one of the following symbols:
2446
2447 `core-keyboard' means the device is a keyboard-like device, but
2448 any other characteristics are unknown.
2449
2450 `core-pointer' means the device is a pointing device, but any
2451 other characteristics are unknown.
2452
2453 `mouse' means the device is a computer mouse.
2454
2455 `trackpoint' means the device is a joystick or trackpoint.
2456
2457 `eraser' means the device is an eraser, which is typically the
2458 other end of a stylus on a graphics tablet.
2459
2460 `pen' means the device is a stylus or some other similar
2461 device.
2462
2463 `puck' means the device is a device similar to a mouse, but
2464 reports absolute coordinates.
2465
2466 `power-button' means the device is a power button, volume
2467 button, or some similar control.
2468
2469 `keyboard' means the device is a keyboard.
2470
2471 `touchscreen' means the device is a touchscreen.
2472
2473 `pad' means the device is a collection of buttons and rings and
2474 strips commonly found in drawing tablets.
2475
2476 `touchpad' means the device is an indirect touch device, such
2477 as a touchpad.
2478
2479 `piano' means the device is a piano, or some other kind of
2480 musical instrument.
2481
2482 `test' means the device is used by the XTEST extension to
2483 report input.
2484
2485It can also be nil, which means the class of the device could not
2486be determined. Individual window systems may also return other
2487symbols."
2488 (let ((frame-type (framep-on-display frame)))
2489 (cond ((eq frame-type 'x)
2490 (x-device-class name))
2491 (t (cond
2492 ((string= name "Virtual core pointer")
2493 'core-pointer)
2494 ((string= name "Virtual core keyboard")
2495 'core-keyboard))))))
2496
2436 2497
2437;;;; Frame geometry values 2498;;;; Frame geometry values
2438 2499
diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el
index a71ae87e215..ac8b1f5df32 100644
--- a/lisp/term/x-win.el
+++ b/lisp/term/x-win.el
@@ -1583,6 +1583,38 @@ frames on all displays."
1583 (dnd-handle-movement position) 1583 (dnd-handle-movement position)
1584 (redisplay)) 1584 (redisplay))
1585 1585
1586(defun x-device-class (name)
1587 "Return the device class of NAME.
1588Users should not call this function; see `device-class' instead."
1589 (let ((downcased-name (downcase name)))
1590 (cond
1591 ((string-match-p "XTEST" name) 'test)
1592 ((string= "Virtual core pointer" name) 'core-pointer)
1593 ((string= "Virtual core keyboard" name) 'core-keyboard)
1594 ((string-match-p "eraser" downcased-name) 'eraser)
1595 ((string-match-p " pad" downcased-name) 'pad)
1596 ((or (or (string-match-p "wacom" downcased-name)
1597 (string-match-p "pen" downcased-name))
1598 (string-match-p "stylus" downcased-name))
1599 'pen)
1600 ((or (string-prefix-p "xwayland-touch:" name)
1601 (string-match-p "touchscreen" downcased-name))
1602 'touchscreen)
1603 ((or (string-match-p "trackpoint" downcased-name)
1604 (string-match-p "stick" downcased-name))
1605 'trackpoint)
1606 ((or (string-match-p "mouse" downcased-name)
1607 (string-match-p "optical" downcased-name)
1608 (string-match-p "pointer" downcased-name))
1609 'mouse)
1610 ((string-match-p "cursor" downcased-name) 'puck)
1611 ((string-match-p "keyboard" downcased-name) 'keyboard)
1612 ((string-match-p "button" downcased-name) 'power-button)
1613 ((string-match-p "touchpad" downcased-name) 'touchpad)
1614 ((or (string-match-p "midi" downcased-name)
1615 (string-match-p "piano" downcased-name))
1616 'piano))))
1617
1586(setq x-dnd-movement-function #'x-dnd-movement) 1618(setq x-dnd-movement-function #'x-dnd-movement)
1587(setq x-dnd-unsupported-drop-function #'x-dnd-handle-unsupported-drop) 1619(setq x-dnd-unsupported-drop-function #'x-dnd-handle-unsupported-drop)
1588 1620