summaryrefslogtreecommitdiff
path: root/src/haiku_support.cc
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2022-07-08 07:34:45 +0000
committerPo Lu <luangruo@yahoo.com>2022-07-08 07:34:45 +0000
commit0fc9808dedc24e843bfbbfe3d3a3930167873fa7 (patch)
treef38de3513e1ddd54d95146962d92ec8d2edbdf8e /src/haiku_support.cc
parentbc015a7b44ab0803cfc35f69987eb28d9f4597e1 (diff)
downloademacs-0fc9808dedc24e843bfbbfe3d3a3930167873fa7.tar.gz
Improve behavior of sticky tooltips on Haiku
* 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.
Diffstat (limited to 'src/haiku_support.cc')
-rw-r--r--src/haiku_support.cc89
1 files changed, 60 insertions, 29 deletions
diff --git a/src/haiku_support.cc b/src/haiku_support.cc
index 332321e2db9..a3d3b7a17d3 100644
--- a/src/haiku_support.cc
+++ b/src/haiku_support.cc
@@ -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 ();