comparison src/keyboard.c @ 2188:f74e9c948380

(command_loop_1): Set FRAME_MENU_BAR_ITEMS here. (menu_bar_items): Reverse the list when done. (command_loop_1): Typo calling Qrecompute_lucid_menubar. (read_key_sequence): Likewise. Also fix call to Vrun_hooks. (kbd_buffer_get_event): Handle selection_clear_event and selection_request_event events. (read_key_sequence): Support Vcurrent_menubar and Qactivate_menubar_hook. Call Qrecompute_lucid_menubar. (syms_of_keyboard): Set up Vcurrent_menubar, Vprevious_lucid_menubar, Qactivate_menubar_hook, and Qrecompute_lucid_menubar.
author Richard M. Stallman <rms@gnu.org>
date Mon, 15 Mar 1993 05:46:58 +0000
parents 9e21e9f8bb0d
children 36cc4399937f
comparison
equal deleted inserted replaced
2187:12b50e8d3b1c 2188:f74e9c948380
243 extern Lisp_Object Vfunction_key_map; 243 extern Lisp_Object Vfunction_key_map;
244 244
245 /* Non-nil means deactivate the mark at end of this command. */ 245 /* Non-nil means deactivate the mark at end of this command. */
246 Lisp_Object Vdeactivate_mark; 246 Lisp_Object Vdeactivate_mark;
247 247
248 /* Menu bar specified in Lucid Emacs fashion. */
249
250 Lisp_Object Vlucid_menu_bar_dirty_flag;
251 Lisp_Object Qrecompute_lucid_menubar, Qactivate_menubar_hook;
252
248 /* Hooks to run before and after each command. */ 253 /* Hooks to run before and after each command. */
249 Lisp_Object Qpre_command_hook, Qpost_command_hook; 254 Lisp_Object Qpre_command_hook, Qpost_command_hook;
250 Lisp_Object Vpre_command_hook, Vpost_command_hook; 255 Lisp_Object Vpre_command_hook, Vpost_command_hook;
251 256
252 /* File in which we write all commands we read. */ 257 /* File in which we write all commands we read. */
833 static int read_key_sequence (); 838 static int read_key_sequence ();
834 839
835 Lisp_Object 840 Lisp_Object
836 command_loop_1 () 841 command_loop_1 ()
837 { 842 {
838 Lisp_Object cmd; 843 Lisp_Object cmd, tem;
839 int lose; 844 int lose;
840 int nonundocount; 845 int nonundocount;
841 Lisp_Object keybuf[30]; 846 Lisp_Object keybuf[30];
842 int i; 847 int i;
843 int no_redisplay; 848 int no_redisplay;
914 if (XTYPE (internal_last_event_frame) == Lisp_Frame 919 if (XTYPE (internal_last_event_frame) == Lisp_Frame
915 && XFRAME (internal_last_event_frame) != selected_frame) 920 && XFRAME (internal_last_event_frame) != selected_frame)
916 Fselect_frame (internal_last_event_frame, Qnil); 921 Fselect_frame (internal_last_event_frame, Qnil);
917 #endif 922 #endif
918 #endif 923 #endif
924 /* If it has changed current-menubar from previous value,
925 really recompute the menubar from the value. */
926 if (! NILP (Vlucid_menu_bar_dirty_flag))
927 call0 (Qrecompute_lucid_menubar);
928
929 #ifdef MULTI_FRAME
930 for (tem = Vframe_list; CONSP (tem); tem = XCONS (tem)->cdr)
931 {
932 struct frame *f = XFRAME (XCONS (tem)->car);
933 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
934 if (windows_or_buffers_changed
935 || (XFASTINT (w->last_modified) < MODIFF
936 && (XFASTINT (w->last_modified)
937 <= XBUFFER (w->buffer)->save_modified)))
938 {
939 struct buffer *prev = current_buffer;
940 current_buffer = XBUFFER (w->buffer);
941 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items ();
942 current_buffer = prev;
943 }
944 }
945 #endif /* MULTI_FRAME */
919 946
920 /* Read next key sequence; i gets its length. */ 947 /* Read next key sequence; i gets its length. */
921 i = read_key_sequence (keybuf, (sizeof keybuf / sizeof (keybuf[0])), 0); 948 i = read_key_sequence (keybuf, (sizeof keybuf / sizeof (keybuf[0])), 0);
922 949
923 ++num_input_keys; 950 ++num_input_keys;
1676 c = getchar (); 1703 c = getchar ();
1677 XSET (obj, Lisp_Int, c); 1704 XSET (obj, Lisp_Int, c);
1678 return obj; 1705 return obj;
1679 } 1706 }
1680 1707
1708 retry:
1681 /* Wait until there is input available. */ 1709 /* Wait until there is input available. */
1682 for (;;) 1710 for (;;)
1683 { 1711 {
1684 if (!EVENT_QUEUES_EMPTY) 1712 if (!EVENT_QUEUES_EMPTY)
1685 break; 1713 break;
1727 1755
1728 last_event_timestamp = event->timestamp; 1756 last_event_timestamp = event->timestamp;
1729 1757
1730 obj = Qnil; 1758 obj = Qnil;
1731 1759
1760 /* These two kinds of events get special handling
1761 and don't actually appear to the command loop. */
1762 if (event->kind == selection_request_event)
1763 {
1764 x_handle_selection_request (event);
1765 kbd_fetch_ptr = event + 1;
1766 goto retry;
1767 }
1768
1769 if (event->kind == selection_clear_event)
1770 {
1771 x_handle_selection_clear (event);
1772 kbd_fetch_ptr = event + 1;
1773 goto retry;
1774 }
1775
1732 #ifdef MULTI_FRAME 1776 #ifdef MULTI_FRAME
1733 /* If this event is on a different frame, return a switch-frame this 1777 /* If this event is on a different frame, return a switch-frame this
1734 time, and leave the event in the queue for next time. */ 1778 time, and leave the event in the queue for next time. */
1735 { 1779 {
1736 Lisp_Object frame = event->frame_or_window; 1780 Lisp_Object frame = event->frame_or_window;
1803 } 1847 }
1804 else 1848 else
1805 /* We were promised by the above while loop that there was 1849 /* We were promised by the above while loop that there was
1806 something for us to read! */ 1850 something for us to read! */
1807 abort (); 1851 abort ();
1852
1853 /* If something gave back nil as the Lispy event,
1854 it means the event was discarded, so try again. */
1855 if (NILP (obj))
1856 goto retry;
1808 1857
1809 input_pending = readable_events (); 1858 input_pending = readable_events ();
1810 1859
1811 #ifdef MULTI_FRAME 1860 #ifdef MULTI_FRAME
1812 Vlast_event_frame = internal_last_event_frame; 1861 Vlast_event_frame = internal_last_event_frame;
2094 2143
2095 /* Now we're releasing a button - check the co-ordinates to 2144 /* Now we're releasing a button - check the co-ordinates to
2096 see if this was a click or a drag. */ 2145 see if this was a click or a drag. */
2097 else if (event->modifiers & up_modifier) 2146 else if (event->modifiers & up_modifier)
2098 { 2147 {
2099 /* Is there a start position stored at all for this 2148 /* If we did not see a down before this up,
2100 button? 2149 ignore the up. Probably this happened because
2101 2150 the down event chose a menu item.
2102 It would be nice if we could assume that if we're 2151 It would be an annoyance to treat the release
2103 getting a button release, we must therefore have gotten 2152 of the button that chose the menu item
2104 a button press. Unfortunately, the X menu code thwarts 2153 as a separate event. */
2105 this assumption, so we'll have to be more robust. We 2154
2106 treat a button release with no stored start position as 2155 if (XTYPE (start_pos) != Lisp_Cons)
2107 a click. */ 2156 return Qnil;
2157
2108 event->modifiers &= ~up_modifier; 2158 event->modifiers &= ~up_modifier;
2159 #if 0 /* Formerly we treated an up with no down as a click event. */
2109 if (XTYPE (start_pos) != Lisp_Cons) 2160 if (XTYPE (start_pos) != Lisp_Cons)
2110 event->modifiers |= click_modifier; 2161 event->modifiers |= click_modifier;
2111 else 2162 else
2163 #endif
2112 { 2164 {
2113 /* The third element of every position should be the (x,y) 2165 /* The third element of every position should be the (x,y)
2114 pair. */ 2166 pair. */
2115 Lisp_Object down = Fnth (make_number (2), start_pos); 2167 Lisp_Object down = Fnth (make_number (2), start_pos);
2116 2168
2147 } 2199 }
2148 } 2200 }
2149 2201
2150 /* The 'kind' field of the event is something we don't recognize. */ 2202 /* The 'kind' field of the event is something we don't recognize. */
2151 default: 2203 default:
2152 abort(); 2204 abort ();
2153 } 2205 }
2154 } 2206 }
2155 2207
2156 static Lisp_Object 2208 static Lisp_Object
2157 make_lispy_movement (frame, bar_window, part, x, y, time) 2209 make_lispy_movement (frame, bar_window, part, x, y, time)
2877 tem = Fkeymapp (def); 2929 tem = Fkeymapp (def);
2878 if (!NILP (tem)) 2930 if (!NILP (tem))
2879 result = menu_bar_one_keymap (def, result); 2931 result = menu_bar_one_keymap (def, result);
2880 } 2932 }
2881 2933
2882 return result; 2934 return Fnreverse (result);
2883 } 2935 }
2884 2936
2885 /* Scan one map KEYMAP, accumulating any menu items it defines 2937 /* Scan one map KEYMAP, accumulating any menu items it defines
2886 that have not yet been seen in RESULT. Return the updated RESULT. */ 2938 that have not yet been seen in RESULT. Return the updated RESULT. */
2887 2939
3284 with respect to the buffer clicked on, not the current buffer. 3336 with respect to the buffer clicked on, not the current buffer.
3285 3337
3286 If the user switches frames in the midst of a key sequence, we put 3338 If the user switches frames in the midst of a key sequence, we put
3287 off the switch-frame event until later; the next call to 3339 off the switch-frame event until later; the next call to
3288 read_char will return it. */ 3340 read_char will return it. */
3341
3289 static int 3342 static int
3290 read_key_sequence (keybuf, bufsize, prompt) 3343 read_key_sequence (keybuf, bufsize, prompt)
3291 Lisp_Object *keybuf; 3344 Lisp_Object *keybuf;
3292 int bufsize; 3345 int bufsize;
3293 char *prompt; 3346 char *prompt;
3566 insert the dummy prefix char `menu-bar'. */ 3619 insert the dummy prefix char `menu-bar'. */
3567 if (EQ (posn, Qmenu_bar)) 3620 if (EQ (posn, Qmenu_bar))
3568 { 3621 {
3569 if (t + 1 >= bufsize) 3622 if (t + 1 >= bufsize)
3570 error ("key sequence too long"); 3623 error ("key sequence too long");
3624 /* Run the Lucid hook. */
3625 call1 (Vrun_hooks, Qactivate_menubar_hook);
3626 /* If it has changed current-menubar from previous value,
3627 really recompute the menubar from the value. */
3628 if (! NILP (Vlucid_menu_bar_dirty_flag))
3629 call0 (Qrecompute_lucid_menubar);
3571 keybuf[t] = posn; 3630 keybuf[t] = posn;
3572 keybuf[t+1] = key; 3631 keybuf[t+1] = key;
3573 mock_input = t + 2; 3632 mock_input = t + 2;
3574 goto replay_sequence; 3633 goto replay_sequence;
3575 } 3634 }
4487 Qevent_symbol_element_mask = intern ("event-symbol-element-mask"); 4546 Qevent_symbol_element_mask = intern ("event-symbol-element-mask");
4488 staticpro (&Qevent_symbol_element_mask); 4547 staticpro (&Qevent_symbol_element_mask);
4489 Qmodifier_cache = intern ("modifier-cache"); 4548 Qmodifier_cache = intern ("modifier-cache");
4490 staticpro (&Qmodifier_cache); 4549 staticpro (&Qmodifier_cache);
4491 4550
4551 Qrecompute_lucid_menubar = intern ("recompute-lucid-menubar");
4552 staticpro (&Qrecompute_lucid_menubar);
4553 Qactivate_menubar_hook = intern ("activate-menubar-hook");
4554 staticpro (&Qactivate_menubar_hook);
4555
4492 { 4556 {
4493 struct event_head *p; 4557 struct event_head *p;
4494 4558
4495 for (p = head_table; 4559 for (p = head_table;
4496 p < head_table + (sizeof (head_table) / sizeof (head_table[0])); 4560 p < head_table + (sizeof (head_table) / sizeof (head_table[0]));
4690 Vpre_command_hook = Qnil; 4754 Vpre_command_hook = Qnil;
4691 4755
4692 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook, 4756 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook,
4693 "Normal hook run before each command is executed."); 4757 "Normal hook run before each command is executed.");
4694 Vpost_command_hook = Qnil; 4758 Vpost_command_hook = Qnil;
4759
4760 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag,
4761 "t means menu bar, specified Lucid style, needs to be recomputed.");
4762 Vlucid_menu_bar_dirty_flag = Qnil;
4695 } 4763 }
4696 4764
4697 keys_of_keyboard () 4765 keys_of_keyboard ()
4698 { 4766 {
4699 initial_define_key (global_map, Ctl ('Z'), "suspend-emacs"); 4767 initial_define_key (global_map, Ctl ('Z'), "suspend-emacs");