andlabs / andlabs/libui

uiMainStep not working on OSX

Abierto
#125 2 comentarios 0 reacciones 0 asignados Ver en GitHub
custom main loops
Lenguaje dominante
C
Estrellas
10.9k
Forks
612
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

I'm using `uiMainStep` to run `libui` events without blocking node event loop.
This method work well on Linux, but doesn't on OSX: the UI is completely blocked. It work well if I use `uiMain`, but I can't because it would block node loop.

I do some investigation on `uiMainStep` darwin source code, and I solved the problem by commenting two lines:

``` objectivec
// see also:
// - http://www.cocoawithlove.com/2009/01/demystifying-nsapplication-by.html
// - https://github.com/gnustep/gui/blob/master/Source/NSApplication.m
int uiMainStep(int wait)
{
NSDate *expire;
NSEvent *e;
NSEventType type;

@autoreleasepool {
// ProPuke did this in his original PR requesting this
// I'm not sure if this will work, but I assume it will...
expire = [NSDate distantPast];
if (wait) // but this is normal so it will work
expire = [NSDate distantFuture];

// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// Removing these check it work:
// if (![realNSApp() isRunning])
// return 0;
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //

e = [realNSApp() nextEventMatchingMask:NSAnyEventMask
untilDate:expire
inMode:NSDefaultRunLoopMode
dequeue:YES];
if (e == nil)
return 1;

type = [e type];
[realNSApp() sendEvent:e];
[realNSApp() updateWindows];

// GNUstep does this
// it also updates the Services menu but there doesn't seem to be a public API for that so
if (type != NSPeriodic && type != NSMouseMoved)
[[realNSApp() mainMenu] update];

return 1;
}
}
```

I don't know objective-c , so I'm not sure... but it work now
If someone confirm it as a good solution, I could provide a PR soon if needed.
/cc @ProPuke

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.