andlabs / andlabs/libui

uiMainStep not working on OSX

オープン
#125 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
custom main loops
主要言語
C
スター
10.9k
フォーク
612
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。