aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYuuki Harano2021-05-05 01:21:02 +0900
committerYuuki Harano2021-05-08 23:46:49 +0900
commit639d94fe14ce4d6036296c4b548ecbe4910ad7fa (patch)
tree20ae784f0c0157581ff59ca7b326e92728930d30 /src
parentff3d7190bbaebf196c0ac7f84d4869fa9362276f (diff)
downloademacs-639d94fe14ce4d6036296c4b548ecbe4910ad7fa.tar.gz
emacs-639d94fe14ce4d6036296c4b548ecbe4910ad7fa.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/gtkutil.c33
-rw-r--r--src/gtkutil.h4
-rw-r--r--src/pgtkfns.c11
3 files changed, 41 insertions, 7 deletions
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,
738/*********************************************************************** 738/***********************************************************************
739 Tooltips 739 Tooltips
740 ***********************************************************************/ 740 ***********************************************************************/
741
742#ifndef HAVE_PGTK
743
741/* Gtk+ calls this callback when the parent of our tooltip dummy changes. 744/* Gtk+ calls this callback when the parent of our tooltip dummy changes.
742 We use that to pop down the tooltip. This happens if Gtk+ for some 745 We use that to pop down the tooltip. This happens if Gtk+ for some
743 reason wants to change or hide the tooltip. */ 746 reason wants to change or hide the tooltip. */
@@ -912,6 +915,27 @@ xg_hide_tooltip (struct frame *f)
912 return FALSE; 915 return FALSE;
913} 916}
914 917
918#else
919
920void
921xg_show_tooltip (struct frame *f,
922 Lisp_Object string)
923{
924 Lisp_Object encoded_string = ENCODE_UTF_8 (string);
925 gtk_widget_set_tooltip_text (FRAME_GTK_OUTER_WIDGET (f), SSDATA (encoded_string));
926}
927
928bool
929xg_hide_tooltip (struct frame *f)
930{
931 if (gtk_widget_get_tooltip_text (FRAME_GTK_OUTER_WIDGET (f)) == NULL)
932 return FALSE;
933 gtk_widget_set_tooltip_text (FRAME_GTK_OUTER_WIDGET (f), NULL);
934 return TRUE;
935}
936
937#endif
938
915 939
916/*********************************************************************** 940/***********************************************************************
917 General functions for creating widgets, resizing, events, e.t.c. 941 General functions for creating widgets, resizing, events, e.t.c.
@@ -1563,8 +1587,10 @@ xg_create_frame_widgets (struct frame *f)
1563 f->output_data.xp->ttip_widget = 0; 1587 f->output_data.xp->ttip_widget = 0;
1564 f->output_data.xp->ttip_lbl = 0; 1588 f->output_data.xp->ttip_lbl = 0;
1565 f->output_data.xp->ttip_window = 0; 1589 f->output_data.xp->ttip_window = 0;
1590#ifndef HAVE_PGTK
1566 gtk_widget_set_tooltip_text (wtop, "Dummy text"); 1591 gtk_widget_set_tooltip_text (wtop, "Dummy text");
1567 g_signal_connect (wtop, "query-tooltip", G_CALLBACK (qttip_cb), f); 1592 g_signal_connect (wtop, "query-tooltip", G_CALLBACK (qttip_cb), f);
1593#endif
1568 1594
1569 { 1595 {
1570 GdkScreen *screen = gtk_widget_get_screen (wtop); 1596 GdkScreen *screen = gtk_widget_get_screen (wtop);
@@ -1665,8 +1691,10 @@ xg_create_frame_outer_widgets (struct frame *f)
1665 f->output_data.xp->ttip_widget = 0; 1691 f->output_data.xp->ttip_widget = 0;
1666 f->output_data.xp->ttip_lbl = 0; 1692 f->output_data.xp->ttip_lbl = 0;
1667 f->output_data.xp->ttip_window = 0; 1693 f->output_data.xp->ttip_window = 0;
1694#ifndef HAVE_PGTK
1668 gtk_widget_set_tooltip_text (wtop, "Dummy text"); 1695 gtk_widget_set_tooltip_text (wtop, "Dummy text");
1669 g_signal_connect (wtop, "query-tooltip", G_CALLBACK (qttip_cb), f); 1696 g_signal_connect (wtop, "query-tooltip", G_CALLBACK (qttip_cb), f);
1697#endif
1670 1698
1671 { 1699 {
1672 GdkScreen *screen = gtk_widget_get_screen (wtop); 1700 GdkScreen *screen = gtk_widget_get_screen (wtop);
@@ -3006,6 +3034,11 @@ make_menu_item (const char *utf8_label,
3006 if (wtoadd) gtk_container_add (GTK_CONTAINER (w), wtoadd); 3034 if (wtoadd) gtk_container_add (GTK_CONTAINER (w), wtoadd);
3007 if (! item->enabled) gtk_widget_set_sensitive (w, FALSE); 3035 if (! item->enabled) gtk_widget_set_sensitive (w, FALSE);
3008 3036
3037#ifdef HAVE_PGTK
3038 if (!NILP (item->help))
3039 gtk_widget_set_tooltip_text (w, SSDATA (item->help));
3040#endif
3041
3009 return w; 3042 return w;
3010} 3043}
3011 3044
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,
200 Lisp_Object string, 200 Lisp_Object string,
201 int *width, 201 int *width,
202 int *height); 202 int *height);
203#ifndef HAVE_PGTK
203extern void xg_show_tooltip (struct frame *f, int root_x, int root_y); 204extern void xg_show_tooltip (struct frame *f, int root_x, int root_y);
205#else
206extern void xg_show_tooltip (struct frame *f, Lisp_Object string);
207#endif
204extern bool xg_hide_tooltip (struct frame *f); 208extern bool xg_hide_tooltip (struct frame *f);
205 209
206#ifdef USE_CAIRO 210#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. */)
3287 Fx_hide_tip (); 3287 Fx_hide_tip ();
3288 3288
3289 block_input (); 3289 block_input ();
3290 ok = xg_prepare_tooltip (f, string, &width, &height); 3290
3291 if (ok) 3291 ok = true;
3292 { 3292 xg_show_tooltip (f, string);
3293 compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); 3293 tip_last_frame = frame;
3294 xg_show_tooltip (f, root_x, root_y);
3295 tip_last_frame = frame;
3296 }
3297 3294
3298 unblock_input (); 3295 unblock_input ();
3299 if (ok) goto start_timer; 3296 if (ok) goto start_timer;