-
Notifications
You must be signed in to change notification settings - Fork 611
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
request: uiMainStepPoll() #146
Comments
To clarify - do we just need to be able to wait for a message under windows, with a maximum timeout period specified? If so the below should do this:
|
|
I've implemented an event loop based on libuv polling on libui-node. I second @daurnimator on requesting a public API that expose a file descriptor (unix) or HANDLE (windows) to wait on. @andlabs you may want to give a look at how I implemented the loop, you could libuv to implement it directly on libui, if you don't mind add another dependency. libui has a c interface, is supports same platforms as libui and greatly simplify event loop management.... |
libuv isn't what you want here. You possibly want something like this: A cross platform way to gather many file handles under a single handle. On windows, such a primitive does not exist and must be synthesised with a thread signalling an event. The simpler solution (that IMO should be taken) is to just expose all the fds/HANDLEs that libui is interested in, and it's up to the user/host application to provide the main loop. GTK's API can probably be used as the template here. |
The problem is there is no file descriptor exposed by any of the widget toolkits for events. |
|
Is |
Yes. though it's not going anywhere; it's part of the libdispatch ABI. (4CF is "for Core Foundation"; it's what CFRunLoop uses under the hood. see https://opensource.apple.com/source/CF/CF-1153.18/CFRunLoop.c) The closest thing to docs is from
==> This works due to I did some work on a demo/example over here: https://gist.github.com/daurnimator/8cc2ef09ad72a5577b66f34957559e47 |
@daurnimator Just to check that it works on 10.11, I ran
|
Great work @daurnimator. I will try to integrate it in libui-node loop using libuv |
Btw, I wrote a blog post with some info: http://daurnimator.com/post/147024385399/using-your-own-main-loop-on-osx |
@parro-it how did you go? I see you copied my code into https://github.com/parro-it/libui-node/blob/d734075232cbb5eeb4b2cb90c907b7015332da52/src/arch/darwin/EventLoop_uvpoll.mm#L20 but I'm not sure if you're using it. (and there's still debugging statements in there!) |
Hi @daurnimator, I'm actually not using it, the one you linked is an old version. So I implemented the event loop using a background thread that repeatedly check, with a blocking call, if there are any event pending. Whenever there are, it calls a function on main thread to dispatch them. Windows to check for GUI events pending from a separate thread, it appear it's just impossible. So on Windows I reverted to a less performant timeout check. I still hope to find a way to improve the Windows part... |
Howso? |
This and the associated 4CF test program are now the second and third (respectively) Google results for For unrelated reasons I now understand what
There is; it's called |
It gives you something to listen on to know when gcd needs to do work. With it you can write your own main loop using your own choice of mach ports/select/poll/kqueue. |
Ah, so just doing this wouldn't be enough to handle all of libui for what you want to do then — you'd also need to know about all the other possible event sources. But I suppose you can gleam a hint from the Core Foundation source code and maybe the lesser documented Core Graphics APIs? |
Other sources such as what? |
The window manager and devices. Look at the implementation of I should probably make adding I/O to the standard main loop (the opposite desire) a separate possible feature request. |
As far as I understand things, all of those use GCD to wait for events. |
Huh; that sounds like a massive change for 10.6 to do... But sure; if that does work then ok? Easiest way to find out would be to put one of your custom run loops in a real Cocoa app and see what breaks, if anything. |
All we need to do is add a function |
I now understand what you mean: what if something uses On OSX |
(Copy-pasting from #21 (comment)) Okay, I need to resurrect this.
How do people do this right now on macOS in a macOS-native application? Because there is no real supported way to do this directly in the same way libui does it now, and even if I did just recreate what And for the record, I am specifically referring to GUI apps here, not just programs that roll their own poll/kqueue loop. |
split from #95
a way to combine uiMainStep() with select() or poll()
on GTK+ and OS X this should be fine
on Windows I don't know one thing:
What would the equivalent of a
select()
be on Windows? It appearsMsgWaitForMultipleObjectsEx()
does not accept file or socket handles. Does it have to do withOVERLAPPED
? I see GLib accepts file handles on Windows...The text was updated successfully, but these errors were encountered: