aboutsummaryrefslogtreecommitdiffstats
path: root/src/keyboard.c
diff options
context:
space:
mode:
authorJoakim Verona2013-09-10 23:26:38 +0200
committerJoakim Verona2013-09-10 23:26:38 +0200
commit92aeabcc8a007f521a664e3aee092eb80ad0f49a (patch)
tree58fde2f218fa45ee1b2c67184b50137a8fb6e140 /src/keyboard.c
parentebc2ba4f6049d17fd41d2f1fc8d65efe309f6bf4 (diff)
parent43aac990c339c0fc3304aa476ebc8ea8467f107e (diff)
downloademacs-92aeabcc8a007f521a664e3aee092eb80ad0f49a.tar.gz
emacs-92aeabcc8a007f521a664e3aee092eb80ad0f49a.zip
merge from trunk
Conflicts: src/dispnew.c
Diffstat (limited to 'src/keyboard.c')
-rw-r--r--src/keyboard.c125
1 files changed, 63 insertions, 62 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
index 1aa25669b5b..a2f772dea8a 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -363,7 +363,7 @@ Lisp_Object Qmenu_bar;
363static void recursive_edit_unwind (Lisp_Object buffer); 363static void recursive_edit_unwind (Lisp_Object buffer);
364static Lisp_Object command_loop (void); 364static Lisp_Object command_loop (void);
365static Lisp_Object Qcommand_execute; 365static Lisp_Object Qcommand_execute;
366EMACS_TIME timer_check (void); 366struct timespec timer_check (void);
367 367
368static void echo_now (void); 368static void echo_now (void);
369static ptrdiff_t echo_length (void); 369static ptrdiff_t echo_length (void);
@@ -373,9 +373,9 @@ static Lisp_Object Qpolling_period;
373/* Incremented whenever a timer is run. */ 373/* Incremented whenever a timer is run. */
374unsigned timers_run; 374unsigned timers_run;
375 375
376/* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt 376/* Address (if not 0) of struct timespec to zero out if a SIGIO interrupt
377 happens. */ 377 happens. */
378EMACS_TIME *input_available_clear_time; 378struct timespec *input_available_clear_time;
379 379
380/* True means use SIGIO interrupts; false means use CBREAK mode. 380/* True means use SIGIO interrupts; false means use CBREAK mode.
381 Default is true if INTERRUPT_INPUT is defined. */ 381 Default is true if INTERRUPT_INPUT is defined. */
@@ -392,12 +392,12 @@ bool interrupts_deferred;
392 392
393/* The time when Emacs started being idle. */ 393/* The time when Emacs started being idle. */
394 394
395static EMACS_TIME timer_idleness_start_time; 395static struct timespec timer_idleness_start_time;
396 396
397/* After Emacs stops being idle, this saves the last value 397/* After Emacs stops being idle, this saves the last value
398 of timer_idleness_start_time from when it was idle. */ 398 of timer_idleness_start_time from when it was idle. */
399 399
400static EMACS_TIME timer_last_idleness_start_time; 400static struct timespec timer_last_idleness_start_time;
401 401
402 402
403/* Global variable declarations. */ 403/* Global variable declarations. */
@@ -1989,10 +1989,10 @@ start_polling (void)
1989 /* If poll timer doesn't exist, are we need one with 1989 /* If poll timer doesn't exist, are we need one with
1990 a different interval, start a new one. */ 1990 a different interval, start a new one. */
1991 if (poll_timer == NULL 1991 if (poll_timer == NULL
1992 || EMACS_SECS (poll_timer->interval) != polling_period) 1992 || poll_timer->interval.tv_sec != polling_period)
1993 { 1993 {
1994 time_t period = max (1, min (polling_period, TYPE_MAXIMUM (time_t))); 1994 time_t period = max (1, min (polling_period, TYPE_MAXIMUM (time_t)));
1995 EMACS_TIME interval = make_emacs_time (period, 0); 1995 struct timespec interval = make_timespec (period, 0);
1996 1996
1997 if (poll_timer) 1997 if (poll_timer)
1998 cancel_atimer (poll_timer); 1998 cancel_atimer (poll_timer);
@@ -2185,7 +2185,7 @@ show_help_echo (Lisp_Object help, Lisp_Object window, Lisp_Object object,
2185/* Input of single characters from keyboard */ 2185/* Input of single characters from keyboard */
2186 2186
2187static Lisp_Object kbd_buffer_get_event (KBOARD **kbp, bool *used_mouse_menu, 2187static Lisp_Object kbd_buffer_get_event (KBOARD **kbp, bool *used_mouse_menu,
2188 EMACS_TIME *end_time); 2188 struct timespec *end_time);
2189static void record_char (Lisp_Object c); 2189static void record_char (Lisp_Object c);
2190 2190
2191static Lisp_Object help_form_saved_window_configs; 2191static Lisp_Object help_form_saved_window_configs;
@@ -2207,7 +2207,7 @@ do { if (polling_stopped_here) start_polling (); \
2207 polling_stopped_here = 0; } while (0) 2207 polling_stopped_here = 0; } while (0)
2208 2208
2209static Lisp_Object 2209static Lisp_Object
2210read_event_from_main_queue (EMACS_TIME *end_time, 2210read_event_from_main_queue (struct timespec *end_time,
2211 sys_jmp_buf local_getcjmp, 2211 sys_jmp_buf local_getcjmp,
2212 bool *used_mouse_menu) 2212 bool *used_mouse_menu)
2213{ 2213{
@@ -2220,7 +2220,7 @@ read_event_from_main_queue (EMACS_TIME *end_time,
2220 /* Read from the main queue, and if that gives us something we can't use yet, 2220 /* Read from the main queue, and if that gives us something we can't use yet,
2221 we put it on the appropriate side queue and try again. */ 2221 we put it on the appropriate side queue and try again. */
2222 2222
2223 if (end_time && EMACS_TIME_LE (*end_time, current_emacs_time ())) 2223 if (end_time && timespec_cmp (*end_time, current_timespec ()) <= 0)
2224 return c; 2224 return c;
2225 2225
2226 /* Actually read a character, waiting if necessary. */ 2226 /* Actually read a character, waiting if necessary. */
@@ -2281,7 +2281,7 @@ read_event_from_main_queue (EMACS_TIME *end_time,
2281/* Like `read_event_from_main_queue' but applies keyboard-coding-system 2281/* Like `read_event_from_main_queue' but applies keyboard-coding-system
2282 to tty input. */ 2282 to tty input. */
2283static Lisp_Object 2283static Lisp_Object
2284read_decoded_event_from_main_queue (EMACS_TIME *end_time, 2284read_decoded_event_from_main_queue (struct timespec *end_time,
2285 sys_jmp_buf local_getcjmp, 2285 sys_jmp_buf local_getcjmp,
2286 Lisp_Object prev_event, 2286 Lisp_Object prev_event,
2287 bool *used_mouse_menu) 2287 bool *used_mouse_menu)
@@ -2379,7 +2379,7 @@ read_decoded_event_from_main_queue (EMACS_TIME *end_time,
2379 Value is -2 when we find input on another keyboard. A second call 2379 Value is -2 when we find input on another keyboard. A second call
2380 to read_char will read it. 2380 to read_char will read it.
2381 2381
2382 If END_TIME is non-null, it is a pointer to an EMACS_TIME 2382 If END_TIME is non-null, it is a pointer to a struct timespec
2383 specifying the maximum time to wait until. If no input arrives by 2383 specifying the maximum time to wait until. If no input arrives by
2384 that time, stop waiting and return nil. 2384 that time, stop waiting and return nil.
2385 2385
@@ -2388,7 +2388,7 @@ read_decoded_event_from_main_queue (EMACS_TIME *end_time,
2388Lisp_Object 2388Lisp_Object
2389read_char (int commandflag, Lisp_Object map, 2389read_char (int commandflag, Lisp_Object map,
2390 Lisp_Object prev_event, 2390 Lisp_Object prev_event,
2391 bool *used_mouse_menu, EMACS_TIME *end_time) 2391 bool *used_mouse_menu, struct timespec *end_time)
2392{ 2392{
2393 Lisp_Object c; 2393 Lisp_Object c;
2394 ptrdiff_t jmpcount; 2394 ptrdiff_t jmpcount;
@@ -2880,7 +2880,7 @@ read_char (int commandflag, Lisp_Object map,
2880 { 2880 {
2881 c = read_decoded_event_from_main_queue (end_time, local_getcjmp, 2881 c = read_decoded_event_from_main_queue (end_time, local_getcjmp,
2882 prev_event, used_mouse_menu); 2882 prev_event, used_mouse_menu);
2883 if (end_time && EMACS_TIME_LE (*end_time, current_emacs_time ())) 2883 if (end_time && timespec_cmp (*end_time, current_timespec ()) <= 0)
2884 goto exit; 2884 goto exit;
2885 if (EQ (c, make_number (-2))) 2885 if (EQ (c, make_number (-2)))
2886 { 2886 {
@@ -3801,7 +3801,7 @@ clear_event (struct input_event *event)
3801static Lisp_Object 3801static Lisp_Object
3802kbd_buffer_get_event (KBOARD **kbp, 3802kbd_buffer_get_event (KBOARD **kbp,
3803 bool *used_mouse_menu, 3803 bool *used_mouse_menu,
3804 EMACS_TIME *end_time) 3804 struct timespec *end_time)
3805{ 3805{
3806 Lisp_Object obj; 3806 Lisp_Object obj;
3807 3807
@@ -3859,15 +3859,15 @@ kbd_buffer_get_event (KBOARD **kbp,
3859 break; 3859 break;
3860 if (end_time) 3860 if (end_time)
3861 { 3861 {
3862 EMACS_TIME now = current_emacs_time (); 3862 struct timespec now = current_timespec ();
3863 if (EMACS_TIME_LE (*end_time, now)) 3863 if (timespec_cmp (*end_time, now) <= 0)
3864 return Qnil; /* Finished waiting. */ 3864 return Qnil; /* Finished waiting. */
3865 else 3865 else
3866 { 3866 {
3867 EMACS_TIME duration = sub_emacs_time (*end_time, now); 3867 struct timespec duration = timespec_sub (*end_time, now);
3868 wait_reading_process_output (min (EMACS_SECS (duration), 3868 wait_reading_process_output (min (duration.tv_sec,
3869 WAIT_READING_MAX), 3869 WAIT_READING_MAX),
3870 EMACS_NSECS (duration), 3870 duration.tv_nsec,
3871 -1, 1, Qnil, NULL, 0); 3871 -1, 1, Qnil, NULL, 0);
3872 } 3872 }
3873 } 3873 }
@@ -4312,10 +4312,10 @@ static void
4312timer_start_idle (void) 4312timer_start_idle (void)
4313{ 4313{
4314 /* If we are already in the idle state, do nothing. */ 4314 /* If we are already in the idle state, do nothing. */
4315 if (EMACS_TIME_VALID_P (timer_idleness_start_time)) 4315 if (timespec_valid_p (timer_idleness_start_time))
4316 return; 4316 return;
4317 4317
4318 timer_idleness_start_time = current_emacs_time (); 4318 timer_idleness_start_time = current_timespec ();
4319 timer_last_idleness_start_time = timer_idleness_start_time; 4319 timer_last_idleness_start_time = timer_idleness_start_time;
4320 4320
4321 /* Mark all idle-time timers as once again candidates for running. */ 4321 /* Mark all idle-time timers as once again candidates for running. */
@@ -4327,7 +4327,7 @@ timer_start_idle (void)
4327static void 4327static void
4328timer_stop_idle (void) 4328timer_stop_idle (void)
4329{ 4329{
4330 timer_idleness_start_time = invalid_emacs_time (); 4330 timer_idleness_start_time = invalid_timespec ();
4331} 4331}
4332 4332
4333/* Resume idle timer from last idle start time. */ 4333/* Resume idle timer from last idle start time. */
@@ -4335,7 +4335,7 @@ timer_stop_idle (void)
4335static void 4335static void
4336timer_resume_idle (void) 4336timer_resume_idle (void)
4337{ 4337{
4338 if (EMACS_TIME_VALID_P (timer_idleness_start_time)) 4338 if (timespec_valid_p (timer_idleness_start_time))
4339 return; 4339 return;
4340 4340
4341 timer_idleness_start_time = timer_last_idleness_start_time; 4341 timer_idleness_start_time = timer_last_idleness_start_time;
@@ -4351,7 +4351,7 @@ Lisp_Object pending_funcalls;
4351 4351
4352/* Return true if TIMER is a valid timer, placing its value into *RESULT. */ 4352/* Return true if TIMER is a valid timer, placing its value into *RESULT. */
4353static bool 4353static bool
4354decode_timer (Lisp_Object timer, EMACS_TIME *result) 4354decode_timer (Lisp_Object timer, struct timespec *result)
4355{ 4355{
4356 Lisp_Object *vector; 4356 Lisp_Object *vector;
4357 4357
@@ -4378,16 +4378,16 @@ decode_timer (Lisp_Object timer, EMACS_TIME *result)
4378 In that case we return 0 to indicate that a new timer_check_2 call 4378 In that case we return 0 to indicate that a new timer_check_2 call
4379 should be done. */ 4379 should be done. */
4380 4380
4381static EMACS_TIME 4381static struct timespec
4382timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers) 4382timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers)
4383{ 4383{
4384 EMACS_TIME nexttime; 4384 struct timespec nexttime;
4385 EMACS_TIME now; 4385 struct timespec now;
4386 EMACS_TIME idleness_now; 4386 struct timespec idleness_now;
4387 Lisp_Object chosen_timer; 4387 Lisp_Object chosen_timer;
4388 struct gcpro gcpro1; 4388 struct gcpro gcpro1;
4389 4389
4390 nexttime = invalid_emacs_time (); 4390 nexttime = invalid_timespec ();
4391 4391
4392 chosen_timer = Qnil; 4392 chosen_timer = Qnil;
4393 GCPRO1 (chosen_timer); 4393 GCPRO1 (chosen_timer);
@@ -4402,19 +4402,19 @@ timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers)
4402 4402
4403 if (CONSP (timers) || CONSP (idle_timers)) 4403 if (CONSP (timers) || CONSP (idle_timers))
4404 { 4404 {
4405 now = current_emacs_time (); 4405 now = current_timespec ();
4406 idleness_now = (EMACS_TIME_VALID_P (timer_idleness_start_time) 4406 idleness_now = (timespec_valid_p (timer_idleness_start_time)
4407 ? sub_emacs_time (now, timer_idleness_start_time) 4407 ? timespec_sub (now, timer_idleness_start_time)
4408 : make_emacs_time (0, 0)); 4408 : make_timespec (0, 0));
4409 } 4409 }
4410 4410
4411 while (CONSP (timers) || CONSP (idle_timers)) 4411 while (CONSP (timers) || CONSP (idle_timers))
4412 { 4412 {
4413 Lisp_Object timer = Qnil, idle_timer = Qnil; 4413 Lisp_Object timer = Qnil, idle_timer = Qnil;
4414 EMACS_TIME timer_time, idle_timer_time; 4414 struct timespec timer_time, idle_timer_time;
4415 EMACS_TIME difference; 4415 struct timespec difference;
4416 EMACS_TIME timer_difference = invalid_emacs_time (); 4416 struct timespec timer_difference = invalid_timespec ();
4417 EMACS_TIME idle_timer_difference = invalid_emacs_time (); 4417 struct timespec idle_timer_difference = invalid_timespec ();
4418 bool ripe, timer_ripe = 0, idle_timer_ripe = 0; 4418 bool ripe, timer_ripe = 0, idle_timer_ripe = 0;
4419 4419
4420 /* Set TIMER and TIMER_DIFFERENCE 4420 /* Set TIMER and TIMER_DIFFERENCE
@@ -4431,10 +4431,10 @@ timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers)
4431 continue; 4431 continue;
4432 } 4432 }
4433 4433
4434 timer_ripe = EMACS_TIME_LE (timer_time, now); 4434 timer_ripe = timespec_cmp (timer_time, now) <= 0;
4435 timer_difference = (timer_ripe 4435 timer_difference = (timer_ripe
4436 ? sub_emacs_time (now, timer_time) 4436 ? timespec_sub (now, timer_time)
4437 : sub_emacs_time (timer_time, now)); 4437 : timespec_sub (timer_time, now));
4438 } 4438 }
4439 4439
4440 /* Likewise for IDLE_TIMER and IDLE_TIMER_DIFFERENCE 4440 /* Likewise for IDLE_TIMER and IDLE_TIMER_DIFFERENCE
@@ -4448,26 +4448,27 @@ timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers)
4448 continue; 4448 continue;
4449 } 4449 }
4450 4450
4451 idle_timer_ripe = EMACS_TIME_LE (idle_timer_time, idleness_now); 4451 idle_timer_ripe = timespec_cmp (idle_timer_time, idleness_now) <= 0;
4452 idle_timer_difference 4452 idle_timer_difference
4453 = (idle_timer_ripe 4453 = (idle_timer_ripe
4454 ? sub_emacs_time (idleness_now, idle_timer_time) 4454 ? timespec_sub (idleness_now, idle_timer_time)
4455 : sub_emacs_time (idle_timer_time, idleness_now)); 4455 : timespec_sub (idle_timer_time, idleness_now));
4456 } 4456 }
4457 4457
4458 /* Decide which timer is the next timer, 4458 /* Decide which timer is the next timer,
4459 and set CHOSEN_TIMER, DIFFERENCE, and RIPE accordingly. 4459 and set CHOSEN_TIMER, DIFFERENCE, and RIPE accordingly.
4460 Also step down the list where we found that timer. */ 4460 Also step down the list where we found that timer. */
4461 4461
4462 if (EMACS_TIME_VALID_P (timer_difference) 4462 if (timespec_valid_p (timer_difference)
4463 && (! EMACS_TIME_VALID_P (idle_timer_difference) 4463 && (! timespec_valid_p (idle_timer_difference)
4464 || idle_timer_ripe < timer_ripe 4464 || idle_timer_ripe < timer_ripe
4465 || (idle_timer_ripe == timer_ripe 4465 || (idle_timer_ripe == timer_ripe
4466 && (timer_ripe 4466 && ((timer_ripe
4467 ? EMACS_TIME_LT (idle_timer_difference, 4467 ? timespec_cmp (idle_timer_difference,
4468 timer_difference) 4468 timer_difference)
4469 : EMACS_TIME_LT (timer_difference, 4469 : timespec_cmp (timer_difference,
4470 idle_timer_difference))))) 4470 idle_timer_difference))
4471 < 0))))
4471 { 4472 {
4472 chosen_timer = timer; 4473 chosen_timer = timer;
4473 timers = XCDR (timers); 4474 timers = XCDR (timers);
@@ -4507,7 +4508,7 @@ timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers)
4507 return 0 to indicate that. */ 4508 return 0 to indicate that. */
4508 } 4509 }
4509 4510
4510 nexttime = make_emacs_time (0, 0); 4511 nexttime = make_timespec (0, 0);
4511 break; 4512 break;
4512 } 4513 }
4513 else 4514 else
@@ -4535,10 +4536,10 @@ timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers)
4535 4536
4536 As long as any timer is ripe, we run it. */ 4537 As long as any timer is ripe, we run it. */
4537 4538
4538EMACS_TIME 4539struct timespec
4539timer_check (void) 4540timer_check (void)
4540{ 4541{
4541 EMACS_TIME nexttime; 4542 struct timespec nexttime;
4542 Lisp_Object timers, idle_timers; 4543 Lisp_Object timers, idle_timers;
4543 struct gcpro gcpro1, gcpro2; 4544 struct gcpro gcpro1, gcpro2;
4544 4545
@@ -4552,7 +4553,7 @@ timer_check (void)
4552 /* Always consider the ordinary timers. */ 4553 /* Always consider the ordinary timers. */
4553 timers = Fcopy_sequence (Vtimer_list); 4554 timers = Fcopy_sequence (Vtimer_list);
4554 /* Consider the idle timers only if Emacs is idle. */ 4555 /* Consider the idle timers only if Emacs is idle. */
4555 if (EMACS_TIME_VALID_P (timer_idleness_start_time)) 4556 if (timespec_valid_p (timer_idleness_start_time))
4556 idle_timers = Fcopy_sequence (Vtimer_idle_list); 4557 idle_timers = Fcopy_sequence (Vtimer_idle_list);
4557 else 4558 else
4558 idle_timers = Qnil; 4559 idle_timers = Qnil;
@@ -4565,7 +4566,7 @@ timer_check (void)
4565 { 4566 {
4566 nexttime = timer_check_2 (timers, idle_timers); 4567 nexttime = timer_check_2 (timers, idle_timers);
4567 } 4568 }
4568 while (EMACS_SECS (nexttime) == 0 && EMACS_NSECS (nexttime) == 0); 4569 while (nexttime.tv_sec == 0 && nexttime.tv_nsec == 0);
4569 4570
4570 UNGCPRO; 4571 UNGCPRO;
4571 return nexttime; 4572 return nexttime;
@@ -4581,9 +4582,9 @@ The value when Emacs is not idle is nil.
4581PSEC is a multiple of the system clock resolution. */) 4582PSEC is a multiple of the system clock resolution. */)
4582 (void) 4583 (void)
4583{ 4584{
4584 if (EMACS_TIME_VALID_P (timer_idleness_start_time)) 4585 if (timespec_valid_p (timer_idleness_start_time))
4585 return make_lisp_time (sub_emacs_time (current_emacs_time (), 4586 return make_lisp_time (timespec_sub (current_timespec (),
4586 timer_idleness_start_time)); 4587 timer_idleness_start_time));
4587 4588
4588 return Qnil; 4589 return Qnil;
4589} 4590}
@@ -7152,7 +7153,7 @@ handle_input_available_signal (int sig)
7152 pending_signals = 1; 7153 pending_signals = 1;
7153 7154
7154 if (input_available_clear_time) 7155 if (input_available_clear_time)
7155 *input_available_clear_time = make_emacs_time (0, 0); 7156 *input_available_clear_time = make_timespec (0, 0);
7156} 7157}
7157 7158
7158static void 7159static void
@@ -7239,7 +7240,7 @@ handle_user_signal (int sig)
7239 /* Tell wait_reading_process_output that it needs to wake 7240 /* Tell wait_reading_process_output that it needs to wake
7240 up and look around. */ 7241 up and look around. */
7241 if (input_available_clear_time) 7242 if (input_available_clear_time)
7242 *input_available_clear_time = make_emacs_time (0, 0); 7243 *input_available_clear_time = make_timespec (0, 0);
7243 } 7244 }
7244 break; 7245 break;
7245 } 7246 }
@@ -10261,7 +10262,7 @@ stuff_buffered_input (Lisp_Object stuffstring)
10261} 10262}
10262 10263
10263void 10264void
10264set_waiting_for_input (EMACS_TIME *time_to_clear) 10265set_waiting_for_input (struct timespec *time_to_clear)
10265{ 10266{
10266 input_available_clear_time = time_to_clear; 10267 input_available_clear_time = time_to_clear;
10267 10268
@@ -10872,7 +10873,7 @@ init_keyboard (void)
10872 immediate_quit = 0; 10873 immediate_quit = 0;
10873 quit_char = Ctl ('g'); 10874 quit_char = Ctl ('g');
10874 Vunread_command_events = Qnil; 10875 Vunread_command_events = Qnil;
10875 timer_idleness_start_time = invalid_emacs_time (); 10876 timer_idleness_start_time = invalid_timespec ();
10876 total_keys = 0; 10877 total_keys = 0;
10877 recent_keys_index = 0; 10878 recent_keys_index = 0;
10878 kbd_fetch_ptr = kbd_buffer; 10879 kbd_fetch_ptr = kbd_buffer;