Mercurial > hg > xemacs-beta
comparison src/events.c @ 2828:a25c824ed558
[xemacs-hg @ 2005-06-26 18:04:49 by aidan]
Rename the ascii-character property, support more keysyms.
author | aidan |
---|---|
date | Sun, 26 Jun 2005 18:05:05 +0000 |
parents | 9f70af3ac939 |
children | ade0c13d91a3 |
comparison
equal
deleted
inserted
replaced
2827:936a6576c655 | 2828:a25c824ed558 |
---|---|
65 Lisp_Object Qbutton_event_p; | 65 Lisp_Object Qbutton_event_p; |
66 Lisp_Object Qmouse_event_p; | 66 Lisp_Object Qmouse_event_p; |
67 Lisp_Object Qprocess_event_p; | 67 Lisp_Object Qprocess_event_p; |
68 | 68 |
69 Lisp_Object Qkey_press, Qbutton_press, Qbutton_release, Qmisc_user; | 69 Lisp_Object Qkey_press, Qbutton_press, Qbutton_release, Qmisc_user; |
70 Lisp_Object Qascii_character; | 70 Lisp_Object Qcharacter_of_keysym, Qascii_character; |
71 | 71 |
72 | 72 |
73 /************************************************************************/ | 73 /************************************************************************/ |
74 /* definition of event object */ | 74 /* definition of event object */ |
75 /************************************************************************/ | 75 /************************************************************************/ |
1194 '(control h). It is clearly correct to do this conversion is the | 1194 '(control h). It is clearly correct to do this conversion is the |
1195 character was just read from a TTY, clearly incorrect inside of | 1195 character was just read from a TTY, clearly incorrect inside of |
1196 define-key, which must be able to handle all consoles. #### What about | 1196 define-key, which must be able to handle all consoles. #### What about |
1197 in other circumstances? #### Should the user have access to this flag? | 1197 in other circumstances? #### Should the user have access to this flag? |
1198 | 1198 |
1199 | |
1200 #### We need to go through and review all the flags in | 1199 #### We need to go through and review all the flags in |
1201 character_to_event() and event_to_character() and figure out exactly | 1200 character_to_event() and event_to_character() and figure out exactly |
1202 under what circumstances they should or should not be set, then go | 1201 under what circumstances they should or should not be set, then go |
1203 through and review all callers of character_to_event(), | 1202 through and review all callers of character_to_event(), |
1204 Fcharacter_to_event(), event_to_character(), and Fevent_to_character() | 1203 Fcharacter_to_event(), event_to_character(), and Fevent_to_character() |
1206 circumstances. | 1205 circumstances. |
1207 | 1206 |
1208 #### Some of this garbage, and some of the flags, could go away if we | 1207 #### Some of this garbage, and some of the flags, could go away if we |
1209 implemented the suggestion, originally from event-Xt.c: | 1208 implemented the suggestion, originally from event-Xt.c: |
1210 | 1209 |
1211 #### The way that keysym correspondence to characters should work: | 1210 [[ The way that keysym correspondence to characters should work: |
1212 - a Lisp_Event should contain a keysym AND a character slot. | 1211 - a Lisp_Event should contain a keysym AND a character slot. |
1213 - keybindings are tried with the keysym. If no binding can be found, | 1212 - keybindings are tried with the keysym. If no binding can be found, |
1214 and there is a corresponding character, call self-insert-command. | 1213 and there is a corresponding character, call self-insert-command. ]] |
1215 | 1214 |
1216 #### Nuke x-iso8859-1.el. | 1215 That's an X-specific way of thinking. All the other platforms--even |
1217 #### Nuke the Qascii_character property. | 1216 the TTY, make sure you've done (set-input-mode t nil 1) and set your |
1218 #### Nuke Vcharacter_set_property. | 1217 console coding system appropriately when checking--just use |
1219 | 1218 characters as emacs keysyms, and, together with defaulting to |
1220 This would apparently solve a lot of different problems. | 1219 self-insert-command if an unbound key with a character correspondence |
1221 */ | 1220 is typed, that works fine for them. (Yes, this ignores GTK.) |
1221 | |
1222 [[ [... snipping other suggestions which I've implemented.] | |
1223 Nuke the Qascii_character property. ]] | |
1224 | |
1225 Well, we've renamed it anyway--it was badly named. | |
1226 Qcharacter_of_keysym, here we go. It's really only with X11 that how | |
1227 to map between adiaeresis and (int-to-char #xE4), or ellipsis and | |
1228 whatever, becomes an issue, and IMO the property approach to this is | |
1229 fine. Aidan Kehoe, 2005-05-15. | |
1230 | |
1231 [[ This would apparently solve a lot of different problems. ]] | |
1232 | |
1233 I'd be interested to know what's left. Removing the allow-meta | |
1234 argument from event-to-character would be a Good Thing, IMO, but | |
1235 beyond that, I'm not sure what else there is to do wrt. key | |
1236 mappings. Of course, feedback from users of the Russian C-x facility | |
1237 is still needed. */ | |
1222 | 1238 |
1223 void | 1239 void |
1224 character_to_event (Ichar c, Lisp_Event *event, struct console *con, | 1240 character_to_event (Ichar c, Lisp_Event *event, struct console *con, |
1225 int use_console_meta_flag, | 1241 int use_console_meta_flag, |
1226 int USED_IF_TTY (do_backspace_mapping)) | 1242 int USED_IF_TTY (do_backspace_mapping)) |
1292 SET_EVENT_CHANNEL (event, wrap_console (con)); | 1308 SET_EVENT_CHANNEL (event, wrap_console (con)); |
1293 SET_EVENT_KEY_KEYSYM (event, (!NILP (k) ? k : make_char (c))); | 1309 SET_EVENT_KEY_KEYSYM (event, (!NILP (k) ? k : make_char (c))); |
1294 SET_EVENT_KEY_MODIFIERS (event, m); | 1310 SET_EVENT_KEY_MODIFIERS (event, m); |
1295 } | 1311 } |
1296 | 1312 |
1297 /* This variable controls what character name -> character code mapping | |
1298 we are using. Window-system-specific code sets this to some symbol, | |
1299 and we use that symbol as the plist key to convert keysyms into 8-bit | |
1300 codes. In this way one can have several character sets predefined and | |
1301 switch them by changing this. | |
1302 | |
1303 #### This is utterly bogus and should be removed. | |
1304 */ | |
1305 Lisp_Object Vcharacter_set_property; | |
1306 | |
1307 Ichar | 1313 Ichar |
1308 event_to_character (Lisp_Object event, | 1314 event_to_character (Lisp_Object event, |
1309 int allow_extra_modifiers, | 1315 int allow_extra_modifiers, |
1310 int allow_meta, | 1316 int allow_meta) |
1311 int map_device_key_names) | |
1312 { | 1317 { |
1313 Ichar c = 0; | 1318 Ichar c = 0; |
1314 Lisp_Object code; | 1319 Lisp_Object code; |
1315 | 1320 |
1316 if (XEVENT_TYPE (event) != key_press_event) | 1321 if (XEVENT_TYPE (event) != key_press_event) |
1317 { | 1322 { |
1318 assert (XEVENT_TYPE (event) != dead_event); | 1323 assert (XEVENT_TYPE (event) != dead_event); |
1319 return -1; | 1324 return -1; |
1320 } | 1325 } |
1321 if (!allow_extra_modifiers && | 1326 if (!allow_extra_modifiers && |
1322 XEVENT_KEY_MODIFIERS (event) & (XEMACS_MOD_SUPER|XEMACS_MOD_HYPER|XEMACS_MOD_ALT)) | 1327 XEVENT_KEY_MODIFIERS (event) & |
1328 (XEMACS_MOD_SUPER|XEMACS_MOD_HYPER|XEMACS_MOD_ALT)) | |
1323 return -1; | 1329 return -1; |
1324 if (CHAR_OR_CHAR_INTP (XEVENT_KEY_KEYSYM (event))) | 1330 if (CHAR_OR_CHAR_INTP (XEVENT_KEY_KEYSYM (event))) |
1325 c = XCHAR_OR_CHAR_INT (XEVENT_KEY_KEYSYM (event)); | 1331 c = XCHAR_OR_CHAR_INT (XEVENT_KEY_KEYSYM (event)); |
1326 else if (!SYMBOLP (XEVENT_KEY_KEYSYM (event))) | 1332 else if (!SYMBOLP (XEVENT_KEY_KEYSYM (event))) |
1327 ABORT (); | 1333 ABORT (); |
1328 else if (map_device_key_names && !NILP (Vcharacter_set_property) | |
1329 /* Allow window-system-specific extensibility of | |
1330 keysym->code mapping */ | |
1331 && CHAR_OR_CHAR_INTP (code = Fget (XEVENT_KEY_KEYSYM (event), | |
1332 Vcharacter_set_property, | |
1333 Qnil))) | |
1334 c = XCHAR_OR_CHAR_INT (code); | |
1335 else if (CHAR_OR_CHAR_INTP (code = Fget (XEVENT_KEY_KEYSYM (event), | 1334 else if (CHAR_OR_CHAR_INTP (code = Fget (XEVENT_KEY_KEYSYM (event), |
1336 Qascii_character, Qnil))) | 1335 Qcharacter_of_keysym, Qnil))) |
1337 c = XCHAR_OR_CHAR_INT (code); | 1336 c = XCHAR_OR_CHAR_INT (code); |
1338 else | 1337 else |
1339 return -1; | 1338 { |
1340 | 1339 Lisp_Object thekeysym = XEVENT_KEY_KEYSYM (event); |
1340 | |
1341 if (CHAR_OR_CHAR_INTP (code = Fget (thekeysym, Qascii_character, Qnil))) | |
1342 { | |
1343 extern Lisp_Object Qkey_mapping; | |
1344 | |
1345 c = XCHAR_OR_CHAR_INT (code); | |
1346 warn_when_safe(Qkey_mapping, Qwarning, | |
1347 "Obsolete key binding technique.\n" | |
1348 | |
1349 "Some code you're using bound %s to `self-insert-command' and messed around\n" | |
1350 "with its `ascii-character' property. Doing this is deprecated, and the code\n" | |
1351 "should be updated to use the `set-character-of-keysym' interface.\n" | |
1352 "If you're the one updating the code, first check if there's still a need\n" | |
1353 "for it; we support many more X11 keysyms out of the box now than we did\n" | |
1354 "in the past. ", XSTRING_DATA(XSYMBOL_NAME(thekeysym))); | |
1355 /* Only show the warning once for each keysym. */ | |
1356 Fput(thekeysym, Qcharacter_of_keysym, code); | |
1357 } | |
1358 else | |
1359 { | |
1360 return -1; | |
1361 } | |
1362 } | |
1341 if (XEVENT_KEY_MODIFIERS (event) & XEMACS_MOD_CONTROL) | 1363 if (XEVENT_KEY_MODIFIERS (event) & XEMACS_MOD_CONTROL) |
1342 { | 1364 { |
1343 if (c >= 'a' && c <= 'z') | 1365 if (c >= 'a' && c <= 'z') |
1344 c -= ('a' - 'A'); | 1366 c -= ('a' - 'A'); |
1345 else | 1367 else |
1363 c |= 0200; | 1385 c |= 0200; |
1364 } | 1386 } |
1365 return c; | 1387 return c; |
1366 } | 1388 } |
1367 | 1389 |
1368 DEFUN ("event-to-character", Fevent_to_character, 1, 4, 0, /* | 1390 DEFUN ("event-to-character", Fevent_to_character, 1, 3, 0, /* |
1369 Return the closest ASCII approximation to the given event object. | 1391 Return the closest character approximation to the given event object. |
1370 If the event isn't a keypress, this returns nil. | 1392 If the event isn't a keypress, this returns nil. |
1371 If the ALLOW-EXTRA-MODIFIERS argument is non-nil, then this is lenient in | 1393 If the ALLOW-EXTRA-MODIFIERS argument is non-nil, then this is lenient in |
1372 its translation; it will ignore modifier keys other than control and meta, | 1394 its translation; it will ignore modifier keys other than control and meta, |
1373 and will ignore the shift modifier on those characters which have no | 1395 and will ignore the shift modifier on those characters which have no |
1374 shifted ASCII equivalent (Control-Shift-A for example, will be mapped to | 1396 shifted ASCII equivalent (Control-Shift-A for example, will be mapped to |
1375 the same ASCII code as Control-A). | 1397 the same ASCII code as Control-A). |
1376 If the ALLOW-META argument is non-nil, then the Meta modifier will be | 1398 If the ALLOW-META argument is non-nil, then the Meta modifier will be |
1377 represented by turning on the high bit of the byte returned; otherwise, nil | 1399 represented by turning on the high bit of the byte returned; otherwise, nil |
1378 will be returned for events containing the Meta modifier. | 1400 will be returned for events containing the Meta modifier. |
1379 If the MAP-DEVICE-KEY-NAMES argument is non-nil, then named keysyms that | |
1380 represent printable characters will be converted to that character. This | |
1381 means, for example, that under X, where a circumflexed lowercase o returns | |
1382 a key with the name `ocircumflex' rather than the actual character, this | |
1383 name will be converted to the appropriate character. See | |
1384 `character-set-property' for some sense of how this works. #### This | |
1385 should not be exposed and may be removed at some point. | |
1386 Note that ALLOW-META may cause ambiguity between meta characters and | 1401 Note that ALLOW-META may cause ambiguity between meta characters and |
1387 Latin-1 characters. | 1402 Latin-1 characters. |
1388 */ | 1403 */ |
1389 (event, allow_extra_modifiers, allow_meta, map_device_key_names)) | 1404 (event, allow_extra_modifiers, allow_meta)) |
1390 { | 1405 { |
1391 Ichar c; | 1406 Ichar c; |
1392 CHECK_LIVE_EVENT (event); | 1407 CHECK_LIVE_EVENT (event); |
1393 c = event_to_character (event, | 1408 c = event_to_character (event, |
1394 !NILP (allow_extra_modifiers), | 1409 !NILP (allow_extra_modifiers), |
1395 !NILP (allow_meta), | 1410 !NILP (allow_meta)); |
1396 !NILP (map_device_key_names)); | |
1397 return c < 0 ? Qnil : make_char (c); | 1411 return c < 0 ? Qnil : make_char (c); |
1398 } | 1412 } |
1399 | 1413 |
1400 DEFUN ("character-to-event", Fcharacter_to_event, 1, 4, 0, /* | 1414 DEFUN ("character-to-event", Fcharacter_to_event, 1, 4, 0, /* |
1401 Convert KEY-DESCRIPTION into an event structure, replete with bucky bits. | 1415 Convert KEY-DESCRIPTION into an event structure, replete with bucky bits. |
2611 DEFSYMBOL (Qprocess_event_p); | 2625 DEFSYMBOL (Qprocess_event_p); |
2612 DEFSYMBOL (Qkey_press); | 2626 DEFSYMBOL (Qkey_press); |
2613 DEFSYMBOL (Qbutton_press); | 2627 DEFSYMBOL (Qbutton_press); |
2614 DEFSYMBOL (Qbutton_release); | 2628 DEFSYMBOL (Qbutton_release); |
2615 DEFSYMBOL (Qmisc_user); | 2629 DEFSYMBOL (Qmisc_user); |
2630 DEFSYMBOL (Qcharacter_of_keysym); | |
2616 DEFSYMBOL (Qascii_character); | 2631 DEFSYMBOL (Qascii_character); |
2617 | 2632 |
2618 defsymbol (&QKbackspace, "backspace"); | 2633 defsymbol (&QKbackspace, "backspace"); |
2619 defsymbol (&QKtab, "tab"); | 2634 defsymbol (&QKtab, "tab"); |
2620 defsymbol (&QKlinefeed, "linefeed"); | 2635 defsymbol (&QKlinefeed, "linefeed"); |
2632 } | 2647 } |
2633 | 2648 |
2634 void | 2649 void |
2635 vars_of_events (void) | 2650 vars_of_events (void) |
2636 { | 2651 { |
2637 DEFVAR_LISP ("character-set-property", &Vcharacter_set_property /* | 2652 } |
2638 This is used to map e.g. `ocircumflex' to the appropriate character under X. | |
2639 This value of this variable (a symbol, normally `x-iso8859-1' if not nil) | |
2640 if used to look up a property on the keysym in question, which should | |
2641 correspond to a character. | |
2642 | |
2643 #### This is way bogus and will be removed soon. | |
2644 | |
2645 The conversion between X keysyms and characters is now handled more or less | |
2646 automatically using XDisplayKeycodes(). | |
2647 */ ); | |
2648 Vcharacter_set_property = Qnil; | |
2649 } |