diff options
| author | Richard M. Stallman | 1995-04-10 07:46:48 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-04-10 07:46:48 +0000 |
| commit | 1e8bd3dad9892b4ffffc183c6f208706c5781da4 (patch) | |
| tree | 2c4f4d0e7d49199fa1bd7cfeaf99c77599b307ea /src | |
| parent | 931e7866164d09f01fa717a0b1d8c7cb1ffc1ece (diff) | |
| download | emacs-1e8bd3dad9892b4ffffc183c6f208706c5781da4.tar.gz emacs-1e8bd3dad9892b4ffffc183c6f208706c5781da4.zip | |
(any_kboard_state): Renamed from unlock_kboard.
Define it unconditionally, but it's a no-op unless MULTI_KBOARD.
(single_kboard_state): New function.
(push_frame_kboard, pop_frame_kboard): New functions.
(single_kboard): Renamed from kboard_locked.
(unlock_kboard): Do nothing with Vunread_command_events.
(read_char): Clean up logic for reading from KBOARD queues.
(kbd_buffer_get_event): Set copy by assignment, not init.
Diffstat (limited to 'src')
| -rw-r--r-- | src/keyboard.c | 177 |
1 files changed, 123 insertions, 54 deletions
diff --git a/src/keyboard.c b/src/keyboard.c index 9642dcad133..cd50ed04055 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -98,7 +98,7 @@ struct backtrace | |||
| 98 | KBOARD *initial_kboard; | 98 | KBOARD *initial_kboard; |
| 99 | KBOARD *current_kboard; | 99 | KBOARD *current_kboard; |
| 100 | KBOARD *all_kboards; | 100 | KBOARD *all_kboards; |
| 101 | int kboard_locked; | 101 | int single_kboard; |
| 102 | #else | 102 | #else |
| 103 | KBOARD the_only_kboard; | 103 | KBOARD the_only_kboard; |
| 104 | #endif | 104 | #endif |
| @@ -397,7 +397,7 @@ static Lisp_Object do_mouse_tracking; | |||
| 397 | call mouse_position_hook to get the promised position, so don't set | 397 | call mouse_position_hook to get the promised position, so don't set |
| 398 | it unless you're prepared to substantiate the claim! */ | 398 | it unless you're prepared to substantiate the claim! */ |
| 399 | int mouse_moved; | 399 | int mouse_moved; |
| 400 | #endif /* HAVE_MOUSE. */ | 400 | #endif /* HAVE_MOUSE */ |
| 401 | 401 | ||
| 402 | /* Symbols to head events. */ | 402 | /* Symbols to head events. */ |
| 403 | Lisp_Object Qmouse_movement; | 403 | Lisp_Object Qmouse_movement; |
| @@ -753,10 +753,14 @@ recursive_edit_unwind (buffer) | |||
| 753 | return Qnil; | 753 | return Qnil; |
| 754 | } | 754 | } |
| 755 | 755 | ||
| 756 | #ifdef MULTI_KBOARD | ||
| 757 | static void | 756 | static void |
| 758 | unlock_kboard () | 757 | any_kboard_state () |
| 759 | { | 758 | { |
| 759 | #ifdef MULTI_KBOARD | ||
| 760 | #if 0 /* Theory: if there's anything in Vunread_command_events, | ||
| 761 | it will right away be read by read_key_sequence, | ||
| 762 | and then if we do switch KBOARDS, it will go into the side | ||
| 763 | queue then. So we don't need to do anything special here -- rms. */ | ||
| 760 | if (CONSP (Vunread_command_events)) | 764 | if (CONSP (Vunread_command_events)) |
| 761 | { | 765 | { |
| 762 | current_kboard->kbd_queue | 766 | current_kboard->kbd_queue |
| @@ -764,9 +768,59 @@ unlock_kboard () | |||
| 764 | current_kboard->kbd_queue_has_data = 1; | 768 | current_kboard->kbd_queue_has_data = 1; |
| 765 | } | 769 | } |
| 766 | Vunread_command_events = Qnil; | 770 | Vunread_command_events = Qnil; |
| 767 | kboard_locked = 0; | 771 | #endif |
| 772 | single_kboard = 0; | ||
| 773 | #endif | ||
| 768 | } | 774 | } |
| 775 | |||
| 776 | /* Switch to the single-kboard state, making current_kboard | ||
| 777 | the only KBOARD from which further input is accepted. */ | ||
| 778 | |||
| 779 | void | ||
| 780 | single_kboard_state () | ||
| 781 | { | ||
| 782 | #ifdef MULTI_KBOARD | ||
| 783 | single_kboard = 1; | ||
| 769 | #endif | 784 | #endif |
| 785 | } | ||
| 786 | |||
| 787 | /* Maintain a stack of kboards, so other parts of Emacs | ||
| 788 | can switch temporarily to the kboard of a given frame | ||
| 789 | and then revert to the previous status. */ | ||
| 790 | |||
| 791 | struct kboard_stack | ||
| 792 | { | ||
| 793 | KBOARD *kboard; | ||
| 794 | struct kboard_stack *next; | ||
| 795 | }; | ||
| 796 | |||
| 797 | static struct kboard_stack *kboard_stack; | ||
| 798 | |||
| 799 | void | ||
| 800 | push_frame_kboard (f) | ||
| 801 | FRAME_PTR f; | ||
| 802 | { | ||
| 803 | struct kboard_stack *p | ||
| 804 | = (struct kboard_stack *) xmalloc (sizeof (struct kboard_stack)); | ||
| 805 | |||
| 806 | p->next = kboard_stack; | ||
| 807 | p->kboard = current_kboard; | ||
| 808 | kboard_stack = p; | ||
| 809 | |||
| 810 | current_kboard = FRAME_KBOARD (f); | ||
| 811 | } | ||
| 812 | |||
| 813 | void | ||
| 814 | pop_frame_kboard () | ||
| 815 | { | ||
| 816 | struct kboard_stack *p = kboard_stack; | ||
| 817 | current_kboard = p->kboard; | ||
| 818 | kboard_stack = p->next; | ||
| 819 | xfree (p); | ||
| 820 | } | ||
| 821 | |||
| 822 | /* Handle errors that are not handled at inner levels | ||
| 823 | by printing an error message and returning to the editor command loop. */ | ||
| 770 | 824 | ||
| 771 | Lisp_Object | 825 | Lisp_Object |
| 772 | cmd_error (data) | 826 | cmd_error (data) |
| @@ -793,7 +847,7 @@ cmd_error (data) | |||
| 793 | 847 | ||
| 794 | Vinhibit_quit = Qnil; | 848 | Vinhibit_quit = Qnil; |
| 795 | #ifdef MULTI_KBOARD | 849 | #ifdef MULTI_KBOARD |
| 796 | unlock_kboard (); | 850 | any_kboard_state (); |
| 797 | #endif | 851 | #endif |
| 798 | 852 | ||
| 799 | return make_number (0); | 853 | return make_number (0); |
| @@ -993,7 +1047,7 @@ command_loop_1 () | |||
| 993 | int prev_modiff; | 1047 | int prev_modiff; |
| 994 | struct buffer *prev_buffer; | 1048 | struct buffer *prev_buffer; |
| 995 | #ifdef MULTI_KBOARD | 1049 | #ifdef MULTI_KBOARD |
| 996 | int was_locked = kboard_locked; | 1050 | int was_locked = single_kboard; |
| 997 | #endif | 1051 | #endif |
| 998 | 1052 | ||
| 999 | Vdeactivate_mark = Qnil; | 1053 | Vdeactivate_mark = Qnil; |
| @@ -1338,7 +1392,7 @@ command_loop_1 () | |||
| 1338 | 1392 | ||
| 1339 | #ifdef MULTI_KBOARD | 1393 | #ifdef MULTI_KBOARD |
| 1340 | if (!was_locked) | 1394 | if (!was_locked) |
| 1341 | unlock_kboard (); | 1395 | any_kboard_state (); |
| 1342 | #endif | 1396 | #endif |
| 1343 | } | 1397 | } |
| 1344 | } | 1398 | } |
| @@ -1661,8 +1715,8 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu) | |||
| 1661 | if (kb != current_kboard) | 1715 | if (kb != current_kboard) |
| 1662 | { | 1716 | { |
| 1663 | Lisp_Object *tailp = &kb->kbd_queue; | 1717 | Lisp_Object *tailp = &kb->kbd_queue; |
| 1664 | /* We shouldn't get here if we were locked onto one kboard! */ | 1718 | /* We shouldn't get here if we were in single-kboard mode! */ |
| 1665 | if (kboard_locked) | 1719 | if (single_kboard) |
| 1666 | abort (); | 1720 | abort (); |
| 1667 | while (CONSP (*tailp)) | 1721 | while (CONSP (*tailp)) |
| 1668 | tailp = &XCONS (*tailp)->cdr; | 1722 | tailp = &XCONS (*tailp)->cdr; |
| @@ -1803,11 +1857,8 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu) | |||
| 1803 | 1857 | ||
| 1804 | if (NILP (c)) | 1858 | if (NILP (c)) |
| 1805 | { | 1859 | { |
| 1806 | /* Primary consideration goes to current_kboard's side queue. | 1860 | /* Primary consideration goes to current_kboard's side queue. */ |
| 1807 | If that's empty, then we check the other side queues and throw | 1861 | |
| 1808 | if we find something there. Finally, we read from the main queue, | ||
| 1809 | and if that gives us something we can't use yet, we put it on the | ||
| 1810 | appropriate side queue and try again. */ | ||
| 1811 | if (current_kboard->kbd_queue_has_data) | 1862 | if (current_kboard->kbd_queue_has_data) |
| 1812 | { | 1863 | { |
| 1813 | if (!CONSP (current_kboard->kbd_queue)) | 1864 | if (!CONSP (current_kboard->kbd_queue)) |
| @@ -1825,50 +1876,66 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu) | |||
| 1825 | Vlast_event_frame = internal_last_event_frame; | 1876 | Vlast_event_frame = internal_last_event_frame; |
| 1826 | #endif | 1877 | #endif |
| 1827 | } | 1878 | } |
| 1828 | else | 1879 | } |
| 1829 | { | 1880 | |
| 1830 | KBOARD *kb; | ||
| 1831 | #ifdef MULTI_KBOARD | 1881 | #ifdef MULTI_KBOARD |
| 1832 | if (!kboard_locked) | 1882 | /* If current_kboard's side queue is empty check the other kboards. |
| 1833 | { | 1883 | If one of them has data that we have not yet seen here, |
| 1834 | for (kb = all_kboards; kb; kb = kb->next_kboard) | 1884 | switch to it and process the data waiting for it. |
| 1835 | if (kb->kbd_queue_has_data) | 1885 | |
| 1836 | { | 1886 | Note: if the events queued up for another kboard |
| 1837 | current_kboard = kb; | 1887 | have already been seen here, and therefore are not a complete command, |
| 1838 | longjmp (wrong_kboard_jmpbuf, 1); | 1888 | the kbd_queue_has_data field is 0, so we skip that kboard here. |
| 1839 | } | 1889 | That's to avoid an infinite loop switching between kboards here. */ |
| 1840 | } | 1890 | if (NILP (c) && !single_kboard) |
| 1891 | { | ||
| 1892 | KBOARD *kb; | ||
| 1893 | for (kb = all_kboards; kb; kb = kb->next_kboard) | ||
| 1894 | if (kb->kbd_queue_has_data) | ||
| 1895 | { | ||
| 1896 | current_kboard = kb; | ||
| 1897 | longjmp (wrong_kboard_jmpbuf, 1); | ||
| 1898 | } | ||
| 1899 | } | ||
| 1841 | #endif | 1900 | #endif |
| 1842 | 1901 | ||
| 1843 | wrong_kboard: | 1902 | /* Finally, we read from the main queue, |
| 1844 | /* Actually read a character, waiting if necessary. */ | 1903 | and if that gives us something we can't use yet, we put it on the |
| 1845 | while (c = kbd_buffer_get_event (&kb), NILP (c)) | 1904 | appropriate side queue and try again. */ |
| 1905 | if (NILP (c)) | ||
| 1906 | { | ||
| 1907 | KBOARD *kb; | ||
| 1908 | |||
| 1909 | wrong_kboard: | ||
| 1910 | |||
| 1911 | /* Actually read a character, waiting if necessary. */ | ||
| 1912 | while (c = kbd_buffer_get_event (&kb), NILP (c)) | ||
| 1913 | { | ||
| 1914 | if (commandflag >= 0 | ||
| 1915 | && !input_pending && !detect_input_pending ()) | ||
| 1846 | { | 1916 | { |
| 1847 | if (commandflag >= 0 | 1917 | prepare_menu_bars (); |
| 1848 | && !input_pending && !detect_input_pending ()) | 1918 | redisplay (); |
| 1849 | { | ||
| 1850 | prepare_menu_bars (); | ||
| 1851 | redisplay (); | ||
| 1852 | } | ||
| 1853 | } | 1919 | } |
| 1920 | } | ||
| 1854 | #ifdef MULTI_KBOARD | 1921 | #ifdef MULTI_KBOARD |
| 1855 | if (kb != current_kboard) | 1922 | if (kb != current_kboard) |
| 1856 | { | 1923 | { |
| 1857 | Lisp_Object *tailp = &kb->kbd_queue; | 1924 | Lisp_Object *tailp = &kb->kbd_queue; |
| 1858 | while (CONSP (*tailp)) | 1925 | while (CONSP (*tailp)) |
| 1859 | tailp = &XCONS (*tailp)->cdr; | 1926 | tailp = &XCONS (*tailp)->cdr; |
| 1860 | if (!NILP (*tailp)) | 1927 | if (!NILP (*tailp)) |
| 1861 | abort (); | 1928 | abort (); |
| 1862 | *tailp = Fcons (c, Qnil); | 1929 | *tailp = Fcons (c, Qnil); |
| 1863 | kb->kbd_queue_has_data = 1; | 1930 | kb->kbd_queue_has_data = 1; |
| 1864 | if (kboard_locked) | 1931 | if (single_kboard) |
| 1865 | goto wrong_kboard; | 1932 | goto wrong_kboard; |
| 1866 | current_kboard = kb; | 1933 | current_kboard = kb; |
| 1867 | longjmp (wrong_kboard_jmpbuf, 1); | 1934 | longjmp (wrong_kboard_jmpbuf, 1); |
| 1868 | } | ||
| 1869 | #endif | ||
| 1870 | } | 1935 | } |
| 1936 | #endif | ||
| 1871 | } | 1937 | } |
| 1938 | |||
| 1872 | /* Terminate Emacs in batch mode if at eof. */ | 1939 | /* Terminate Emacs in batch mode if at eof. */ |
| 1873 | if (noninteractive && INTEGERP (c) && XINT (c) < 0) | 1940 | if (noninteractive && INTEGERP (c) && XINT (c) < 0) |
| 1874 | Fkill_emacs (make_number (1)); | 1941 | Fkill_emacs (make_number (1)); |
| @@ -2145,7 +2212,7 @@ readable_events () | |||
| 2145 | if (FRAMEP (do_mouse_tracking) && mouse_moved) | 2212 | if (FRAMEP (do_mouse_tracking) && mouse_moved) |
| 2146 | return 1; | 2213 | return 1; |
| 2147 | #endif | 2214 | #endif |
| 2148 | if (kboard_locked) | 2215 | if (single_kboard) |
| 2149 | { | 2216 | { |
| 2150 | if (current_kboard->kbd_queue_has_data) | 2217 | if (current_kboard->kbd_queue_has_data) |
| 2151 | return 1; | 2218 | return 1; |
| @@ -2212,7 +2279,7 @@ kbd_buffer_store_event (event) | |||
| 2212 | KBOARD *kb; | 2279 | KBOARD *kb; |
| 2213 | struct input_event *sp; | 2280 | struct input_event *sp; |
| 2214 | 2281 | ||
| 2215 | if (kboard_locked | 2282 | if (single_kboard |
| 2216 | && (kb = FRAME_KBOARD (XFRAME (event->frame_or_window)), | 2283 | && (kb = FRAME_KBOARD (XFRAME (event->frame_or_window)), |
| 2217 | kb != current_kboard)) | 2284 | kb != current_kboard)) |
| 2218 | { | 2285 | { |
| @@ -2392,10 +2459,12 @@ kbd_buffer_get_event (KBOARD **kbp) | |||
| 2392 | if (event->kind == selection_request_event) | 2459 | if (event->kind == selection_request_event) |
| 2393 | { | 2460 | { |
| 2394 | #ifdef HAVE_X11 | 2461 | #ifdef HAVE_X11 |
| 2395 | struct input_event copy = *event; | 2462 | struct input_event copy; |
| 2463 | |||
| 2396 | /* Remove it from the buffer before processing it, | 2464 | /* Remove it from the buffer before processing it, |
| 2397 | since otherwise swallow_events will see it | 2465 | since otherwise swallow_events will see it |
| 2398 | and process it again. */ | 2466 | and process it again. */ |
| 2467 | copy = *event; | ||
| 2399 | kbd_fetch_ptr = event + 1; | 2468 | kbd_fetch_ptr = event + 1; |
| 2400 | x_handle_selection_request (©); | 2469 | x_handle_selection_request (©); |
| 2401 | #else | 2470 | #else |