Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom event carrying a pointer #688

Open
yngccc opened this issue Jan 11, 2016 · 13 comments
Open

Custom event carrying a pointer #688

yngccc opened this issue Jan 11, 2016 · 13 comments
Labels
enhancement Feature suggestions and PRs macOS Wayland Windows Win32 specific (not Cygwin or WSL) X11
Milestone

Comments

@yngccc
Copy link

yngccc commented Jan 11, 2016

I like to push custom events(file descriptors IO, etc) from a thread to the main thread, I see you can do glfwPostEmptyEvent but there is no callback for it. Am I missing something or is there a plan to support this in the future? And how do I tell if glfwWaitEvent returns from a glfwPostEmptyEvent, for now I set a global flag every frame from callbacks and if that flag is not set I assume glfwPostEmptyEvent happened, is this reliable?

@elmindreda
Copy link
Member

What I should have done, but didn't think of at the time, is to add a pointer and a callback to that event. As it's too late for that, I'm planning to add a new event with that. In the meantime, you could use a standalone thread safe queue to much the same effect.

@elmindreda elmindreda self-assigned this Jan 11, 2016
@yngccc
Copy link
Author

yngccc commented Jan 11, 2016

I am thinking doing the reverse and push GLFW events through a pipe to second thread which run the actual event loop by epolling on file descriptors. Anyway good to hear this is an issue being worked on.

@elmindreda
Copy link
Member

typedef void (*GLFWcustomfun)(GLFWwindow*,void*);
GLFWcustomfun glfwSetCustomEventCallback(GLFWwindow* window, GLFWcustomfun cbfun);
void glfwPostCustomEvent(GLFWwindow* window, void* pointer);

@elmindreda elmindreda changed the title support for user event? Custom event carrying a pointer Jan 11, 2016
@elmindreda elmindreda added enhancement Feature suggestions and PRs macOS Windows Win32 specific (not Cygwin or WSL) X11 Wayland Mir labels Jan 11, 2016
@elmindreda
Copy link
Member

I'll just hijack this thread for the feature if that's all right.

@yngccc yngccc closed this as completed Jan 11, 2016
@yngccc yngccc reopened this Jan 11, 2016
@yngccc
Copy link
Author

yngccc commented Jan 11, 2016

sounds good. oops...

@jadahl
Copy link
Member

jadahl commented Jan 12, 2016

Why would this require window system specific code?

@elmindreda
Copy link
Member

@jadahl If it uses custom window events to interleave with the event stream.

@jadahl
Copy link
Member

jadahl commented Jan 15, 2016

Is it something like a roundtrip function, i.e. the callback is called when the event has been processed by the display server and been passed back to the application? "CustomEvent" sounds rather like a specially crafted data packet sent to somewhere.

@jadahl
Copy link
Member

jadahl commented Jan 15, 2016

Or does it just callback to be posted on the main thread? i.e. it won't involve any winsys things, it just needs to be aware of what thread happens to be the one dispatching window system events. If so, couldn't this be done without involving winsys backends?

@elmindreda
Copy link
Member

@jadahl The former. An actual window system event carrying a pointer, which I imagine would only be posted from secondary threads.

This could absolutely be done by a client-side thread safe queue. It's more that it's there; the window system already has a thread safe queue that can carry an opaque pointer on every platform except Mir (where GLFW has one instead) and possibly Wayland, where I haven't had time to check yet.

@jadahl
Copy link
Member

jadahl commented Jan 27, 2016

@elmindreda What you describe sounds like the latter, i.e. nothing needs to pass by the server. If it's just a callback to run on the main thread, in Wayland you'll have to add an fd to the the poll and make it readable when adding a "custom event" to some list somewhere which is dispatched when the fd becomes readable.

@elmindreda elmindreda added this to the 4.0 milestone Jul 31, 2016
@elmindreda
Copy link
Member

Postponing this until (if) there's a shared event queue in 4.0.

@congzhangzh
Copy link

hi folks, any progress?:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature suggestions and PRs macOS Wayland Windows Win32 specific (not Cygwin or WSL) X11
Projects
None yet
Development

No branches or pull requests

5 participants