GLFW Message Pump

jakeshirley wrote on Thursday, February 27, 2014:

Hey guys, is there a way I can set up a more traditional message pump using GLFW?


I find the callbacks a bit limited. I am coming from SDL where you can get a message for pretty much anything. I am working on Windows, so if anyone has a way to hook into the Windows message pump, that would also work!

wintertime wrote on Monday, March 10, 2014:

I felt the same inclination some time ago, as its tedious to always fill in all these callbacks and it creates more dependencies in the program.

So I just created my own event struct and a message queue (can be a simple wrapper around std::deque or whatever you like), and also some tiny functions to act as callbacks and translate it into an event and push it into a message queue. Add some setup code to put a pointer to a message queue into the glfw user pointer and set up all events and some cleanup code to revert that. Then just poll the queue and if its empty it automatically calls the glfw poll function and tries again to remove an event from the queue.
Thats some easy ~100 lines you could write and reuse forever. :slight_smile: