diff options
| author | Po Lu | 2022-07-08 07:34:45 +0000 |
|---|---|---|
| committer | Po Lu | 2022-07-08 07:34:45 +0000 |
| commit | 0fc9808dedc24e843bfbbfe3d3a3930167873fa7 (patch) | |
| tree | f38de3513e1ddd54d95146962d92ec8d2edbdf8e /src | |
| parent | bc015a7b44ab0803cfc35f69987eb28d9f4597e1 (diff) | |
| download | emacs-0fc9808dedc24e843bfbbfe3d3a3930167873fa7.tar.gz emacs-0fc9808dedc24e843bfbbfe3d3a3930167873fa7.zip | |
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')
| -rw-r--r-- | src/haiku_support.cc | 89 | ||||
| -rw-r--r-- | src/haiku_support.h | 3 | ||||
| -rw-r--r-- | src/haikufns.c | 4 |
3 files changed, 63 insertions, 33 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: | |||
| 1517 | BLocker cr_surface_lock; | 1517 | BLocker cr_surface_lock; |
| 1518 | #endif | 1518 | #endif |
| 1519 | 1519 | ||
| 1520 | BPoint tooltip_position; | ||
| 1521 | BMessage *wait_for_release_message; | 1520 | BMessage *wait_for_release_message; |
| 1522 | 1521 | ||
| 1523 | EmacsView () : BView (BRect (0, 0, 0, 0), "Emacs", | 1522 | EmacsView () : BView (BRect (0, 0, 0, 0), "Emacs", |
| @@ -1797,11 +1796,8 @@ public: | |||
| 1797 | struct haiku_mouse_motion_event rq; | 1796 | struct haiku_mouse_motion_event rq; |
| 1798 | int32 windowid; | 1797 | int32 windowid; |
| 1799 | EmacsWindow *window; | 1798 | EmacsWindow *window; |
| 1800 | BToolTip *tooltip; | ||
| 1801 | BPoint target_tooltip_position; | ||
| 1802 | 1799 | ||
| 1803 | window = (EmacsWindow *) Window (); | 1800 | window = (EmacsWindow *) Window (); |
| 1804 | tooltip = ToolTip (); | ||
| 1805 | 1801 | ||
| 1806 | if (transit == B_EXITED_VIEW) | 1802 | if (transit == B_EXITED_VIEW) |
| 1807 | rq.just_exited_p = true; | 1803 | rq.just_exited_p = true; |
| @@ -1821,16 +1817,6 @@ public: | |||
| 1821 | else | 1817 | else |
| 1822 | rq.dnd_message = false; | 1818 | rq.dnd_message = false; |
| 1823 | 1819 | ||
| 1824 | if (tooltip) | ||
| 1825 | { | ||
| 1826 | target_tooltip_position | ||
| 1827 | = BPoint (-(point.x - tooltip_position.x), | ||
| 1828 | -(point.y - tooltip_position.y)); | ||
| 1829 | tooltip->SetMouseRelativeLocation (target_tooltip_position); | ||
| 1830 | tooltip->SetSticky (true); | ||
| 1831 | ShowToolTip (tooltip); | ||
| 1832 | } | ||
| 1833 | |||
| 1834 | if (!grab_view_locker.Lock ()) | 1820 | if (!grab_view_locker.Lock ()) |
| 1835 | gui_abort ("Couldn't lock grab view locker"); | 1821 | gui_abort ("Couldn't lock grab view locker"); |
| 1836 | 1822 | ||
| @@ -3282,6 +3268,41 @@ public: | |||
| 3282 | } | 3268 | } |
| 3283 | }; | 3269 | }; |
| 3284 | 3270 | ||
| 3271 | /* A view that is added as a child of a tooltip's text view, and | ||
| 3272 | prevents motion events from reaching it (thereby moving the | ||
| 3273 | tooltip). */ | ||
| 3274 | class EmacsMotionSuppressionView : public BView | ||
| 3275 | { | ||
| 3276 | void | ||
| 3277 | AttachedToWindow (void) | ||
| 3278 | { | ||
| 3279 | BView *text_view, *tooltip_view; | ||
| 3280 | |||
| 3281 | /* We know that this view is a child of the text view, whose | ||
| 3282 | parent is the tooltip view, and that the tooltip view has | ||
| 3283 | already set its mouse event mask. */ | ||
| 3284 | |||
| 3285 | text_view = Parent (); | ||
| 3286 | |||
| 3287 | if (!text_view) | ||
| 3288 | return; | ||
| 3289 | |||
| 3290 | tooltip_view = text_view->Parent (); | ||
| 3291 | |||
| 3292 | if (!tooltip_view) | ||
| 3293 | return; | ||
| 3294 | |||
| 3295 | tooltip_view->SetEventMask (B_KEYBOARD_EVENTS, 0); | ||
| 3296 | } | ||
| 3297 | |||
| 3298 | public: | ||
| 3299 | EmacsMotionSuppressionView (void) : BView (BRect (-1, -1, 1, 1), | ||
| 3300 | NULL, 0, 0) | ||
| 3301 | { | ||
| 3302 | return; | ||
| 3303 | } | ||
| 3304 | }; | ||
| 3305 | |||
| 3285 | static int32 | 3306 | static int32 |
| 3286 | start_running_application (void *data) | 3307 | start_running_application (void *data) |
| 3287 | { | 3308 | { |
| @@ -4320,36 +4341,46 @@ BView_set_tooltip (void *view, const char *tooltip) | |||
| 4320 | 4341 | ||
| 4321 | /* Set VIEW's tooltip to a sticky tooltip at X by Y. */ | 4342 | /* Set VIEW's tooltip to a sticky tooltip at X by Y. */ |
| 4322 | void | 4343 | void |
| 4323 | BView_set_and_show_sticky_tooltip (void *view, const char *tooltip_text, | 4344 | be_show_sticky_tooltip (void *view, const char *tooltip_text, |
| 4324 | int x, int y) | 4345 | int x, int y) |
| 4325 | { | 4346 | { |
| 4326 | BToolTip *tooltip; | 4347 | BToolTip *tooltip; |
| 4327 | BView *vw; | 4348 | BView *vw, *tooltip_view; |
| 4328 | EmacsView *ev; | 4349 | BPoint point; |
| 4329 | BPoint pt; | ||
| 4330 | 4350 | ||
| 4331 | vw = (BView *) view; | 4351 | vw = (BView *) view; |
| 4332 | 4352 | ||
| 4333 | if (!vw->LockLooper ()) | 4353 | if (!vw->LockLooper ()) |
| 4334 | gui_abort ("Failed to lock view while showing sticky tooltip"); | 4354 | gui_abort ("Failed to lock view while showing sticky tooltip"); |
| 4335 | 4355 | ||
| 4356 | vw->SetToolTip ((const char *) NULL); | ||
| 4357 | |||
| 4358 | /* If the tooltip text is empty, then a tooltip object won't be | ||
| 4359 | created by SetToolTip. */ | ||
| 4360 | if (tooltip_text[0] == '\0') | ||
| 4361 | tooltip_text = " "; | ||
| 4362 | |||
| 4336 | vw->SetToolTip (tooltip_text); | 4363 | vw->SetToolTip (tooltip_text); |
| 4364 | |||
| 4337 | tooltip = vw->ToolTip (); | 4365 | tooltip = vw->ToolTip (); |
| 4338 | 4366 | ||
| 4339 | ev = dynamic_cast<EmacsView *> (vw); | 4367 | vw->GetMouse (&point, NULL, 1); |
| 4368 | point.x -= x; | ||
| 4369 | point.y -= y; | ||
| 4340 | 4370 | ||
| 4341 | if (ev) | 4371 | point.x = -point.x; |
| 4342 | ev->tooltip_position = BPoint (x, y); | 4372 | point.y = -point.y; |
| 4343 | 4373 | ||
| 4344 | vw->GetMouse (&pt, NULL, 1); | 4374 | /* We don't have to make the tooltip sticky since not receiving |
| 4345 | pt.x -= x; | 4375 | mouse movement is enough to prevent it from being hidden. */ |
| 4346 | pt.y -= y; | 4376 | tooltip->SetMouseRelativeLocation (point); |
| 4347 | 4377 | ||
| 4348 | pt.x = -pt.x; | 4378 | /* Prevent the tooltip from moving in response to mouse |
| 4349 | pt.y = -pt.y; | 4379 | movement. */ |
| 4380 | tooltip_view = tooltip->View (); | ||
| 4350 | 4381 | ||
| 4351 | tooltip->SetMouseRelativeLocation (pt); | 4382 | if (tooltip_view) |
| 4352 | tooltip->SetSticky (true); | 4383 | tooltip_view->AddChild (new EmacsMotionSuppressionView); |
| 4353 | 4384 | ||
| 4354 | vw->ShowToolTip (tooltip); | 4385 | vw->ShowToolTip (tooltip); |
| 4355 | vw->UnlockLooper (); | 4386 | vw->UnlockLooper (); |
diff --git a/src/haiku_support.h b/src/haiku_support.h index d73f15560be..5f44494a8d3 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h | |||
| @@ -648,8 +648,7 @@ extern int32 BAlert_go (void *, void (*) (void), void (*) (void), | |||
| 648 | extern void BButton_set_enabled (void *, int); | 648 | extern void BButton_set_enabled (void *, int); |
| 649 | extern void BView_set_tooltip (void *, const char *); | 649 | extern void BView_set_tooltip (void *, const char *); |
| 650 | extern void BView_show_tooltip (void *); | 650 | extern void BView_show_tooltip (void *); |
| 651 | extern void BView_set_and_show_sticky_tooltip (void *, const char *, | 651 | extern void be_show_sticky_tooltip (void *, const char *, int, int); |
| 652 | int, int); | ||
| 653 | 652 | ||
| 654 | extern void BAlert_delete (void *); | 653 | extern void BAlert_delete (void *); |
| 655 | 654 | ||
diff --git a/src/haikufns.c b/src/haikufns.c index 878917eeef7..e0a65b499f4 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, | |||
| 2392 | reliable way to get it. */ | 2392 | reliable way to get it. */ |
| 2393 | compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); | 2393 | compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); |
| 2394 | BView_convert_from_screen (FRAME_HAIKU_VIEW (f), &root_x, &root_y); | 2394 | BView_convert_from_screen (FRAME_HAIKU_VIEW (f), &root_x, &root_y); |
| 2395 | BView_set_and_show_sticky_tooltip (FRAME_HAIKU_VIEW (f), SSDATA (string), | 2395 | be_show_sticky_tooltip (FRAME_HAIKU_VIEW (f), SSDATA (string), |
| 2396 | root_x, root_y); | 2396 | root_x, root_y); |
| 2397 | unblock_input (); | 2397 | unblock_input (); |
| 2398 | goto start_timer; | 2398 | goto start_timer; |
| 2399 | } | 2399 | } |