]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve behavior of sticky tooltips on Haiku
authorPo Lu <luangruo@yahoo.com>
Fri, 8 Jul 2022 07:34:45 +0000 (07:34 +0000)
committerPo Lu <luangruo@yahoo.com>
Fri, 8 Jul 2022 07:34:45 +0000 (07:34 +0000)
* src/haiku_support.cc (class EmacsView, MouseMoved): Remove
`tooltip_position'.
(class EmacsMotionSuppressionView): New class.
(BView_set_and_show_sticky_tooltip): Rename to
`be_show_sticky_tooltip'.  Add motion suppression view.

* src/haiku_support.h: Update prototypes.
* src/haikufns.c (Fx_show_tip): Update for renamed function.

src/haiku_support.cc
src/haiku_support.h
src/haikufns.c

index 332321e2db9714fa5ccc75531968e1b6291928e1..a3d3b7a17d383630d2fef84fd132e5683bf32267 100644 (file)
@@ -1517,7 +1517,6 @@ public:
   BLocker cr_surface_lock;
 #endif
 
-  BPoint tooltip_position;
   BMessage *wait_for_release_message;
 
   EmacsView () : BView (BRect (0, 0, 0, 0), "Emacs",
@@ -1797,11 +1796,8 @@ public:
     struct haiku_mouse_motion_event rq;
     int32 windowid;
     EmacsWindow *window;
-    BToolTip *tooltip;
-    BPoint target_tooltip_position;
 
     window = (EmacsWindow *) Window ();
-    tooltip = ToolTip ();
 
     if (transit == B_EXITED_VIEW)
       rq.just_exited_p = true;
@@ -1821,16 +1817,6 @@ public:
     else
       rq.dnd_message = false;
 
-    if (tooltip)
-      {
-       target_tooltip_position
-         = BPoint (-(point.x - tooltip_position.x),
-                   -(point.y - tooltip_position.y));
-       tooltip->SetMouseRelativeLocation (target_tooltip_position);
-       tooltip->SetSticky (true);
-       ShowToolTip (tooltip);
-      }
-
     if (!grab_view_locker.Lock ())
       gui_abort ("Couldn't lock grab view locker");
 
@@ -3282,6 +3268,41 @@ public:
   }
 };
 
+/* A view that is added as a child of a tooltip's text view, and
+   prevents motion events from reaching it (thereby moving the
+   tooltip).  */
+class EmacsMotionSuppressionView : public BView
+{
+  void
+  AttachedToWindow (void)
+  {
+    BView *text_view, *tooltip_view;
+
+    /* We know that this view is a child of the text view, whose
+       parent is the tooltip view, and that the tooltip view has
+       already set its mouse event mask.  */
+
+    text_view = Parent ();
+
+    if (!text_view)
+      return;
+
+    tooltip_view = text_view->Parent ();
+
+    if (!tooltip_view)
+      return;
+
+    tooltip_view->SetEventMask (B_KEYBOARD_EVENTS, 0);
+  }
+
+public:
+  EmacsMotionSuppressionView (void) : BView (BRect (-1, -1, 1, 1),
+                                            NULL, 0, 0)
+  {
+    return;
+  }
+};
+
 static int32
 start_running_application (void *data)
 {
@@ -4320,36 +4341,46 @@ BView_set_tooltip (void *view, const char *tooltip)
 
 /* Set VIEW's tooltip to a sticky tooltip at X by Y.  */
 void
-BView_set_and_show_sticky_tooltip (void *view, const char *tooltip_text,
-                                  int x, int y)
+be_show_sticky_tooltip (void *view, const char *tooltip_text,
+                       int x, int y)
 {
   BToolTip *tooltip;
-  BView *vw;
-  EmacsView *ev;
-  BPoint pt;
+  BView *vw, *tooltip_view;
+  BPoint point;
 
   vw = (BView *) view;
 
   if (!vw->LockLooper ())
     gui_abort ("Failed to lock view while showing sticky tooltip");
 
+  vw->SetToolTip ((const char *) NULL);
+
+  /* If the tooltip text is empty, then a tooltip object won't be
+     created by SetToolTip.  */
+  if (tooltip_text[0] == '\0')
+    tooltip_text = " ";
+
   vw->SetToolTip (tooltip_text);
+
   tooltip = vw->ToolTip ();
 
-  ev = dynamic_cast<EmacsView *> (vw);
+  vw->GetMouse (&point, NULL, 1);
+  point.x -= x;
+  point.y -= y;
 
-  if (ev)
-    ev->tooltip_position = BPoint (x, y);
+  point.x = -point.x;
+  point.y = -point.y;
 
-  vw->GetMouse (&pt, NULL, 1);
-  pt.x -= x;
-  pt.y -= y;
+  /* We don't have to make the tooltip sticky since not receiving
+     mouse movement is enough to prevent it from being hidden.  */
+  tooltip->SetMouseRelativeLocation (point);
 
-  pt.x = -pt.x;
-  pt.y = -pt.y;
+  /* Prevent the tooltip from moving in response to mouse
+     movement.  */
+  tooltip_view = tooltip->View ();
 
-  tooltip->SetMouseRelativeLocation (pt);
-  tooltip->SetSticky (true);
+  if (tooltip_view)
+    tooltip_view->AddChild (new EmacsMotionSuppressionView);
 
   vw->ShowToolTip (tooltip);
   vw->UnlockLooper ();
index d73f15560bebe258225385853295640a03738397..5f44494a8d3f03fc6f8a76a470781d88f472d050 100644 (file)
@@ -648,8 +648,7 @@ extern int32 BAlert_go (void *, void (*) (void), void (*) (void),
 extern void BButton_set_enabled (void *, int);
 extern void BView_set_tooltip (void *, const char *);
 extern void BView_show_tooltip (void *);
-extern void BView_set_and_show_sticky_tooltip (void *, const char *,
-                                              int, int);
+extern void be_show_sticky_tooltip (void *, const char *, int, int);
 
 extern void BAlert_delete (void *);
 
index 878917eeef7c06852c62d7e169ae8c8150e9f5cc..e0a65b499f455ca7fc733acaeedd6022a2b9078b 100644 (file)
@@ -2392,8 +2392,8 @@ DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
                      reliable way to get it.  */
       compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
       BView_convert_from_screen (FRAME_HAIKU_VIEW (f), &root_x, &root_y);
-      BView_set_and_show_sticky_tooltip (FRAME_HAIKU_VIEW (f), SSDATA (string),
-                                        root_x, root_y);
+      be_show_sticky_tooltip (FRAME_HAIKU_VIEW (f), SSDATA (string),
+                             root_x, root_y);
       unblock_input ();
       goto start_timer;
     }