Getting void mouseMagnify() to work

On my Windows 10 machine, I’m running the following line of code:

 void mouseMagnify(const MouseEvent& mouse, float scale) override { DBG(scale); }

But it doesn’t respond at all when I test it.

I’ve tried it in a variety of Components and projects. Is there something I’m missing?

Can you override any other mouse functions on your component?

What happens when you do:

// Click anywhere in your component to test
void mouseDown (const MouseEvent& event) override { DBG("TEST"); } 

mouseMagnify is called when a pinch-to-zoom mouse-gesture is used. How are you emitting that “signal”?

Other mouse functions such as mouseDown are working as I would expect them to.

To test mouseMagnify I’m holding the mouse over the given component and then pinch-zooming on my trackpad, and nothing happens. I’ve also tested to make sure that the component has keyboard focus, and it does.

Obviously the message is being lost somewhere upstream, but I don’t know where to look.

I’m getting the same result as you. I can pinch zoom in the Windows10 Photos app with my track pad, but nothing happens in the JUCE component.

My Laptop is a 2018 Dell Vostro.

I’ve just run into the same problem on macOS 10.13.6

All other mouse methods are being fired, but mouseMagnify never gets called when performing a pinch gesture over the component I have overridden it for.

Can reproduce by starting a new Plugin from Projucer, adding

    void mouseMagnify(const juce::MouseEvent &event, float scaleFactor) override
    {
        DBG("mouseMagnify called");
    }

to PluginEditor.h and running the standalone: no DBG messages are output.

Is there something I missed somewhere?

You’ll have to dig into it unfortunately. The flow that leads to that function goes through the generic handleMagnifyGesture function, and prior to that, on macOS it goes through magnify which is supposed to be triggered by magnifyWithEvent.

1 Like

Well, this is embarrassing: I put a breakpoint in handleMagnifyGesture and followed it through to my component’s mouseMagnify method.

Now everything is working as expected!

Christ knows what happened before, perhaps I need more coffee! :wink:

I haven’t had such luck as @jrlanglois.

I put a breakpoint at line 97 of juce_ComponentPeer.cpp:

void ComponentPeer::handleMagnifyGesture (MouseInputSource::InputSourceType type, Point<float> pos, int64 time, float scaleFactor, int touchIndex)
{
    if (auto* mouse = Desktop::getInstance().mouseSources->getOrCreateMouseInputSource (type, touchIndex))
        MouseInputSource (*mouse).handleMagnifyGesture (*this, pos, time, scaleFactor);
}

But it never breaks when I pinch-zoom on my trackpad.

Then I followed the call hierarchy all the way back to line 3395 in juce_win32_Windowing.cpp:

static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
    {
        // Ensure that non-client areas are scaled for per-monitor DPI awareness v1 - can't
        // do this in peerWindowProc as we have no window at this point
        if (message == WM_NCCREATE && enableNonClientDPIScaling != nullptr)
            enableNonClientDPIScaling (h);

        if (auto* peer = getOwnerOfWindow (h))
        {
            jassert (isValidPeer (peer));
            return peer->peerWindowProc (h, message, wParam, lParam);
        }

        return DefWindowProcW (h, message, wParam, lParam);
    }

I put a breakpoint here, with condition “message == 0x119”. (windowProc() breaks all the time, but as far as I can tell, “message == 0x119” is the condition that should lead to handleMagnifyGesture () being called). But this breakpoint is also never reached. Visual Studio can’t find any higher results than windowProc() on the call hierarchy, so I’m stuck.

I’m still dead in the water because of this problem. Can anyone help? It seems possible that the problem is not with JUCE but on some other level on my laptop, but I really have no idea where to begin searching.

This seems to be a JUCE issue - my mouseMagnify handler works flawlessly on a Macbook, but doesn’t get called when doing a zoom gesture on a Windows Laptop’s trackpad. Other applications on that laptop do allow me to zoom via gesture, but JUCE just treats it like scrolling.

1 Like

Anyone had any luck solving this issue? I can’t get it to work either (using iPad pro).

2024 and this method still doesn’t work on iOS.

1 Like

2026 now

3 Likes

Researching a different bug, I may have found what’s causing mouseMagnify() to fail being called on Windows.

IMHO the problem lies in the fact that, when a JUCE program detects that it’s running on a Windows version that’s touch capable, it invariably registers itself as being able to receive touch events.

Specifically, if the API function RegisterTouchWindow() exists, then juce_Windowing_windows.cpp picks it up in canUseMultiTouch(), and immediately calls it on the current peer. There’s no way to opt-out of it at present moment that I know of.

The problem is, that mouseMagnify() on Windows is not triggered by touch events but by gestures (it’s only called through doGestureEvent() in juce_Windowing_windows.cpp)

And when a window is registered as being able to receive touch events because of the previously described check on RegisterTouchWindow (almost always nowadays, I guess), Windows stops sending it such gesture events:


(from Getting Started with Windows Touch Gestures - Win32 apps | Microsoft Learn )

I’m seeing this happening on a Windows machine that has no input peripherals connected to it, no mouse and no touch screen, I’m accessing it remotely. And still, the code sees it as touch capable because RegisterTouchWindow exists, and therefore JUCE peers are registered as capable of receiving multi-touch events.

This is not always desiderable, because it disables the default handling by Windows of some common gestures like long press to right-click (which is the bug I was researching for)

1 Like

Yep, that’s why it fails. What I don’t know is how they can fix that, and whether they will. It’s been impossible for our plugins to use pinch to zoom gestures on Windows for years now, and it annoys users who would love to be able to zoom in and out more easily.

fwiw, I have related or similar details here BR: Windows touch and gestures don't seem to work

1 Like

The simplest way would be to provide a global “switch” for turning that off (a preprocessor macro or something more elegant), or perhaps they could devise a way to toggle that per-component, although that should somehow propagate from the plug-in editor to its parent component that has an heavyweight native peer associated with it

The simplest way would be to provide a global “switch” for turning that off…

Not sure exactly why it didn’t work, but I tried commenting out the call to registerTouchWindow(), but I still did not get any gestures in the win32 message handler.

What bothers me is that I’ve never seen any response from the Juce team on this issue, in this or the related threads where this problem has been discussed.

1 Like

I’d like to echo this. For developers building products that are expected to feel native on modern systems, this is increasingly a blocker rather than a feature request.

For comparison, Qt and SDL both support trackpad gesture/magnify input cross-platform, which makes JUCE’s current gap more noticeable.

1 Like