Mercurial > hg > xemacs-beta
comparison src/event-stream.c @ 86:364816949b59 r20-0b93
Import from CVS: tag r20-0b93
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:09:02 +0200 |
parents | 6a378aca36af |
children | 0d2f883870bc |
comparison
equal
deleted
inserted
replaced
85:c661705957e0 | 86:364816949b59 |
---|---|
258 keyboard and mouse events by pushing them here. | 258 keyboard and mouse events by pushing them here. |
259 | 259 |
260 Chained through event_next() | 260 Chained through event_next() |
261 command_event_queue_tail is a pointer to the last-added element. | 261 command_event_queue_tail is a pointer to the last-added element. |
262 */ | 262 */ |
263 static Lisp_Object process_event_queue; | |
264 static Lisp_Object process_event_queue_tail; | |
263 static Lisp_Object command_event_queue; | 265 static Lisp_Object command_event_queue; |
264 static Lisp_Object command_event_queue_tail; | 266 static Lisp_Object command_event_queue_tail; |
265 | 267 |
266 /* Nonzero means echo unfinished commands after this many seconds of pause. */ | 268 /* Nonzero means echo unfinished commands after this many seconds of pause. */ |
267 static int echo_keystrokes; | 269 static int echo_keystrokes; |
1448 | 1450 |
1449 /**********************************************************************/ | 1451 /**********************************************************************/ |
1450 /* enqueuing and dequeuing events */ | 1452 /* enqueuing and dequeuing events */ |
1451 /**********************************************************************/ | 1453 /**********************************************************************/ |
1452 | 1454 |
1455 /* Add an event to the back of the process_event_queue */ | |
1456 void | |
1457 enqueue_process_event (Lisp_Object event) | |
1458 { | |
1459 enqueue_event (event, &process_event_queue, &process_event_queue_tail); | |
1460 } | |
1461 | |
1462 Lisp_Object | |
1463 dequeue_process_event (void) | |
1464 { | |
1465 return dequeue_event (&process_event_queue, &process_event_queue_tail); | |
1466 } | |
1467 | |
1453 /* Add an event to the back of the command-event queue: it will be the next | 1468 /* Add an event to the back of the command-event queue: it will be the next |
1454 event read after all pending events. This only works on keyboard, | 1469 event read after all pending events. This only works on keyboard, |
1455 mouse-click, misc-user, and eval events. | 1470 mouse-click, misc-user, and eval events. |
1456 */ | 1471 */ |
1457 void | 1472 void |
1837 /* the number of keyboard characters read. callint.c wants this. | 1852 /* the number of keyboard characters read. callint.c wants this. |
1838 */ | 1853 */ |
1839 Charcount num_input_chars; | 1854 Charcount num_input_chars; |
1840 | 1855 |
1841 static void | 1856 static void |
1842 next_event_internal (Lisp_Object target_event, int allow_queued) | 1857 next_event_internal (Lisp_Object target_event, int allow_queued, |
1858 int allow_deferred) | |
1843 { | 1859 { |
1844 struct gcpro gcpro1; | 1860 struct gcpro gcpro1; |
1845 /* QUIT; This is incorrect - the caller must do this because some | 1861 /* QUIT; This is incorrect - the caller must do this because some |
1846 callers (ie, Fnext_event()) do not want to QUIT. */ | 1862 callers (ie, Fnext_event()) do not want to QUIT. */ |
1847 | 1863 |
1857 Fdeallocate_event (event); | 1873 Fdeallocate_event (event); |
1858 #ifdef DEBUG_XEMACS | 1874 #ifdef DEBUG_XEMACS |
1859 if (debug_emacs_events) | 1875 if (debug_emacs_events) |
1860 { | 1876 { |
1861 write_c_string ("(command event queue) ", | 1877 write_c_string ("(command event queue) ", |
1878 Qexternal_debugging_output); | |
1879 print_internal (target_event, Qexternal_debugging_output, 1); | |
1880 write_c_string ("\n", Qexternal_debugging_output); | |
1881 } | |
1882 #endif | |
1883 } | |
1884 else if (allow_deferred && !NILP (process_event_queue)) | |
1885 { | |
1886 Lisp_Object event = dequeue_process_event (); | |
1887 Fcopy_event (event, target_event); | |
1888 Fdeallocate_event (event); | |
1889 #ifdef DEBUG_EMACS | |
1890 if (debug_emacs_events) | |
1891 { | |
1892 write_c_string ("(process event queue) ", | |
1862 Qexternal_debugging_output); | 1893 Qexternal_debugging_output); |
1863 print_internal (target_event, Qexternal_debugging_output, 1); | 1894 print_internal (target_event, Qexternal_debugging_output, 1); |
1864 write_c_string ("\n", Qexternal_debugging_output); | 1895 write_c_string ("\n", Qexternal_debugging_output); |
1865 } | 1896 } |
1866 #endif | 1897 #endif |
2099 recent-keys. */ | 2130 recent-keys. */ |
2100 else | 2131 else |
2101 { | 2132 { |
2102 run_pre_idle_hook (); | 2133 run_pre_idle_hook (); |
2103 redisplay (); | 2134 redisplay (); |
2104 next_event_internal (event, 1); | 2135 next_event_internal (event, 1, 1); |
2105 Vquit_flag = Qnil; /* Read C-g as an event. */ | 2136 Vquit_flag = Qnil; /* Read C-g as an event. */ |
2106 store_this_key = 1; | 2137 store_this_key = 1; |
2107 } | 2138 } |
2108 } | 2139 } |
2109 | 2140 |
2300 || event_stream_event_pending_p (1)) | 2331 || event_stream_event_pending_p (1)) |
2301 { | 2332 { |
2302 /* This will take stuff off the command_event_queue, or read it | 2333 /* This will take stuff off the command_event_queue, or read it |
2303 from the event_stream, but it will not block. | 2334 from the event_stream, but it will not block. |
2304 */ | 2335 */ |
2305 next_event_internal (event, 1); | 2336 next_event_internal (event, 1, 1); |
2306 Vquit_flag = Qnil; /* Treat C-g as a user event (ignore it). | 2337 Vquit_flag = Qnil; /* Treat C-g as a user event (ignore it). |
2307 It is vitally important that we reset | 2338 It is vitally important that we reset |
2308 Vquit_flag here. Otherwise, if we're | 2339 Vquit_flag here. Otherwise, if we're |
2309 reading from a TTY console, | 2340 reading from a TTY console, |
2310 maybe_read_quit_event() will notice | 2341 maybe_read_quit_event() will notice |
2361 | 2392 |
2362 DEFUN ("accept-process-output", Faccept_process_output, 0, 3, 0, /* | 2393 DEFUN ("accept-process-output", Faccept_process_output, 0, 3, 0, /* |
2363 Allow any pending output from subprocesses to be read by Emacs. | 2394 Allow any pending output from subprocesses to be read by Emacs. |
2364 It is read into the process' buffers or given to their filter functions. | 2395 It is read into the process' buffers or given to their filter functions. |
2365 Non-nil arg PROCESS means do not return until some output has been received | 2396 Non-nil arg PROCESS means do not return until some output has been received |
2366 from PROCESS. | 2397 from PROCESS. Nil arg PROCESS means do not return until some output has |
2398 been received from any process. | |
2367 If the second arg is non-nil, it is the maximum number of seconds to wait: | 2399 If the second arg is non-nil, it is the maximum number of seconds to wait: |
2368 this function will return after that much time even if no input has arrived | 2400 this function will return after that much time even if no input has arrived |
2369 from PROCESS. This argument may be a float, meaning wait some fractional | 2401 from PROCESS. This argument may be a float, meaning wait some fractional |
2370 part of a second. | 2402 part of a second. |
2371 If the third arg is non-nil, it is a number of milliseconds that is added | 2403 If the third arg is non-nil, it is a number of milliseconds that is added |
2378 struct gcpro gcpro1, gcpro2; | 2410 struct gcpro gcpro1, gcpro2; |
2379 Lisp_Object event = Qnil; | 2411 Lisp_Object event = Qnil; |
2380 Lisp_Object result = Qnil; | 2412 Lisp_Object result = Qnil; |
2381 int timeout_id; | 2413 int timeout_id; |
2382 int timeout_enabled = 0; | 2414 int timeout_enabled = 0; |
2415 int done = 0; | |
2383 struct buffer *old_buffer = current_buffer; | 2416 struct buffer *old_buffer = current_buffer; |
2384 | 2417 |
2385 /* We preserve the current buffer but nothing else. If a focus | 2418 /* We preserve the current buffer but nothing else. If a focus |
2386 change alters the selected window then the top level event loop | 2419 change alters the selected window then the top level event loop |
2387 will eventually alter current_buffer to match. In the mean time | 2420 will eventually alter current_buffer to match. In the mean time |
2390 if (!NILP (process)) | 2423 if (!NILP (process)) |
2391 CHECK_PROCESS (process); | 2424 CHECK_PROCESS (process); |
2392 | 2425 |
2393 GCPRO2 (event, process); | 2426 GCPRO2 (event, process); |
2394 | 2427 |
2395 if (!NILP (process) && (!NILP (timeout_secs) || !NILP (timeout_msecs))) | 2428 if (!NILP (timeout_secs) || !NILP (timeout_msecs)) |
2396 { | 2429 { |
2397 unsigned long msecs = 0; | 2430 unsigned long msecs = 0; |
2398 if (!NILP (timeout_secs)) | 2431 if (!NILP (timeout_secs)) |
2399 msecs = lisp_number_to_milliseconds (timeout_secs, 1); | 2432 msecs = lisp_number_to_milliseconds (timeout_secs, 1); |
2400 if (!NILP (timeout_msecs)) | 2433 if (!NILP (timeout_msecs)) |
2409 } | 2442 } |
2410 } | 2443 } |
2411 | 2444 |
2412 event = Fmake_event (); | 2445 event = Fmake_event (); |
2413 | 2446 |
2414 while (!NILP (process) | 2447 while (!done && |
2448 ((NILP (process) && timeout_enabled) || | |
2449 (NILP (process) && event_stream_event_pending_p (0)) || | |
2450 (!NILP (process)))) | |
2415 /* Calling detect_input_pending() is the wrong thing here, because | 2451 /* Calling detect_input_pending() is the wrong thing here, because |
2416 that considers the Vunread_command_events and command_event_queue. | 2452 that considers the Vunread_command_events and command_event_queue. |
2417 We don't need to look at the command_event_queue because we are | 2453 We don't need to look at the command_event_queue because we are |
2418 only interested in process events, which don't go on that. In | 2454 only interested in process events, which don't go on that. In |
2419 fact, we can't read from it anyway, because we put stuff on it. | 2455 fact, we can't read from it anyway, because we put stuff on it. |
2424 to dispatch any process events that may be on the queue. It is | 2460 to dispatch any process events that may be on the queue. It is |
2425 not clear to me that this is important, because the top-level | 2461 not clear to me that this is important, because the top-level |
2426 loop will process it, and I don't think that there is ever a | 2462 loop will process it, and I don't think that there is ever a |
2427 time when one calls accept-process-output with a nil argument | 2463 time when one calls accept-process-output with a nil argument |
2428 and really need the processes to be handled. */ | 2464 and really need the processes to be handled. */ |
2429 || (!EQ (result, Qt) && event_stream_event_pending_p (0))) | |
2430 { | 2465 { |
2431 /* If our timeout has arrived, we move along. */ | 2466 /* If our timeout has arrived, we move along. */ |
2432 if (timeout_enabled && !event_stream_wakeup_pending_p (timeout_id, 0)) | 2467 if (timeout_enabled && !event_stream_wakeup_pending_p (timeout_id, 0)) |
2433 { | 2468 { |
2434 timeout_enabled = 0; | 2469 timeout_enabled = 0; |
2435 process = Qnil; /* We're done. */ | 2470 done = 1; /* We're done. */ |
2471 continue; /* Don't call next_event_internal */ | |
2436 } | 2472 } |
2437 | 2473 |
2438 QUIT; /* next_event_internal() does not QUIT, so check for ^G | 2474 QUIT; /* next_event_internal() does not QUIT, so check for ^G |
2439 before reading output from the process - this makes it | 2475 before reading output from the process - this makes it |
2440 less likely that the filter will actually be aborted. | 2476 less likely that the filter will actually be aborted. |
2441 */ | 2477 */ |
2442 | 2478 |
2443 next_event_internal (event, 0); | 2479 next_event_internal (event, 0, 1); |
2444 /* If C-g was pressed while we were waiting, Vquit_flag got | 2480 /* If C-g was pressed while we were waiting, Vquit_flag got |
2445 set and next_event_internal() also returns C-g. When | 2481 set and next_event_internal() also returns C-g. When |
2446 we enqueue the C-g below, it will get discarded. The | 2482 we enqueue the C-g below, it will get discarded. The |
2447 next time through, QUIT will be called and will signal a quit. */ | 2483 next time through, QUIT will be called and will signal a quit. */ |
2448 switch (XEVENT_TYPE (event)) | 2484 switch (XEVENT_TYPE (event)) |
2449 { | 2485 { |
2450 case process_event: | 2486 case process_event: |
2451 { | 2487 { |
2452 if (EQ (XEVENT (event)->event.process.process, process)) | 2488 if (NILP (process) || |
2489 EQ (XEVENT (event)->event.process.process, process)) | |
2453 { | 2490 { |
2454 process = Qnil; | 2491 done = 1; |
2455 /* RMS's version always returns nil when proc is nil, | 2492 /* RMS's version always returns nil when proc is nil, |
2456 and only returns t if input ever arrived on proc. */ | 2493 and only returns t if input ever arrived on proc. */ |
2457 result = Qt; | 2494 result = Qt; |
2458 } | 2495 } |
2459 | 2496 |
2516 */ | 2553 */ |
2517 /* We're a generator of the command_event_queue, so we can't be a | 2554 /* We're a generator of the command_event_queue, so we can't be a |
2518 consumer as well. We don't care about command and eval-events | 2555 consumer as well. We don't care about command and eval-events |
2519 anyway. | 2556 anyway. |
2520 */ | 2557 */ |
2521 next_event_internal (event, 0); /* blocks */ | 2558 next_event_internal (event, 0, 0); /* blocks */ |
2522 /* See the comment in accept-process-output about Vquit_flag */ | 2559 /* See the comment in accept-process-output about Vquit_flag */ |
2523 switch (XEVENT_TYPE (event)) | 2560 switch (XEVENT_TYPE (event)) |
2524 { | 2561 { |
2562 case process_event: | |
2563 { | |
2564 /* Avoid calling filter functions recursively by squirreling | |
2565 away process events */ | |
2566 enqueue_process_event (Fcopy_event (event, Qnil)); | |
2567 goto DONE_LABEL; | |
2568 } | |
2569 | |
2525 case timeout_event: | 2570 case timeout_event: |
2526 /* We execute the event even if it's ours, and notice that it's | 2571 /* We execute the event even if it's ours, and notice that it's |
2527 happened above. */ | 2572 happened above. */ |
2528 case pointer_motion_event: | 2573 case pointer_motion_event: |
2529 case process_event: | |
2530 case magic_event: | 2574 case magic_event: |
2531 { | 2575 { |
2532 EXECUTE_INTERNAL: | 2576 EXECUTE_INTERNAL: |
2533 execute_internal_event (event); | 2577 execute_internal_event (event); |
2534 break; | 2578 break; |
2621 */ | 2665 */ |
2622 /* We're a generator of the command_event_queue, so we can't be a | 2666 /* We're a generator of the command_event_queue, so we can't be a |
2623 consumer as well. In fact, we know there's nothing on the | 2667 consumer as well. In fact, we know there's nothing on the |
2624 command_event_queue that we didn't just put there. | 2668 command_event_queue that we didn't just put there. |
2625 */ | 2669 */ |
2626 next_event_internal (event, 0); /* blocks */ | 2670 next_event_internal (event, 0, 0); /* blocks */ |
2627 /* See the comment in accept-process-output about Vquit_flag */ | 2671 /* See the comment in accept-process-output about Vquit_flag */ |
2628 | 2672 |
2629 if (command_event_p (event)) | 2673 if (command_event_p (event)) |
2630 { | 2674 { |
2631 result = Qnil; | 2675 result = Qnil; |
2637 { | 2681 { |
2638 /* eval-events get delayed until later. */ | 2682 /* eval-events get delayed until later. */ |
2639 enqueue_command_event (Fcopy_event (event, Qnil)); | 2683 enqueue_command_event (Fcopy_event (event, Qnil)); |
2640 break; | 2684 break; |
2641 } | 2685 } |
2686 | |
2687 case process_event: | |
2688 { | |
2689 /* Avoid recursive calls to process filters */ | |
2690 enqueue_process_event (Fcopy_event (event, Qnil)); | |
2691 break; | |
2692 } | |
2693 | |
2642 case timeout_event: | 2694 case timeout_event: |
2643 /* We execute the event even if it's ours, and notice that it's | 2695 /* We execute the event even if it's ours, and notice that it's |
2644 happened above. */ | 2696 happened above. */ |
2645 default: | 2697 default: |
2646 { | 2698 { |
2691 /* We're a generator of the command_event_queue, so we can't be a | 2743 /* We're a generator of the command_event_queue, so we can't be a |
2692 consumer as well. Also, we have no reason to consult the | 2744 consumer as well. Also, we have no reason to consult the |
2693 command_event_queue; there are only user and eval-events there, | 2745 command_event_queue; there are only user and eval-events there, |
2694 and we'd just have to put them back anyway. | 2746 and we'd just have to put them back anyway. |
2695 */ | 2747 */ |
2696 next_event_internal (event, 0); | 2748 next_event_internal (event, 0, 1); |
2697 /* See the comment in accept-process-output about Vquit_flag */ | 2749 /* See the comment in accept-process-output about Vquit_flag */ |
2698 if (command_event_p (event) | 2750 if (command_event_p (event) |
2699 || (XEVENT_TYPE (event) == eval_event) | 2751 || (XEVENT_TYPE (event) == eval_event) |
2700 || (XEVENT_TYPE (event) == magic_eval_event)) | 2752 || (XEVENT_TYPE (event) == magic_eval_event)) |
2701 enqueue_command_event_1 (event); | 2753 enqueue_command_event_1 (event); |
4127 | 4179 |
4128 command_event_queue = Qnil; | 4180 command_event_queue = Qnil; |
4129 staticpro (&command_event_queue); | 4181 staticpro (&command_event_queue); |
4130 command_event_queue_tail = Qnil; | 4182 command_event_queue_tail = Qnil; |
4131 | 4183 |
4184 process_event_queue = Qnil; | |
4185 staticpro (&process_event_queue); | |
4186 process_event_queue_tail = Qnil; | |
4187 | |
4132 Vlast_selected_frame = Qnil; | 4188 Vlast_selected_frame = Qnil; |
4133 staticpro (&Vlast_selected_frame); | 4189 staticpro (&Vlast_selected_frame); |
4134 | 4190 |
4135 pending_timeout_list = Qnil; | 4191 pending_timeout_list = Qnil; |
4136 staticpro (&pending_timeout_list); | 4192 staticpro (&pending_timeout_list); |