From: Yuuki Harano Date: Tue, 4 May 2021 16:21:02 +0000 (+0900) Subject: Entrust Gtk with handling tooltips X-Git-Tag: emacs-29.0.90~3707 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=639d94fe14ce4d6036296c4b548ecbe4910ad7fa;p=emacs.git Entrust Gtk with handling tooltips Previously, tooltips for menu items are below the menu. To solve it, set tooltip text on menu items in advance, and entrust gtk with handling tooltips. * src/gtkutil.c (xg_show_tooltip): New function for pgtk to set tooltip text on the widget. (xg_hide_tooltip): New function for pgtk to clear tooltip text on the widget. (xg_create_frame_widgets): Don't set initial tooltips text, and don't use qttip_cb. (xg_create_frame_outer_widgets): Ditto. (make_menu_item): Set tooltip text on the menu item. * src/gtkutil.h: New declaration of xg_show_tooltip for pgtk. * src/pgtkfns.c (Fx_show_tip): Calls xg_show_tooltip, and always ok. --- diff --git a/src/gtkutil.c b/src/gtkutil.c index 7760c8ed0a2..ee8b9259206 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -738,6 +738,9 @@ xg_check_special_colors (struct frame *f, /*********************************************************************** Tooltips ***********************************************************************/ + +#ifndef HAVE_PGTK + /* Gtk+ calls this callback when the parent of our tooltip dummy changes. We use that to pop down the tooltip. This happens if Gtk+ for some reason wants to change or hide the tooltip. */ @@ -912,6 +915,27 @@ xg_hide_tooltip (struct frame *f) return FALSE; } +#else + +void +xg_show_tooltip (struct frame *f, + Lisp_Object string) +{ + Lisp_Object encoded_string = ENCODE_UTF_8 (string); + gtk_widget_set_tooltip_text (FRAME_GTK_OUTER_WIDGET (f), SSDATA (encoded_string)); +} + +bool +xg_hide_tooltip (struct frame *f) +{ + if (gtk_widget_get_tooltip_text (FRAME_GTK_OUTER_WIDGET (f)) == NULL) + return FALSE; + gtk_widget_set_tooltip_text (FRAME_GTK_OUTER_WIDGET (f), NULL); + return TRUE; +} + +#endif + /*********************************************************************** General functions for creating widgets, resizing, events, e.t.c. @@ -1563,8 +1587,10 @@ xg_create_frame_widgets (struct frame *f) f->output_data.xp->ttip_widget = 0; f->output_data.xp->ttip_lbl = 0; f->output_data.xp->ttip_window = 0; +#ifndef HAVE_PGTK gtk_widget_set_tooltip_text (wtop, "Dummy text"); g_signal_connect (wtop, "query-tooltip", G_CALLBACK (qttip_cb), f); +#endif { GdkScreen *screen = gtk_widget_get_screen (wtop); @@ -1665,8 +1691,10 @@ xg_create_frame_outer_widgets (struct frame *f) f->output_data.xp->ttip_widget = 0; f->output_data.xp->ttip_lbl = 0; f->output_data.xp->ttip_window = 0; +#ifndef HAVE_PGTK gtk_widget_set_tooltip_text (wtop, "Dummy text"); g_signal_connect (wtop, "query-tooltip", G_CALLBACK (qttip_cb), f); +#endif { GdkScreen *screen = gtk_widget_get_screen (wtop); @@ -3006,6 +3034,11 @@ make_menu_item (const char *utf8_label, if (wtoadd) gtk_container_add (GTK_CONTAINER (w), wtoadd); if (! item->enabled) gtk_widget_set_sensitive (w, FALSE); +#ifdef HAVE_PGTK + if (!NILP (item->help)) + gtk_widget_set_tooltip_text (w, SSDATA (item->help)); +#endif + return w; } diff --git a/src/gtkutil.h b/src/gtkutil.h index a421cee6ca4..4afdfe7405a 100644 --- a/src/gtkutil.h +++ b/src/gtkutil.h @@ -200,7 +200,11 @@ extern bool xg_prepare_tooltip (struct frame *f, Lisp_Object string, int *width, int *height); +#ifndef HAVE_PGTK extern void xg_show_tooltip (struct frame *f, int root_x, int root_y); +#else +extern void xg_show_tooltip (struct frame *f, Lisp_Object string); +#endif extern bool xg_hide_tooltip (struct frame *f); #ifdef USE_CAIRO diff --git a/src/pgtkfns.c b/src/pgtkfns.c index 65c81f7438e..73681c66f7a 100644 --- a/src/pgtkfns.c +++ b/src/pgtkfns.c @@ -3287,13 +3287,10 @@ Text larger than the specified size is clipped. */) Fx_hide_tip (); block_input (); - ok = xg_prepare_tooltip (f, string, &width, &height); - if (ok) - { - compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); - xg_show_tooltip (f, root_x, root_y); - tip_last_frame = frame; - } + + ok = true; + xg_show_tooltip (f, string); + tip_last_frame = frame; unblock_input (); if (ok) goto start_timer;