aboutsummaryrefslogtreecommitdiffstats
path: root/src/keyboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/keyboard.c')
-rw-r--r--src/keyboard.c128
1 files changed, 38 insertions, 90 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
index de48b53053b..c80f1d61e77 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -22,7 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22#define KEYBOARD_INLINE EXTERN_INLINE 22#define KEYBOARD_INLINE EXTERN_INLINE
23 23
24#include <stdio.h> 24#include <stdio.h>
25#include <setjmp.h> 25
26#include "lisp.h" 26#include "lisp.h"
27#include "termchar.h" 27#include "termchar.h"
28#include "termopts.h" 28#include "termopts.h"
@@ -56,6 +56,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
56#include <sys/ioctl.h> 56#include <sys/ioctl.h>
57#endif /* not MSDOS */ 57#endif /* not MSDOS */
58 58
59#if defined USABLE_FIONREAD && defined USG5_4
60# include <sys/filio.h>
61#endif
62
59#include "syssignal.h" 63#include "syssignal.h"
60 64
61#include <sys/types.h> 65#include <sys/types.h>
@@ -80,9 +84,7 @@ int interrupt_input_pending;
80 pending_atimers separately, to reduce code size. So, any code that 84 pending_atimers separately, to reduce code size. So, any code that
81 changes interrupt_input_pending or pending_atimers should update 85 changes interrupt_input_pending or pending_atimers should update
82 this too. */ 86 this too. */
83#ifdef SYNC_INPUT
84int pending_signals; 87int pending_signals;
85#endif
86 88
87#define KBD_BUFFER_SIZE 4096 89#define KBD_BUFFER_SIZE 4096
88 90
@@ -141,7 +143,7 @@ static ptrdiff_t before_command_echo_length;
141 143
142/* For longjmp to where kbd input is being done. */ 144/* For longjmp to where kbd input is being done. */
143 145
144static jmp_buf getcjmp; 146static sys_jmp_buf getcjmp;
145 147
146/* True while doing kbd input. */ 148/* True while doing kbd input. */
147int waiting_for_input; 149int waiting_for_input;
@@ -388,19 +390,6 @@ int interrupt_input;
388/* Nonzero while interrupts are temporarily deferred during redisplay. */ 390/* Nonzero while interrupts are temporarily deferred during redisplay. */
389int interrupts_deferred; 391int interrupts_deferred;
390 392
391/* Allow configure to inhibit use of FIONREAD. */
392#ifdef BROKEN_FIONREAD
393#undef FIONREAD
394#endif
395
396/* We are unable to use interrupts if FIONREAD is not available,
397 so flush SIGIO so we won't try. */
398#if !defined (FIONREAD)
399#ifdef SIGIO
400#undef SIGIO
401#endif
402#endif
403
404/* If we support a window system, turn on the code to poll periodically 393/* If we support a window system, turn on the code to poll periodically
405 to detect C-g. It isn't actually used when doing interrupt input. */ 394 to detect C-g. It isn't actually used when doing interrupt input. */
406#if defined (HAVE_WINDOW_SYSTEM) && !defined (USE_ASYNC_EVENTS) 395#if defined (HAVE_WINDOW_SYSTEM) && !defined (USE_ASYNC_EVENTS)
@@ -446,12 +435,12 @@ static Lisp_Object modify_event_symbol (ptrdiff_t, int, Lisp_Object,
446 Lisp_Object *, ptrdiff_t); 435 Lisp_Object *, ptrdiff_t);
447static Lisp_Object make_lispy_switch_frame (Lisp_Object); 436static Lisp_Object make_lispy_switch_frame (Lisp_Object);
448static int help_char_p (Lisp_Object); 437static int help_char_p (Lisp_Object);
449static void save_getcjmp (jmp_buf); 438static void save_getcjmp (sys_jmp_buf);
450static void restore_getcjmp (jmp_buf); 439static void restore_getcjmp (sys_jmp_buf);
451static Lisp_Object apply_modifiers (int, Lisp_Object); 440static Lisp_Object apply_modifiers (int, Lisp_Object);
452static void clear_event (struct input_event *); 441static void clear_event (struct input_event *);
453static Lisp_Object restore_kboard_configuration (Lisp_Object); 442static Lisp_Object restore_kboard_configuration (Lisp_Object);
454#ifdef SIGIO 443#ifdef USABLE_SIGIO
455static void deliver_input_available_signal (int signo); 444static void deliver_input_available_signal (int signo);
456#endif 445#endif
457static void handle_interrupt (void); 446static void handle_interrupt (void);
@@ -2022,17 +2011,9 @@ static struct atimer *poll_timer;
2022void 2011void
2023poll_for_input_1 (void) 2012poll_for_input_1 (void)
2024{ 2013{
2025/* Tell ns_read_socket() it is being called asynchronously so it can avoid
2026 doing anything dangerous. */
2027#ifdef HAVE_NS
2028 ++handling_signal;
2029#endif
2030 if (interrupt_input_blocked == 0 2014 if (interrupt_input_blocked == 0
2031 && !waiting_for_input) 2015 && !waiting_for_input)
2032 read_avail_input (0); 2016 read_avail_input (0);
2033#ifdef HAVE_NS
2034 --handling_signal;
2035#endif
2036} 2017}
2037 2018
2038/* Timer callback function for poll_timer. TIMER is equal to 2019/* Timer callback function for poll_timer. TIMER is equal to
@@ -2043,12 +2024,8 @@ poll_for_input (struct atimer *timer)
2043{ 2024{
2044 if (poll_suppress_count == 0) 2025 if (poll_suppress_count == 0)
2045 { 2026 {
2046#ifdef SYNC_INPUT
2047 interrupt_input_pending = 1; 2027 interrupt_input_pending = 1;
2048 pending_signals = 1; 2028 pending_signals = 1;
2049#else
2050 poll_for_input_1 ();
2051#endif
2052 } 2029 }
2053} 2030}
2054 2031
@@ -2327,8 +2304,8 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2327{ 2304{
2328 volatile Lisp_Object c; 2305 volatile Lisp_Object c;
2329 ptrdiff_t jmpcount; 2306 ptrdiff_t jmpcount;
2330 jmp_buf local_getcjmp; 2307 sys_jmp_buf local_getcjmp;
2331 jmp_buf save_jump; 2308 sys_jmp_buf save_jump;
2332 volatile int key_already_recorded = 0; 2309 volatile int key_already_recorded = 0;
2333 Lisp_Object tem, save; 2310 Lisp_Object tem, save;
2334 volatile Lisp_Object previous_echo_area_message; 2311 volatile Lisp_Object previous_echo_area_message;
@@ -2574,7 +2551,7 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2574 it *must not* be in effect when we call redisplay. */ 2551 it *must not* be in effect when we call redisplay. */
2575 2552
2576 jmpcount = SPECPDL_INDEX (); 2553 jmpcount = SPECPDL_INDEX ();
2577 if (_setjmp (local_getcjmp)) 2554 if (sys_setjmp (local_getcjmp))
2578 { 2555 {
2579 /* Handle quits while reading the keyboard. */ 2556 /* Handle quits while reading the keyboard. */
2580 /* We must have saved the outer value of getcjmp here, 2557 /* We must have saved the outer value of getcjmp here,
@@ -3406,13 +3383,13 @@ record_char (Lisp_Object c)
3406 See read_process_output. */ 3383 See read_process_output. */
3407 3384
3408static void 3385static void
3409save_getcjmp (jmp_buf temp) 3386save_getcjmp (sys_jmp_buf temp)
3410{ 3387{
3411 memcpy (temp, getcjmp, sizeof getcjmp); 3388 memcpy (temp, getcjmp, sizeof getcjmp);
3412} 3389}
3413 3390
3414static void 3391static void
3415restore_getcjmp (jmp_buf temp) 3392restore_getcjmp (sys_jmp_buf temp)
3416{ 3393{
3417 memcpy (getcjmp, temp, sizeof getcjmp); 3394 memcpy (getcjmp, temp, sizeof getcjmp);
3418} 3395}
@@ -3649,10 +3626,8 @@ kbd_buffer_store_event_hold (register struct input_event *event,
3649 /* Don't read keyboard input until we have processed kbd_buffer. 3626 /* Don't read keyboard input until we have processed kbd_buffer.
3650 This happens when pasting text longer than KBD_BUFFER_SIZE/2. */ 3627 This happens when pasting text longer than KBD_BUFFER_SIZE/2. */
3651 hold_keyboard_input (); 3628 hold_keyboard_input ();
3652#ifdef SIGIO
3653 if (!noninteractive) 3629 if (!noninteractive)
3654 signal (SIGIO, SIG_IGN); 3630 ignore_sigio ();
3655#endif
3656 stop_polling (); 3631 stop_polling ();
3657 } 3632 }
3658#endif /* subprocesses */ 3633#endif /* subprocesses */
@@ -3821,14 +3796,14 @@ kbd_buffer_get_event (KBOARD **kbp,
3821 /* Start reading input again, we have processed enough so we can 3796 /* Start reading input again, we have processed enough so we can
3822 accept new events again. */ 3797 accept new events again. */
3823 unhold_keyboard_input (); 3798 unhold_keyboard_input ();
3824#ifdef SIGIO 3799#ifdef USABLE_SIGIO
3825 if (!noninteractive) 3800 if (!noninteractive)
3826 { 3801 {
3827 struct sigaction action; 3802 struct sigaction action;
3828 emacs_sigaction_init (&action, deliver_input_available_signal); 3803 emacs_sigaction_init (&action, deliver_input_available_signal);
3829 sigaction (SIGIO, &action, 0); 3804 sigaction (SIGIO, &action, 0);
3830 } 3805 }
3831#endif /* SIGIO */ 3806#endif
3832 start_polling (); 3807 start_polling ();
3833 } 3808 }
3834#endif /* subprocesses */ 3809#endif /* subprocesses */
@@ -3870,10 +3845,9 @@ kbd_buffer_get_event (KBOARD **kbp,
3870 /* One way or another, wait until input is available; then, if 3845 /* One way or another, wait until input is available; then, if
3871 interrupt handlers have not read it, read it now. */ 3846 interrupt handlers have not read it, read it now. */
3872 3847
3873/* Note SIGIO has been undef'd if FIONREAD is missing. */ 3848#ifdef USABLE_SIGIO
3874#ifdef SIGIO
3875 gobble_input (0); 3849 gobble_input (0);
3876#endif /* SIGIO */ 3850#endif
3877 if (kbd_fetch_ptr != kbd_store_ptr) 3851 if (kbd_fetch_ptr != kbd_store_ptr)
3878 break; 3852 break;
3879#if defined (HAVE_MOUSE) || defined (HAVE_GPM) 3853#if defined (HAVE_MOUSE) || defined (HAVE_GPM)
@@ -4352,7 +4326,7 @@ decode_timer (Lisp_Object timer, EMACS_TIME *result)
4352 if (! NILP (vector[0])) 4326 if (! NILP (vector[0]))
4353 return 0; 4327 return 0;
4354 4328
4355 return decode_time_components (vector[1], vector[2], vector[3], vector[4], 4329 return decode_time_components (vector[1], vector[2], vector[3], vector[8],
4356 result, 0); 4330 result, 0);
4357} 4331}
4358 4332
@@ -4554,7 +4528,7 @@ in the same style as (current-time).
4554 4528
4555The value when Emacs is not idle is nil. 4529The value when Emacs is not idle is nil.
4556 4530
4557NSEC is a multiple of the system clock resolution. */) 4531PSEC is a multiple of the system clock resolution. */)
4558 (void) 4532 (void)
4559{ 4533{
4560 if (EMACS_TIME_VALID_P (timer_idleness_start_time)) 4534 if (EMACS_TIME_VALID_P (timer_idleness_start_time))
@@ -6785,7 +6759,7 @@ get_input_pending (int *addr, int flags)
6785void 6759void
6786gobble_input (int expected) 6760gobble_input (int expected)
6787{ 6761{
6788#ifdef SIGIO 6762#ifdef USABLE_SIGIO
6789 if (interrupt_input) 6763 if (interrupt_input)
6790 { 6764 {
6791 sigset_t blocked, procmask; 6765 sigset_t blocked, procmask;
@@ -6840,7 +6814,7 @@ record_asynch_buffer_change (void)
6840 return; 6814 return;
6841 6815
6842 /* Make sure no interrupt happens while storing the event. */ 6816 /* Make sure no interrupt happens while storing the event. */
6843#ifdef SIGIO 6817#ifdef USABLE_SIGIO
6844 if (interrupt_input) 6818 if (interrupt_input)
6845 { 6819 {
6846 sigset_t blocked, procmask; 6820 sigset_t blocked, procmask;
@@ -7066,7 +7040,7 @@ tty_read_avail_input (struct terminal *terminal,
7066#endif /* HAVE_GPM */ 7040#endif /* HAVE_GPM */
7067 7041
7068/* Determine how many characters we should *try* to read. */ 7042/* Determine how many characters we should *try* to read. */
7069#ifdef FIONREAD 7043#ifdef USABLE_FIONREAD
7070 /* Find out how much input is available. */ 7044 /* Find out how much input is available. */
7071 if (ioctl (fileno (tty->input), FIONREAD, &n_to_read) < 0) 7045 if (ioctl (fileno (tty->input), FIONREAD, &n_to_read) < 0)
7072 { 7046 {
@@ -7079,14 +7053,12 @@ tty_read_avail_input (struct terminal *terminal,
7079 return 0; 7053 return 0;
7080 if (n_to_read > sizeof cbuf) 7054 if (n_to_read > sizeof cbuf)
7081 n_to_read = sizeof cbuf; 7055 n_to_read = sizeof cbuf;
7082#else /* no FIONREAD */ 7056#elif defined USG || defined CYGWIN
7083#if defined (USG) || defined (CYGWIN)
7084 /* Read some input if available, but don't wait. */ 7057 /* Read some input if available, but don't wait. */
7085 n_to_read = sizeof cbuf; 7058 n_to_read = sizeof cbuf;
7086 fcntl (fileno (tty->input), F_SETFL, O_NDELAY); 7059 fcntl (fileno (tty->input), F_SETFL, O_NDELAY);
7087#else 7060#else
7088 you lose; 7061# error "Cannot read without possibly delaying"
7089#endif
7090#endif 7062#endif
7091 7063
7092#ifdef subprocesses 7064#ifdef subprocesses
@@ -7135,7 +7107,7 @@ tty_read_avail_input (struct terminal *terminal,
7135#endif 7107#endif
7136 ); 7108 );
7137 7109
7138#ifndef FIONREAD 7110#ifndef USABLE_FIONREAD
7139#if defined (USG) || defined (CYGWIN) 7111#if defined (USG) || defined (CYGWIN)
7140 fcntl (fileno (tty->input), F_SETFL, 0); 7112 fcntl (fileno (tty->input), F_SETFL, 0);
7141#endif /* USG or CYGWIN */ 7113#endif /* USG or CYGWIN */
@@ -7206,19 +7178,12 @@ tty_read_avail_input (struct terminal *terminal,
7206 return nread; 7178 return nread;
7207} 7179}
7208 7180
7209#if defined SYNC_INPUT || defined SIGIO
7210static void 7181static void
7211handle_async_input (void) 7182handle_async_input (void)
7212{ 7183{
7213 interrupt_input_pending = 0; 7184 interrupt_input_pending = 0;
7214#ifdef SYNC_INPUT
7215 pending_signals = pending_atimers; 7185 pending_signals = pending_atimers;
7216#endif 7186
7217/* Tell ns_read_socket() it is being called asynchronously so it can avoid
7218 doing anything dangerous. */
7219#ifdef HAVE_NS
7220 ++handling_signal;
7221#endif
7222 while (1) 7187 while (1)
7223 { 7188 {
7224 int nread; 7189 int nread;
@@ -7229,13 +7194,8 @@ handle_async_input (void)
7229 if (nread <= 0) 7194 if (nread <= 0)
7230 break; 7195 break;
7231 } 7196 }
7232#ifdef HAVE_NS
7233 --handling_signal;
7234#endif
7235} 7197}
7236#endif /* SYNC_INPUT || SIGIO */
7237 7198
7238#ifdef SYNC_INPUT
7239void 7199void
7240process_pending_signals (void) 7200process_pending_signals (void)
7241{ 7201{
@@ -7243,25 +7203,17 @@ process_pending_signals (void)
7243 handle_async_input (); 7203 handle_async_input ();
7244 do_pending_atimers (); 7204 do_pending_atimers ();
7245} 7205}
7246#endif
7247 7206
7248#ifdef SIGIO /* for entire page */ 7207#ifdef USABLE_SIGIO
7249/* Note SIGIO has been undef'd if FIONREAD is missing. */
7250 7208
7251static void 7209static void
7252handle_input_available_signal (int sig) 7210handle_input_available_signal (int sig)
7253{ 7211{
7254#ifdef SYNC_INPUT
7255 interrupt_input_pending = 1; 7212 interrupt_input_pending = 1;
7256 pending_signals = 1; 7213 pending_signals = 1;
7257#endif
7258 7214
7259 if (input_available_clear_time) 7215 if (input_available_clear_time)
7260 *input_available_clear_time = make_emacs_time (0, 0); 7216 *input_available_clear_time = make_emacs_time (0, 0);
7261
7262#ifndef SYNC_INPUT
7263 handle_async_input ();
7264#endif
7265} 7217}
7266 7218
7267static void 7219static void
@@ -7269,7 +7221,7 @@ deliver_input_available_signal (int sig)
7269{ 7221{
7270 handle_on_main_thread (sig, handle_input_available_signal); 7222 handle_on_main_thread (sig, handle_input_available_signal);
7271} 7223}
7272#endif /* SIGIO */ 7224#endif /* USABLE_SIGIO */
7273 7225
7274/* Send ourselves a SIGIO. 7226/* Send ourselves a SIGIO.
7275 7227
@@ -7280,7 +7232,7 @@ deliver_input_available_signal (int sig)
7280void 7232void
7281reinvoke_input_signal (void) 7233reinvoke_input_signal (void)
7282{ 7234{
7283#ifdef SIGIO 7235#ifdef USABLE_SIGIO
7284 handle_async_input (); 7236 handle_async_input ();
7285#endif 7237#endif
7286} 7238}
@@ -7354,7 +7306,7 @@ handle_user_signal (int sig)
7354 } 7306 }
7355 7307
7356 p->npending++; 7308 p->npending++;
7357#ifdef SIGIO 7309#ifdef USABLE_SIGIO
7358 if (interrupt_input) 7310 if (interrupt_input)
7359 kill (getpid (), SIGIO); 7311 kill (getpid (), SIGIO);
7360 else 7312 else
@@ -11010,7 +10962,7 @@ quit_throw_to_read_char (int from_signal)
11010 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame), 10962 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame),
11011 0, 0, Qnil); 10963 0, 0, Qnil);
11012 10964
11013 _longjmp (getcjmp, 1); 10965 sys_longjmp (getcjmp, 1);
11014} 10966}
11015 10967
11016DEFUN ("set-input-interrupt-mode", Fset_input_interrupt_mode, 10968DEFUN ("set-input-interrupt-mode", Fset_input_interrupt_mode,
@@ -11023,8 +10975,7 @@ See also `current-input-mode'. */)
11023 (Lisp_Object interrupt) 10975 (Lisp_Object interrupt)
11024{ 10976{
11025 int new_interrupt_input; 10977 int new_interrupt_input;
11026#ifdef SIGIO 10978#ifdef USABLE_SIGIO
11027/* Note SIGIO has been undef'd if FIONREAD is missing. */
11028#ifdef HAVE_X_WINDOWS 10979#ifdef HAVE_X_WINDOWS
11029 if (x_display_list != NULL) 10980 if (x_display_list != NULL)
11030 { 10981 {
@@ -11035,9 +10986,9 @@ See also `current-input-mode'. */)
11035 else 10986 else
11036#endif /* HAVE_X_WINDOWS */ 10987#endif /* HAVE_X_WINDOWS */
11037 new_interrupt_input = !NILP (interrupt); 10988 new_interrupt_input = !NILP (interrupt);
11038#else /* not SIGIO */ 10989#else /* not USABLE_SIGIO */
11039 new_interrupt_input = 0; 10990 new_interrupt_input = 0;
11040#endif /* not SIGIO */ 10991#endif /* not USABLE_SIGIO */
11041 10992
11042 if (new_interrupt_input != interrupt_input) 10993 if (new_interrupt_input != interrupt_input)
11043 { 10994 {
@@ -11397,9 +11348,7 @@ init_keyboard (void)
11397 input_pending = 0; 11348 input_pending = 0;
11398 interrupt_input_blocked = 0; 11349 interrupt_input_blocked = 0;
11399 interrupt_input_pending = 0; 11350 interrupt_input_pending = 0;
11400#ifdef SYNC_INPUT
11401 pending_signals = 0; 11351 pending_signals = 0;
11402#endif
11403 11352
11404 /* This means that command_loop_1 won't try to select anything the first 11353 /* This means that command_loop_1 won't try to select anything the first
11405 time through. */ 11354 time through. */
@@ -11431,15 +11380,14 @@ init_keyboard (void)
11431 sigaction (SIGQUIT, &action, 0); 11380 sigaction (SIGQUIT, &action, 0);
11432#endif /* not DOS_NT */ 11381#endif /* not DOS_NT */
11433 } 11382 }
11434/* Note SIGIO has been undef'd if FIONREAD is missing. */ 11383#ifdef USABLE_SIGIO
11435#ifdef SIGIO
11436 if (!noninteractive) 11384 if (!noninteractive)
11437 { 11385 {
11438 struct sigaction action; 11386 struct sigaction action;
11439 emacs_sigaction_init (&action, deliver_input_available_signal); 11387 emacs_sigaction_init (&action, deliver_input_available_signal);
11440 sigaction (SIGIO, &action, 0); 11388 sigaction (SIGIO, &action, 0);
11441 } 11389 }
11442#endif /* SIGIO */ 11390#endif
11443 11391
11444/* Use interrupt input by default, if it works and noninterrupt input 11392/* Use interrupt input by default, if it works and noninterrupt input
11445 has deficiencies. */ 11393 has deficiencies. */