diff options
| author | Po Lu | 2022-03-02 19:00:21 +0800 |
|---|---|---|
| committer | Po Lu | 2022-03-02 19:02:14 +0800 |
| commit | 68e293c81d8ef687500969461067dc774353968f (patch) | |
| tree | f44b99fa8f4da204e4f590040b5049a0aa947505 /src | |
| parent | 6d78321ce824ede11ab04d976d46487bcd191cab (diff) | |
| download | emacs-68e293c81d8ef687500969461067dc774353968f.tar.gz emacs-68e293c81d8ef687500969461067dc774353968f.zip | |
Fix reporting of imaginary key prefixes on toolkit tool and menu bars
* src/keyboard.c (make_lispy_position): Set imaginary prefix if
the terminal says what widget the position is on top of.
* src/termhooks.h (struct terminal): New field
`toolkit_position_hook'.
* src/xterm.c (x_toolkit_position): New function.
(x_create_terminal): Register hook.
Diffstat (limited to 'src')
| -rw-r--r-- | src/keyboard.c | 16 | ||||
| -rw-r--r-- | src/termhooks.h | 7 | ||||
| -rw-r--r-- | src/xterm.c | 38 |
3 files changed, 61 insertions, 0 deletions
diff --git a/src/keyboard.c b/src/keyboard.c index da8c6c54d85..218f9a86c86 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -5247,6 +5247,8 @@ make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y, | |||
| 5247 | Lisp_Object window_or_frame = f | 5247 | Lisp_Object window_or_frame = f |
| 5248 | ? window_from_coordinates (f, mx, my, &part, true, true) | 5248 | ? window_from_coordinates (f, mx, my, &part, true, true) |
| 5249 | : Qnil; | 5249 | : Qnil; |
| 5250 | bool tool_bar_p = false; | ||
| 5251 | bool menu_bar_p = false; | ||
| 5250 | 5252 | ||
| 5251 | /* Report mouse events on the tab bar and (on GUI frames) on the | 5253 | /* Report mouse events on the tab bar and (on GUI frames) on the |
| 5252 | tool bar. */ | 5254 | tool bar. */ |
| @@ -5280,6 +5282,20 @@ make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y, | |||
| 5280 | coordinates. FIXME! */ | 5282 | coordinates. FIXME! */ |
| 5281 | window_or_frame = Qnil; | 5283 | window_or_frame = Qnil; |
| 5282 | } | 5284 | } |
| 5285 | |||
| 5286 | if (FRAME_TERMINAL (f)->toolkit_position_hook) | ||
| 5287 | { | ||
| 5288 | FRAME_TERMINAL (f)->toolkit_position_hook (f, mx, my, &menu_bar_p, | ||
| 5289 | &tool_bar_p); | ||
| 5290 | |||
| 5291 | if (NILP (track_mouse) || EQ (track_mouse, Qt)) | ||
| 5292 | { | ||
| 5293 | if (menu_bar_p) | ||
| 5294 | posn = Qmenu_bar; | ||
| 5295 | else if (tool_bar_p) | ||
| 5296 | posn = Qtool_bar; | ||
| 5297 | } | ||
| 5298 | } | ||
| 5283 | #endif | 5299 | #endif |
| 5284 | if (f | 5300 | if (f |
| 5285 | && !FRAME_WINDOW_P (f) | 5301 | && !FRAME_WINDOW_P (f) |
diff --git a/src/termhooks.h b/src/termhooks.h index b7696fed4f8..8fb4837ee57 100644 --- a/src/termhooks.h +++ b/src/termhooks.h | |||
| @@ -831,6 +831,13 @@ struct terminal | |||
| 831 | frames on the terminal when it calls this hook, so infinite | 831 | frames on the terminal when it calls this hook, so infinite |
| 832 | recursion is prevented. */ | 832 | recursion is prevented. */ |
| 833 | void (*delete_terminal_hook) (struct terminal *); | 833 | void (*delete_terminal_hook) (struct terminal *); |
| 834 | |||
| 835 | /* Called to determine whether a position is on the toolkit tool bar | ||
| 836 | or menu bar. May be NULL. It should accept five arguments | ||
| 837 | FRAME, X, Y, MENU_BAR_P, TOOL_BAR_P, and store true into | ||
| 838 | `menu_bar_p' if X and Y are in FRAME's toolkit menu bar, and true | ||
| 839 | into `tool_bar_p` if X and Y are in FRAME's toolkit tool bar. */ | ||
| 840 | void (*toolkit_position_hook) (struct frame *, int, int, bool *, bool *); | ||
| 834 | } GCALIGNED_STRUCT; | 841 | } GCALIGNED_STRUCT; |
| 835 | 842 | ||
| 836 | INLINE bool | 843 | INLINE bool |
diff --git a/src/xterm.c b/src/xterm.c index 3f693004172..9960f4930d2 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -854,6 +854,41 @@ record_event (char *locus, int type) | |||
| 854 | 854 | ||
| 855 | #endif | 855 | #endif |
| 856 | 856 | ||
| 857 | #if defined USE_X_TOOLKIT || USE_GTK | ||
| 858 | static void | ||
| 859 | x_toolkit_position (struct frame *f, int x, int y, | ||
| 860 | bool *menu_bar_p, bool *tool_bar_p) | ||
| 861 | { | ||
| 862 | #ifdef USE_GTK | ||
| 863 | GdkRectangle test_rect; | ||
| 864 | int scale; | ||
| 865 | |||
| 866 | y += (FRAME_MENUBAR_HEIGHT (f) | ||
| 867 | + FRAME_TOOLBAR_TOP_HEIGHT (f)); | ||
| 868 | x += FRAME_TOOLBAR_LEFT_WIDTH (f); | ||
| 869 | |||
| 870 | if (FRAME_EXTERNAL_MENU_BAR (f)) | ||
| 871 | *menu_bar_p = (x >= 0 && x < FRAME_PIXEL_WIDTH (f) | ||
| 872 | && y >= 0 && y < FRAME_MENUBAR_HEIGHT (f)); | ||
| 873 | |||
| 874 | if (FRAME_X_OUTPUT (f)->toolbar_widget) | ||
| 875 | { | ||
| 876 | scale = xg_get_scale (f); | ||
| 877 | test_rect.x = x / scale; | ||
| 878 | test_rect.y = y / scale; | ||
| 879 | test_rect.width = 1; | ||
| 880 | test_rect.height = 1; | ||
| 881 | |||
| 882 | *tool_bar_p = gtk_widget_intersect (FRAME_X_OUTPUT (f)->toolbar_widget, | ||
| 883 | &test_rect, NULL); | ||
| 884 | } | ||
| 885 | #else | ||
| 886 | *menu_bar_p = (x > 0 && x < FRAME_PIXEL_WIDTH (f) | ||
| 887 | && (y < 0 && y >= -FRAME_MENUBAR_HEIGHT (f))); | ||
| 888 | #endif | ||
| 889 | } | ||
| 890 | #endif | ||
| 891 | |||
| 857 | static void | 892 | static void |
| 858 | x_update_opaque_region (struct frame *f, XEvent *configure) | 893 | x_update_opaque_region (struct frame *f, XEvent *configure) |
| 859 | { | 894 | { |
| @@ -17820,6 +17855,9 @@ x_create_terminal (struct x_display_info *dpyinfo) | |||
| 17820 | terminal->free_pixmap = x_free_pixmap; | 17855 | terminal->free_pixmap = x_free_pixmap; |
| 17821 | terminal->delete_frame_hook = x_destroy_window; | 17856 | terminal->delete_frame_hook = x_destroy_window; |
| 17822 | terminal->delete_terminal_hook = x_delete_terminal; | 17857 | terminal->delete_terminal_hook = x_delete_terminal; |
| 17858 | #if defined USE_X_TOOLKIT || defined USE_GTK | ||
| 17859 | terminal->toolkit_position_hook = x_toolkit_position; | ||
| 17860 | #endif | ||
| 17823 | /* Other hooks are NULL by default. */ | 17861 | /* Other hooks are NULL by default. */ |
| 17824 | 17862 | ||
| 17825 | return terminal; | 17863 | return terminal; |