Giter Club home page Giter Club logo

Comments (8)

s-ludwig avatar s-ludwig commented on July 16, 2024

On Windows, you should use the default "WinAPI" driver. It will use MsgWaitForMultipleObjectsEx for its event loop and calls TranslateMessage/DispatchMessage, so that all window messages are dispatched to their window procedure as usual.

If you need any advanced message processing, such as classical dialog handling (IsDialogMessage), this would need an additional message hook API, but that would be quick to add.

from eventcore.

drug007 avatar drug007 commented on July 16, 2024

It will use MsgWaitForMultipleObjectsEx for its event loop and calls TranslateMessage/DispatchMessage, so that all window messages are dispatched to their window procedure as usual.

I understand that from the source code easily. But I can't realize what API should I use to add a callback, the event driver has the individual driver features like sockets, pipes etc. In X11 I use sockets and waitForData, what one of these features should I use in Windows? I'm a linux user in general so some obvious things can elude me.

from eventcore.

s-ludwig avatar s-ludwig commented on July 16, 2024

This is done via the window procedure, which is set using RegisterClass (WNDCLASS.lpfnWndProc member). Whenever a window is then created with that particular class name, the window procedure will be called for each message that goes to the window (done by DispatchMessage).

from eventcore.

drug007 avatar drug007 commented on July 16, 2024

Ok, I see. So eventcore encapsulates native windows message loop. But when I register a class and create the window, eventDriver exits the event loop because it has zero waiters. So I need to do something more...

from eventcore.

drug007 avatar drug007 commented on July 16, 2024

I added a dummy timer and the native window works as expected except on closing the window event loop continue to work because of the dummy timer. Probably better would be to create a dummy event and then sending it on WM_DESTROY message to gracefully exit of event loop. Is it right (ideomatic to eventcore) approach?

from eventcore.

drug007 avatar drug007 commented on July 16, 2024

Now I create an event and trigger it on WM_DESTROY. It works but I get:

Warning: Event handles leaked at driver shutdown.

But as I can see the event callback is removed on triggering and eventcore does not provide API to remove an event manually. How to exit the event loop gracefully?

from eventcore.

s-ludwig avatar s-ludwig commented on July 16, 2024

Interesting, I never came across this issue, apparently because vibe-core starts to wait for an event (eventdriver.events) as soon as its event loop starts. That event is used for other threads to signal a manual event loop exit. So creating an event, calling wait on it and then cancelWait/releaseRef after the window got closed should work properly.

I wonder if that should be something to document as a recommended way to handle windows, or if there should rather be a Windows-specific API addition, such as exposing addWaiter/removeWaiter.

from eventcore.

drug007 avatar drug007 commented on July 16, 2024

releaseRef is what I need. Currently I think that custom event is ideomatic way to achive the goal, no need to expose addWaiter/removeWaiter they should belong to private API.

from eventcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.