Skip to content

Commit 66efeb3

Browse files
committed
better solution for enabling link mouseover cursors on macOS
The previous solution (using SetCapture) was eating keyboard input in all SWELL windows when using REAPER-provided up-to-date SWELL.
1 parent 2048d8d commit 66efeb3

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

src/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ add_library(reapack OBJECT
6565
config.cpp
6666
control.cpp
6767
database.cpp
68-
dialog.cpp
68+
dialog.cpp $<IF:$<BOOL:${APPLE}>,dialog.mm,>
6969
download.cpp
7070
event.cpp
7171
filedialog.cpp

src/dialog.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ WDL_DLGRET Dialog::Proc(HWND handle, UINT msg, WPARAM wParam, LPARAM lParam)
7272
if(wParam != SIZE_MINIMIZED)
7373
dlg->onResize();
7474
break;
75+
#ifdef __APPLE__
76+
// This stops SWELL_SendMouseMessageImpl from continuously resetting the
77+
// mouse cursor allowing NSTextViews to change it on mouse hover.
78+
case WM_SETCURSOR:
79+
return dlg->isTextEditUnderMouse();
80+
#endif
7581
case WM_DESTROY:
7682
dlg->onClose();
7783
break;

src/dialog.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ class Dialog {
143143
static WDL_DLGRET Proc(HWND, UINT, WPARAM, LPARAM);
144144
static int HandleKey(MSG *, accelerator_register_t *);
145145

146+
#ifdef __APPLE__
147+
bool isTextEditUnderMouse() const;
148+
#endif
149+
146150
const int m_template;
147151
POINT m_minimumSize;
148152
WDL_WndSizer m_resizer;

src/dialog.mm

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "dialog.hpp"
2+
3+
#include <AppKit/NSTextView.h>
4+
#include <swell/swell.h>
5+
6+
bool Dialog::isTextEditUnderMouse() const
7+
{
8+
POINT p;
9+
GetCursorPos(&p);
10+
const HWND ctrl = WindowFromPoint(p);
11+
12+
return ctrl && [static_cast<id>(ctrl) isKindOfClass:[NSTextView class]];
13+
}

src/richedit-gtk.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ RichEdit::RichEdit(HWND handle)
2929
{
3030
}
3131

32-
RichEdit::~RichEdit()
33-
{
34-
}
32+
RichEdit::~RichEdit() = default;
3533

3634
void RichEdit::onNotify(LPNMHDR, LPARAM)
3735
{

src/richedit-win32.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ RichEdit::RichEdit(HWND handle)
5353
SES_HYPERLINKTOOLTIPS, SES_HYPERLINKTOOLTIPS);
5454
}
5555

56-
RichEdit::~RichEdit()
57-
{
58-
}
56+
RichEdit::~RichEdit() = default;
5957

6058
void RichEdit::onNotify(LPNMHDR info, LPARAM lParam)
6159
{

src/richedit.mm

+4-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
#include "richedit.hpp"
1919

20-
#include <Cocoa/Cocoa.h>
20+
#include <AppKit/NSAttributedString.h>
21+
#include <AppKit/NSColor.h>
22+
#include <AppKit/NSTextView.h>
2123

2224
void RichEdit::Init()
2325
{
@@ -26,16 +28,9 @@
2628
RichEdit::RichEdit(HWND handle)
2729
: Control(handle)
2830
{
29-
// hack: restore NSTextView's default mouse cursors (eg. hover links)
30-
// this is an incomplete fix for the hyperlink's shy tooltips
31-
SetCapture(handle);
3231
}
3332

34-
RichEdit::~RichEdit()
35-
{
36-
if(GetCapture() == handle())
37-
ReleaseCapture();
38-
}
33+
RichEdit::~RichEdit() = default;
3934

4035
void RichEdit::onNotify(LPNMHDR, LPARAM)
4136
{

0 commit comments

Comments
 (0)