diff options
| author | Po Lu | 2022-04-08 09:47:25 +0800 |
|---|---|---|
| committer | Po Lu | 2022-04-08 09:47:25 +0800 |
| commit | 1a1c5a6884a60ef2ffa98f3ee4af793eac985f80 (patch) | |
| tree | 2697c3f6bd928783dff1e214fdf2d26e91819f17 | |
| parent | 6ac7fa7e78b84a6fbdf12a63d927ad55bacd8d91 (diff) | |
| download | emacs-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.texi | 76 | ||||
| -rw-r--r-- | etc/NEWS | 7 | ||||
| -rw-r--r-- | lisp/frame.el | 61 | ||||
| -rw-r--r-- | lisp/term/x-win.el | 32 |
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. | |||
| 1127 | If the last event came from a keyboard macro, the value is @code{macro}. | 1127 | If 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 | ||
| 1132 | Input events must come from somewhere; sometimes, that is a keyboard | ||
| 1133 | macro, a signal, or `unread-command-events', but it is usually a | ||
| 1134 | physical input device connected to a computer that is controlled by | ||
| 1135 | the user. Those devices are referred to as @dfn{input devices}, and | ||
| 1136 | Emacs associates each input event with the input device from which it | ||
| 1137 | originated. They are identified by a name that is unique to each | ||
| 1138 | input device. | ||
| 1139 | |||
| 1140 | The ability to determine the precise input device used depends on the | ||
| 1141 | details of each system. When that information is unavailable, Emacs | ||
| 1142 | reports keyboard events as originating from the @samp{"Virtual core | ||
| 1143 | keyboard"}, and other events as originating from the @samp{"Virtual | ||
| 1144 | core pointer"}. (These values are used on every platform because the | ||
| 1145 | X server reports them when detailed device information is not known.) | ||
| 1146 | |||
| 1130 | @defvar last-event-device | 1147 | @defvar last-event-device |
| 1131 | This variable records the name of the input device from which the last | 1148 | This variable records the name of the input device from which the last |
| 1132 | input event read was generated. It is @code{nil} if no such device | 1149 | input 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 | |||
| 1141 | device (such as a mouse) or a keyboard. | 1158 | device (such as a mouse) or a keyboard. |
| 1142 | @end defvar | 1159 | @end defvar |
| 1143 | 1160 | ||
| 1161 | @defun device-class frame name | ||
| 1162 | There are various different types of devices, which can be determined | ||
| 1163 | from their names. This function can be used to determined the correct | ||
| 1164 | type of the device @var{name} for an event originating from | ||
| 1165 | @var{frame}. | ||
| 1166 | |||
| 1167 | The return value is one of the following symbols (``device classes''): | ||
| 1168 | |||
| 1169 | @table @code | ||
| 1170 | @item core-keyboard | ||
| 1171 | The core keyboard; this is means the device is a keyboard-like device, | ||
| 1172 | but no other characteristics are unknown. | ||
| 1173 | |||
| 1174 | @item core-pointer | ||
| 1175 | The core pointer; this means the device is a pointing device, but no | ||
| 1176 | other characteristics are known. | ||
| 1177 | |||
| 1178 | @item mouse | ||
| 1179 | A computer mouse. | ||
| 1180 | |||
| 1181 | @item trackpoint | ||
| 1182 | A trackpoint or joystick (or other similar control.) | ||
| 1183 | |||
| 1184 | @item eraser | ||
| 1185 | The other end of a stylus on a graphics tablet, or a standalone | ||
| 1186 | eraser. | ||
| 1187 | |||
| 1188 | @item pen | ||
| 1189 | The pointed end of a pen on a graphics tablet, a stylus, or some other | ||
| 1190 | similar device. | ||
| 1191 | |||
| 1192 | @item puck | ||
| 1193 | A device that looks like a computer mouse, but reports absolute | ||
| 1194 | coordinates relative to some other surface. | ||
| 1195 | |||
| 1196 | @item power-button | ||
| 1197 | A power button or volume button (or other similar control.) | ||
| 1198 | |||
| 1199 | @item keyboard | ||
| 1200 | A computer keyboard. | ||
| 1201 | |||
| 1202 | @item touchscreen | ||
| 1203 | A computer touchpad. | ||
| 1204 | |||
| 1205 | @item pad | ||
| 1206 | A collection of sensitive buttons, rings, and strips commonly found | ||
| 1207 | around a drawing tablet. | ||
| 1208 | |||
| 1209 | @item touchpad | ||
| 1210 | An indirect touch device such as a touchpad. | ||
| 1211 | |||
| 1212 | @item piano | ||
| 1213 | A musical instrument such as an electronic keyboard. | ||
| 1214 | |||
| 1215 | @item test | ||
| 1216 | A 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 |
| @@ -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'. |
| 1364 | On X Windows, this specifies the input extension device from which the | 1364 | On X Windows, 'last-event-device' specifies the input extension device |
| 1365 | last input event originated. | 1365 | from which the last input event originated, and 'device-class' can be |
| 1366 | used 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. | ||
| 2440 | NAME is a string that can be the value of `last-event-device', or | ||
| 2441 | nil. FRAME is a window system frame, typically the value of | ||
| 2442 | `last-event-frame' when `last-event-device' was set. On some | ||
| 2443 | window systems, it can also be a display name or a terminal. | ||
| 2444 | |||
| 2445 | The 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 | |||
| 2485 | It can also be nil, which means the class of the device could not | ||
| 2486 | be determined. Individual window systems may also return other | ||
| 2487 | symbols." | ||
| 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. | ||
| 1588 | Users 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 | ||