emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/pgtk 639d94f 1/2: Entrust Gtk with handling tooltips


From: Yuuki Harano
Subject: feature/pgtk 639d94f 1/2: Entrust Gtk with handling tooltips
Date: Sat, 8 May 2021 11:11:50 -0400 (EDT)

branch: feature/pgtk
commit 639d94fe14ce4d6036296c4b548ecbe4910ad7fa
Author: Yuuki Harano <masm+github@masm11.me>
Commit: Yuuki Harano <masm+github@masm11.me>

    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.
---
 src/gtkutil.c | 33 +++++++++++++++++++++++++++++++++
 src/gtkutil.h |  4 ++++
 src/pgtkfns.c | 11 ++++-------
 3 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/src/gtkutil.c b/src/gtkutil.c
index 7760c8e..ee8b925 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 a421cee..4afdfe7 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 65c81f7..73681c6 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;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]