Window loop custom event management

I noticed that GLFW doesn’t currently support trackpad (ex: windows precision trackpad) “pinch-to-zoom”. By zoom, I mean the one-to-one zoom effect something like below.

ezgif.com-gif-maker (1)

I want to try out implementing custom win32 event handling for my app. Is there a way I can achieve this without rewriting the internal event loop?

For win32 I believe you can do this either by using SetWindowsHookEx to add your own window callback function or using PeekMessage with the filter parameters set to receive only the messages you need, though the later case might miss some messages which GLFW processes in _glfwPlatformPollEvents which you still need to call.

How would I set this up, I’m not sure I understand what’s required.

So I add my filter with PeekMessage, process said event, and then call glfwPollEvents. Will that be sufficient?

That should work, except occasionally it will miss some messages as if they happen between you calling PeekMessage and glfwPollEvents the GLFW message loop will ‘swallow’ them.

SetWindowsHookEx would be a more guaranteed solution to ensure you get all messages, though it’s slightly more complex to use so you could try the PeekMessage approach first.

An alternative is to modify the GLFW message function and maintain a fork, which might be easier.

it will miss some messages as if they happen between you calling PeekMessage and glfwPollEvents

How so? I thought peek doesn’t remove the message from the message queue.

The difference between GetMessage and PeekMessage is that PeekMessage does not wait until a message is posted, and it has an extra parameter wRemoveMsg which controls whether a message is removed from the queue or not.

_glfwPlatformPollEvents uses PM_REMOVE which removes messages - it has to otherwise the queue would not drain and only the first message would be read.

Ahh I see now what you mean, and how events can be “swallowed”. Took me a while, thanks!

Hello, I noticed that WM_GESTURE isn’t what I’m really looking for. This is off-topic, but wanted to ask if you knew how I can capture trackpad (not touch screen) events.

I’m not receiving any WM_GESTURE events when I try to zoom or rotate. I assume it’s the legacy gesture handling, and not the new “precision drivers” events

Does WM_TOUCH work?

Nope :frowning:
That didn’t work.

I’m doing something like this, hope that’s correct

image

I changed the file-drop to print “drop” and that seems to work, so I guess I am messing with the right loop, but then again, not sure

Note that copying text is more useful than an image as I can’t copy text from an image :slight_smile:

You’ve put your code in the if (!window) section, which as per the comment is for the hidden helper window and for a regular window during its initial creation. You should put your changes in the second switch (uMsg) section after this, namely lines 548-1214 of the original code where WM_MOUSEMOVE and other input is processed.

copying text is more useful than an image

Understood :), my bad.

Ahh you’re right! I’ll check with the other loop, thanks for the heads up!

    // ...
    switch (uMsg)
    {
        case WM_GESTURE:
        case WM_TOUCH: {
            printf("WM GESTURE OR TOUCH\n");
            break;
        }
        case WM_MOUSEACTIVATE:
        // ...  

I still get nothing

I don’t know enough about touch/gesture input to help you further, so I would just advise to read the documentation and perhaps look for samples and try those.

Thanks for your help so far!
pinch-gesture seems to activate the WM_MOUSEWHEEL event