Further enhancements to custom run loops on OS X for custom resize loops.

This commit is contained in:
Pietro Gagliardi 2016-10-31 14:33:11 -04:00
parent 211b11b80f
commit d3b33e39ce
2 changed files with 27 additions and 13 deletions

View File

@ -171,7 +171,20 @@ void uiMainSteps(void)
int uiMainStep(int wait)
{
return mainStep(wait, ^(NSEvent *e) {
struct nextEventArgs nea;
nea.mask = NSAnyEventMask;
// ProPuke did this in his original PR requesting this
// I'm not sure if this will work, but I assume it will...
nea.duration = [NSDate distantPast];
if (wait) // but this is normal so it will work
nea.duration = [NSDate distantFuture];
nea.mode = NSDefaultRunLoopMode;
nea.dequeue = YES;
return mainStep(&nea, ^(NSEvent *e) {
return NO;
});
}
@ -179,26 +192,20 @@ int uiMainStep(int wait)
// see also:
// - http://www.cocoawithlove.com/2009/01/demystifying-nsapplication-by.html
// - https://github.com/gnustep/gui/blob/master/Source/NSApplication.m
int mainStep(int wait, BOOL (^interceptEvent)(NSEvent *e))
int mainStep(struct nextEventArgs *nea, BOOL (^interceptEvent)(NSEvent *e))
{
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];
if (!isRunning())
return 0;
e = [realNSApp() nextEventMatchingMask:NSAnyEventMask
untilDate:expire
inMode:NSDefaultRunLoopMode
dequeue:YES];
e = [realNSApp() nextEventMatchingMask:nea->mask
untilDate:nea->duration
inMode:nea->mode
dequeue:nea->dequeue];
if (e == nil)
return 1;

View File

@ -43,7 +43,14 @@ extern void uninitMenus(void);
@property (strong) menuManager *menuManager;
@end
#define appDelegate() ((appDelegate *) [realNSApp() delegate])
extern int mainStep(int wait, BOOL (^interceptEvent)(NSEvent *));
struct nextEventArgs {
NSEventMask mask;
NSDate *duration;
// LONGTERM no NSRunLoopMode?
NSString *mode;
BOOL dequeue;
};
extern int mainStep(struct nextEventArgs *nea, BOOL (^interceptEvent)(NSEvent *));
// util.m
extern void disableAutocorrect(NSTextView *);