##// END OF EJS Templates
run CFRunLoopRun if NSApp:run finishes on its own...
Min RK -
Show More
@@ -7,6 +7,7 b' Calls NSApp / CoreFoundation APIs via ctypes.'
7
7
8 import ctypes
8 import ctypes
9 import ctypes.util
9 import ctypes.util
10 from threading import Event
10
11
11 objc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('objc'))
12 objc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('objc'))
12
13
@@ -97,8 +98,11 b' def _wake(NSApp):'
97 msg(NSApp, n('postEvent:atStart:'), void_p(event), True)
98 msg(NSApp, n('postEvent:atStart:'), void_p(event), True)
98
99
99
100
101 _triggered = Event()
102
100 def _input_callback(fdref, flags, info):
103 def _input_callback(fdref, flags, info):
101 """Callback to fire when there's input to be read"""
104 """Callback to fire when there's input to be read"""
105 _triggered.set()
102 CFFileDescriptorInvalidate(fdref)
106 CFFileDescriptorInvalidate(fdref)
103 CFRelease(fdref)
107 CFRelease(fdref)
104 NSApp = _NSApp()
108 NSApp = _NSApp()
@@ -111,6 +115,7 b' _c_input_callback = _c_callback_func_type(_input_callback)'
111
115
112 def _stop_on_read(fd):
116 def _stop_on_read(fd):
113 """Register callback to stop eventloop when there's data on fd"""
117 """Register callback to stop eventloop when there's data on fd"""
118 _triggered.clear()
114 fdref = CFFileDescriptorCreate(None, fd, False, _c_input_callback, None)
119 fdref = CFFileDescriptorCreate(None, fd, False, _c_input_callback, None)
115 CFFileDescriptorEnableCallBacks(fdref, kCFFileDescriptorReadCallBack)
120 CFFileDescriptorEnableCallBacks(fdref, kCFFileDescriptorReadCallBack)
116 source = CFFileDescriptorCreateRunLoopSource(None, fdref, 0)
121 source = CFFileDescriptorCreateRunLoopSource(None, fdref, 0)
@@ -130,4 +135,9 b' def inputhook(context):'
130 return
135 return
131 _stop_on_read(context.fileno())
136 _stop_on_read(context.fileno())
132 msg(NSApp, n('run'))
137 msg(NSApp, n('run'))
133
138 if not _triggered.is_set():
139 # app closed without firing callback,
140 # probably due to last window being closed.
141 # Run the loop manually in this case,
142 # since there may be events still to process (#9734)
143 CoreFoundation.CFRunLoopRun()
General Comments 0
You need to be logged in to leave comments. Login now