Mercurial > emacs
comparison src/keyboard.c @ 1821:04fb1d3d6992
JimB's changes since January 18th
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Tue, 26 Jan 1993 01:58:16 +0000 |
parents | 456ebec04db7 |
children | 2cc82d6070e2 |
comparison
equal
deleted
inserted
replaced
1820:b95bdb97c3e8 | 1821:04fb1d3d6992 |
---|---|
150 Lisp_Object last_nonmenu_event; | 150 Lisp_Object last_nonmenu_event; |
151 | 151 |
152 /* Last input character read for any purpose. */ | 152 /* Last input character read for any purpose. */ |
153 Lisp_Object last_input_char; | 153 Lisp_Object last_input_char; |
154 | 154 |
155 /* If not Qnil, an object to be read as the next command input. */ | 155 /* If not Qnil, a list of objects to be read as subsequent command input. */ |
156 Lisp_Object unread_command_event; | 156 Lisp_Object unread_command_events; |
157 | 157 |
158 /* If not Qnil, this is a switch-frame event which we decided to put | 158 /* If not Qnil, this is a switch-frame event which we decided to put |
159 off until the end of a key sequence. This should be read as the | 159 off until the end of a key sequence. This should be read as the |
160 next command input, after any unread_command_event. | 160 next command input, after any unread_command_events. |
161 | 161 |
162 read_key_sequence uses this to delay switch-frame events until the | 162 read_key_sequence uses this to delay switch-frame events until the |
163 end of the key sequence; Fread_char uses it to put off switch-frame | 163 end of the key sequence; Fread_char uses it to put off switch-frame |
164 events until a non-ASCII event is acceptable as input. */ | 164 events until a non-ASCII event is acceptable as input. */ |
165 Lisp_Object unread_switch_frame; | 165 Lisp_Object unread_switch_frame; |
865 echo_area_glyphs = 0; | 865 echo_area_glyphs = 0; |
866 no_direct = 1; | 866 no_direct = 1; |
867 if (!NILP (Vquit_flag)) | 867 if (!NILP (Vquit_flag)) |
868 { | 868 { |
869 Vquit_flag = Qnil; | 869 Vquit_flag = Qnil; |
870 unread_command_event = make_number (quit_char); | 870 unread_command_events = Fcons (make_number (quit_char), Qnil); |
871 } | 871 } |
872 } | 872 } |
873 | 873 |
874 #ifdef C_ALLOCA | 874 #ifdef C_ALLOCA |
875 alloca (0); /* Cause a garbage collection now */ | 875 alloca (0); /* Cause a garbage collection now */ |
1143 { | 1143 { |
1144 register Lisp_Object c; | 1144 register Lisp_Object c; |
1145 int count; | 1145 int count; |
1146 jmp_buf save_jump; | 1146 jmp_buf save_jump; |
1147 | 1147 |
1148 if (!NILP (unread_command_event)) | 1148 if (CONSP (unread_command_events)) |
1149 { | 1149 { |
1150 c = unread_command_event; | 1150 c = XCONS (unread_command_events)->car; |
1151 unread_command_event = Qnil; | 1151 unread_command_events = XCONS (unread_command_events)->cdr; |
1152 | 1152 |
1153 if (this_command_key_count == 0) | 1153 if (this_command_key_count == 0) |
1154 goto reread_first; | 1154 goto reread_first; |
1155 else | 1155 else |
1156 goto reread; | 1156 goto reread; |
1227 Lisp_Object tem0; | 1227 Lisp_Object tem0; |
1228 | 1228 |
1229 /* After a mouse event, start echoing right away. | 1229 /* After a mouse event, start echoing right away. |
1230 This is because we are probably about to display a menu, | 1230 This is because we are probably about to display a menu, |
1231 and we don't want to delay before doing so. */ | 1231 and we don't want to delay before doing so. */ |
1232 if (XTYPE (prev_event) == Lisp_Cons) | 1232 if (EVENT_HAS_PARAMETERS (prev_event)) |
1233 echo (); | 1233 echo (); |
1234 else | 1234 else |
1235 { | 1235 { |
1236 tem0 = sit_for (echo_keystrokes, 0, 1, 1); | 1236 tem0 = sit_for (echo_keystrokes, 0, 1, 1); |
1237 if (EQ (tem0, Qt)) | 1237 if (EQ (tem0, Qt)) |
1878 case mouse_click: | 1878 case mouse_click: |
1879 case scrollbar_click: | 1879 case scrollbar_click: |
1880 { | 1880 { |
1881 int button = XFASTINT (event->code); | 1881 int button = XFASTINT (event->code); |
1882 Lisp_Object position; | 1882 Lisp_Object position; |
1883 Lisp_Object *start_pos; | 1883 Lisp_Object *start_pos_ptr; |
1884 Lisp_Object start_pos; | |
1884 | 1885 |
1885 if (button < 0 || button >= NUM_MOUSE_BUTTONS) | 1886 if (button < 0 || button >= NUM_MOUSE_BUTTONS) |
1886 abort (); | 1887 abort (); |
1887 | 1888 |
1888 /* Build the position as appropriate for this mouse click. */ | 1889 /* Build the position as appropriate for this mouse click. */ |
1897 | 1898 |
1898 if (XTYPE (window) != Lisp_Window) | 1899 if (XTYPE (window) != Lisp_Window) |
1899 posn = Qnil; | 1900 posn = Qnil; |
1900 else | 1901 else |
1901 { | 1902 { |
1903 XSETINT (event->x, | |
1904 (XINT (event->x) - XINT (XWINDOW (window)->left))); | |
1905 XSETINT (event->y, | |
1906 (XINT (event->y) - XINT (XWINDOW (window)->top))); | |
1907 | |
1902 if (part == 1) | 1908 if (part == 1) |
1903 posn = Qmode_line; | 1909 posn = Qmode_line; |
1904 else if (part == 2) | 1910 else if (part == 2) |
1905 posn = Qvertical_line; | 1911 posn = Qvertical_line; |
1906 else | 1912 else |
1907 { | 1913 XSET (posn, Lisp_Int, |
1908 XSETINT (event->x, (XINT (event->x) | 1914 buffer_posn_from_coords (XWINDOW (window), |
1909 - XINT (XWINDOW (window)->left))); | 1915 XINT (event->x), |
1910 XSETINT (event->y, (XINT (event->y) | 1916 XINT (event->y))); |
1911 - XINT (XWINDOW (window)->top))); | |
1912 XSET (posn, Lisp_Int, | |
1913 buffer_posn_from_coords (XWINDOW (window), | |
1914 XINT (event->x), | |
1915 XINT (event->y))); | |
1916 } | |
1917 } | 1917 } |
1918 | 1918 |
1919 position = | 1919 position = |
1920 Fcons (window, | 1920 Fcons (window, |
1921 Fcons (posn, | 1921 Fcons (posn, |
1936 Fcons (make_number (event->timestamp), | 1936 Fcons (make_number (event->timestamp), |
1937 Fcons (part, | 1937 Fcons (part, |
1938 Qnil))))); | 1938 Qnil))))); |
1939 } | 1939 } |
1940 | 1940 |
1941 start_pos = &XVECTOR (button_down_location)->contents[button]; | 1941 start_pos_ptr = &XVECTOR (button_down_location)->contents[button]; |
1942 | |
1943 start_pos = *start_pos_ptr; | |
1944 *start_pos_ptr = Qnil; | |
1942 | 1945 |
1943 /* If this is a button press, squirrel away the location, so | 1946 /* If this is a button press, squirrel away the location, so |
1944 we can decide later whether it was a click or a drag. */ | 1947 we can decide later whether it was a click or a drag. */ |
1945 if (event->modifiers & down_modifier) | 1948 if (event->modifiers & down_modifier) |
1946 *start_pos = Fcopy_alist (position); | 1949 *start_pos_ptr = Fcopy_alist (position); |
1947 | 1950 |
1948 /* Now we're releasing a button - check the co-ordinates to | 1951 /* Now we're releasing a button - check the co-ordinates to |
1949 see if this was a click or a drag. */ | 1952 see if this was a click or a drag. */ |
1950 else if (event->modifiers & up_modifier) | 1953 else if (event->modifiers & up_modifier) |
1951 { | 1954 { |
1952 Lisp_Object down = Fnth (make_number (2), *start_pos); | 1955 /* Is there a start position stored at all for this |
1953 | 1956 button? |
1954 /* The third element of every position should be the (x,y) | 1957 |
1955 pair. */ | 1958 It would be nice if we could assume that if we're |
1956 if (! CONSP (down)) | 1959 getting a button release, we must therefore have gotten |
1957 abort (); | 1960 a button press. Unfortunately, the X menu code thwarts |
1958 | 1961 this assumption, so we'll have to be more robust. We |
1962 treat a button release with no stored start position as | |
1963 a click. */ | |
1959 event->modifiers &= ~up_modifier; | 1964 event->modifiers &= ~up_modifier; |
1960 event->modifiers |= ((EQ (event->x, XCONS (down)->car) | 1965 if (XTYPE (start_pos) != Lisp_Cons) |
1961 && EQ (event->y, XCONS (down)->cdr)) | 1966 event->modifiers |= click_modifier; |
1962 ? click_modifier | 1967 else |
1963 : drag_modifier); | 1968 { |
1969 /* The third element of every position should be the (x,y) | |
1970 pair. */ | |
1971 Lisp_Object down = Fnth (make_number (2), start_pos); | |
1972 | |
1973 event->modifiers |= ((EQ (event->x, XCONS (down)->car) | |
1974 && EQ (event->y, XCONS (down)->cdr)) | |
1975 ? click_modifier | |
1976 : drag_modifier); | |
1977 } | |
1964 } | 1978 } |
1965 else | 1979 else |
1966 /* Every mouse event should either have the down_modifier or | 1980 /* Every mouse event should either have the down_modifier or |
1967 the up_modifier set. */ | 1981 the up_modifier set. */ |
1968 abort (); | 1982 abort (); |
1976 lispy_mouse_names, &mouse_syms, | 1990 lispy_mouse_names, &mouse_syms, |
1977 (sizeof (lispy_mouse_names) | 1991 (sizeof (lispy_mouse_names) |
1978 / sizeof (lispy_mouse_names[0]))); | 1992 / sizeof (lispy_mouse_names[0]))); |
1979 | 1993 |
1980 if (event->modifiers & drag_modifier) | 1994 if (event->modifiers & drag_modifier) |
1981 { | 1995 return Fcons (head, |
1982 Lisp_Object lispy_event = | 1996 Fcons (start_pos, |
1983 Fcons (head, | 1997 Fcons (position, |
1984 Fcons (*start_pos, | 1998 Qnil))); |
1985 Fcons (position, | |
1986 Qnil))); | |
1987 | |
1988 /* Allow this to be GC'd. */ | |
1989 *start_pos = Qnil; | |
1990 | |
1991 return lispy_event; | |
1992 } | |
1993 else | 1999 else |
1994 return Fcons (head, | 2000 return Fcons (head, |
1995 Fcons (position, | 2001 Fcons (position, |
1996 Qnil)); | 2002 Qnil)); |
1997 } | 2003 } |
2451 | 2457 |
2452 /* Apply modifiers to that symbol. */ | 2458 /* Apply modifiers to that symbol. */ |
2453 return apply_modifiers (modifiers, *slot); | 2459 return apply_modifiers (modifiers, *slot); |
2454 } | 2460 } |
2455 | 2461 |
2456 | |
2457 DEFUN ("mouse-click-p", Fmouse_click_p, Smouse_click_p, 1, 1, 0, | |
2458 "Return non-nil iff OBJECT is a representation of a mouse event.\n\ | |
2459 A mouse event is a list of five elements whose car is a symbol of the\n\ | |
2460 form <MODIFIERS>mouse-<DIGIT>. I hope this is a temporary hack.") | |
2461 (object) | |
2462 Lisp_Object object; | |
2463 { | |
2464 if (EVENT_HAS_PARAMETERS (object) | |
2465 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (object)), | |
2466 Qmouse_click)) | |
2467 return Qt; | |
2468 else | |
2469 return Qnil; | |
2470 } | |
2471 | 2462 |
2472 /* Store into *addr a value nonzero if terminal input chars are available. | 2463 /* Store into *addr a value nonzero if terminal input chars are available. |
2473 Serves the purpose of ioctl (0, FIONREAD, addr) | 2464 Serves the purpose of ioctl (0, FIONREAD, addr) |
2474 but works even if FIONREAD does not exist. | 2465 but works even if FIONREAD does not exist. |
2475 (In fact, this may actually read some input.) */ | 2466 (In fact, this may actually read some input.) */ |
2684 | 2675 |
2685 static int echo_flag; | 2676 static int echo_flag; |
2686 static int echo_now; | 2677 static int echo_now; |
2687 | 2678 |
2688 /* Read a character like read_char but optionally prompt based on maps | 2679 /* Read a character like read_char but optionally prompt based on maps |
2689 in the array MAPS. NMAPS is the length of MAPS. | 2680 in the array MAPS. NMAPS is the length of MAPS. Return nil if we |
2681 decided not to read a character, because there are no menu items in | |
2682 MAPS. | |
2690 | 2683 |
2691 PREV_EVENT is the previous input event, or nil if we are reading | 2684 PREV_EVENT is the previous input event, or nil if we are reading |
2692 the first event of a key sequence. | 2685 the first event of a key sequence. |
2693 | 2686 |
2694 If USED_MOUSE_MENU is non-zero, then we set *USED_MOUSE_MENU to 1 | 2687 If USED_MOUSE_MENU is non-zero, then we set *USED_MOUSE_MENU to 1 |
2728 if (!NILP (name)) | 2721 if (!NILP (name)) |
2729 break; | 2722 break; |
2730 } | 2723 } |
2731 | 2724 |
2732 /* If we don't have any menus, just read a character normally. */ | 2725 /* If we don't have any menus, just read a character normally. */ |
2733 if (NILP (name)) | 2726 if (mapno >= nmaps) |
2734 return Qnil; | 2727 return Qnil; |
2735 | 2728 |
2736 #ifdef HAVE_X_WINDOW | 2729 #ifdef HAVE_X_WINDOWS |
2737 #ifndef NO_X_MENU | 2730 #ifdef HAVE_X_MENU |
2738 /* If we got to this point via a mouse click, | 2731 /* If we got to this point via a mouse click, |
2739 use a real menu for mouse selection. */ | 2732 use a real menu for mouse selection. */ |
2740 if (XTYPE (prev_event) == Lisp_Cons) | 2733 if (EVENT_HAS_PARAMETERS (prev_event)) |
2741 { | 2734 { |
2742 /* Display the menu and get the selection. */ | 2735 /* Display the menu and get the selection. */ |
2743 Lisp_Object *realmaps | 2736 Lisp_Object *realmaps |
2744 = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); | 2737 = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); |
2745 Lisp_Object value; | 2738 Lisp_Object value; |
2755 XSET (value, Lisp_Int, quit_char); | 2748 XSET (value, Lisp_Int, quit_char); |
2756 if (used_mouse_menu) | 2749 if (used_mouse_menu) |
2757 *used_mouse_menu = 1; | 2750 *used_mouse_menu = 1; |
2758 return value; | 2751 return value; |
2759 } | 2752 } |
2760 #endif /* not NO_X_MENU */ | 2753 #endif /* HAVE_X_MENU */ |
2761 #endif /* HAVE_X_WINDOW */ | 2754 #endif /* HAVE_X_WINDOWS */ |
2762 | 2755 |
2763 /* Prompt string always starts with map's prompt, and a space. */ | 2756 /* Prompt string always starts with map's prompt, and a space. */ |
2764 strcpy (menu, XSTRING (name)->data); | 2757 strcpy (menu, XSTRING (name)->data); |
2765 nlength = XSTRING (name)->size; | 2758 nlength = XSTRING (name)->size; |
2766 menu[nlength++] = ':'; | 2759 menu[nlength++] = ':'; |
3675 DEFUN ("input-pending-p", Finput_pending_p, Sinput_pending_p, 0, 0, 0, | 3668 DEFUN ("input-pending-p", Finput_pending_p, Sinput_pending_p, 0, 0, 0, |
3676 "T if command input is currently available with no waiting.\n\ | 3669 "T if command input is currently available with no waiting.\n\ |
3677 Actually, the value is nil only if we can be sure that no input is available.") | 3670 Actually, the value is nil only if we can be sure that no input is available.") |
3678 () | 3671 () |
3679 { | 3672 { |
3680 if (!NILP (unread_command_event)) | 3673 if (!NILP (unread_command_events)) |
3681 return (Qt); | 3674 return (Qt); |
3682 | 3675 |
3683 return detect_input_pending () ? Qt : Qnil; | 3676 return detect_input_pending () ? Qt : Qnil; |
3684 } | 3677 } |
3685 | 3678 |
3747 () | 3740 () |
3748 { | 3741 { |
3749 defining_kbd_macro = 0; | 3742 defining_kbd_macro = 0; |
3750 update_mode_lines++; | 3743 update_mode_lines++; |
3751 | 3744 |
3752 unread_command_event = Qnil; | 3745 unread_command_events = Qnil; |
3753 | 3746 |
3754 discard_tty_input (); | 3747 discard_tty_input (); |
3755 | 3748 |
3756 /* Without the cast, GCC complains that this assignment loses the | 3749 /* Without the cast, GCC complains that this assignment loses the |
3757 volatile qualifier of kbd_store_ptr. Is there anything wrong | 3750 volatile qualifier of kbd_store_ptr. Is there anything wrong |
3995 sigfree (); | 3988 sigfree (); |
3996 /* Prevent another signal from doing this before we finish. */ | 3989 /* Prevent another signal from doing this before we finish. */ |
3997 clear_waiting_for_input (); | 3990 clear_waiting_for_input (); |
3998 input_pending = 0; | 3991 input_pending = 0; |
3999 | 3992 |
4000 unread_command_event = Qnil; | 3993 unread_command_events = Qnil; |
4001 | 3994 |
4002 _longjmp (getcjmp, 1); | 3995 _longjmp (getcjmp, 1); |
4003 } | 3996 } |
4004 | 3997 |
4005 DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0, | 3998 DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0, |
4049 { | 4042 { |
4050 /* This is correct before outermost invocation of the editor loop */ | 4043 /* This is correct before outermost invocation of the editor loop */ |
4051 command_loop_level = -1; | 4044 command_loop_level = -1; |
4052 immediate_quit = 0; | 4045 immediate_quit = 0; |
4053 quit_char = Ctl ('g'); | 4046 quit_char = Ctl ('g'); |
4054 unread_command_event = Qnil; | 4047 unread_command_events = Qnil; |
4055 total_keys = 0; | 4048 total_keys = 0; |
4056 recent_keys_index = 0; | 4049 recent_keys_index = 0; |
4057 kbd_fetch_ptr = kbd_buffer; | 4050 kbd_fetch_ptr = kbd_buffer; |
4058 kbd_store_ptr = kbd_buffer; | 4051 kbd_store_ptr = kbd_buffer; |
4059 do_mouse_tracking = 0; | 4052 do_mouse_tracking = 0; |
4217 staticpro (&unread_switch_frame); | 4210 staticpro (&unread_switch_frame); |
4218 | 4211 |
4219 defsubr (&Sread_key_sequence); | 4212 defsubr (&Sread_key_sequence); |
4220 defsubr (&Srecursive_edit); | 4213 defsubr (&Srecursive_edit); |
4221 defsubr (&Strack_mouse); | 4214 defsubr (&Strack_mouse); |
4222 defsubr (&Smouse_click_p); | |
4223 defsubr (&Sinput_pending_p); | 4215 defsubr (&Sinput_pending_p); |
4224 defsubr (&Scommand_execute); | 4216 defsubr (&Scommand_execute); |
4225 defsubr (&Srecent_keys); | 4217 defsubr (&Srecent_keys); |
4226 defsubr (&Sthis_command_keys); | 4218 defsubr (&Sthis_command_keys); |
4227 defsubr (&Ssuspend_emacs); | 4219 defsubr (&Ssuspend_emacs); |
4248 so that you can determine whether the command was run by mouse or not."); | 4240 so that you can determine whether the command was run by mouse or not."); |
4249 | 4241 |
4250 DEFVAR_LISP ("last-input-char", &last_input_char, | 4242 DEFVAR_LISP ("last-input-char", &last_input_char, |
4251 "Last terminal input key."); | 4243 "Last terminal input key."); |
4252 | 4244 |
4253 DEFVAR_LISP ("unread-command-event", &unread_command_event, | 4245 DEFVAR_LISP ("unread-command-events", &unread_command_events, |
4254 "Object to be read as next input from input stream, or nil if none."); | 4246 "Lisp of object to be read as next input from input stream, or nil if none."); |
4255 | 4247 |
4256 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char, | 4248 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char, |
4257 "Meta-prefix character code. Meta-foo as command input\n\ | 4249 "Meta-prefix character code. Meta-foo as command input\n\ |
4258 turns into this character followed by foo."); | 4250 turns into this character followed by foo."); |
4259 XSET (meta_prefix_char, Lisp_Int, 033); | 4251 XSET (meta_prefix_char, Lisp_Int, 033); |