[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 0fc9808ded: Improve behavior of sticky tooltips on Haiku
From: |
Po Lu |
Subject: |
master 0fc9808ded: Improve behavior of sticky tooltips on Haiku |
Date: |
Fri, 8 Jul 2022 03:35:03 -0400 (EDT) |
branch: master
commit 0fc9808dedc24e843bfbbfe3d3a3930167873fa7
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
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.
---
src/haiku_support.cc | 89 +++++++++++++++++++++++++++++++++++-----------------
src/haiku_support.h | 3 +-
src/haikufns.c | 4 +--
3 files changed, 63 insertions(+), 33 deletions(-)
diff --git a/src/haiku_support.cc b/src/haiku_support.cc
index 332321e2db..a3d3b7a17d 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 ();
diff --git a/src/haiku_support.h b/src/haiku_support.h
index d73f15560b..5f44494a8d 100644
--- a/src/haiku_support.h
+++ b/src/haiku_support.h
@@ -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 *);
diff --git a/src/haikufns.c b/src/haikufns.c
index 878917eeef..e0a65b499f 100644
--- a/src/haikufns.c
+++ b/src/haikufns.c
@@ -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;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 0fc9808ded: Improve behavior of sticky tooltips on Haiku,
Po Lu <=