##// END OF EJS Templates
tidy, docstrings
Min RK -
Show More
@@ -1,3 +1,7 b''
1 """Inputhook for OS X
2
3 Calls NSApp / CoreFoundation APIs via ctypes.
4 """
1 5
2 6 # obj-c boilerplate from appnope, used under BSD 2-clause
3 7
@@ -5,7 +9,6 b' import ctypes'
5 9 import ctypes.util
6 10
7 11 objc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('objc'))
8 CoreFoundation = ctypes.cdll.LoadLibrary(ctypes.util.find_library('CoreFoundation'))
9 12
10 13 void_p = ctypes.c_void_p
11 14
@@ -30,7 +33,11 b' def C(classname):'
30 33 """get an ObjC Class by name"""
31 34 return objc.objc_getClass(_utf8(classname))
32 35
33 # CoreFoundation calls we will use:
36 # end obj-c boilerplate from appnope
37
38 # CoreFoundation C-API calls we will use:
39 CoreFoundation = ctypes.cdll.LoadLibrary(ctypes.util.find_library('CoreFoundation'))
40
34 41 CFFileDescriptorCreate = CoreFoundation.CFFileDescriptorCreate
35 42 CFFileDescriptorCreate.restype = void_p
36 43 CFFileDescriptorCreate.argtypes = [void_p, ctypes.c_int, ctypes.c_bool, void_p]
@@ -66,10 +73,12 b' CFFileDescriptorInvalidate.argtypes = [void_p]'
66 73 kCFFileDescriptorReadCallBack = 1
67 74 kCFRunLoopCommonModes = void_p.in_dll(CoreFoundation, 'kCFRunLoopCommonModes')
68 75
76
69 77 def _NSApp():
70 78 """Return the global NSApplication instance (NSApp)"""
71 79 return msg(C('NSApplication'), n('sharedApplication'))
72 80
81
73 82 def _wake(NSApp):
74 83 """Wake the Application"""
75 84 event = msg(C('NSEvent'),
@@ -87,6 +96,7 b' def _wake(NSApp):'
87 96 )
88 97 msg(NSApp, n('postEvent:atStart:'), void_p(event), True)
89 98
99
90 100 def _input_callback(fdref, flags, info):
91 101 """Callback to fire when there's input to be read"""
92 102 CFFileDescriptorInvalidate(fdref)
@@ -98,6 +108,7 b' def _input_callback(fdref, flags, info):'
98 108 _c_callback_func_type = ctypes.CFUNCTYPE(None, void_p, void_p, void_p)
99 109 _c_input_callback = _c_callback_func_type(_input_callback)
100 110
111
101 112 def _stop_on_read(fd):
102 113 """Register callback to stop eventloop when there's data on fd"""
103 114 fdref = CFFileDescriptorCreate(None, fd, False, _c_input_callback, None)
@@ -107,6 +118,7 b' def _stop_on_read(fd):'
107 118 CFRunLoopAddSource(loop, source, kCFRunLoopCommonModes)
108 119 CFRelease(source)
109 120
121
110 122 def inputhook(context):
111 123 """Inputhook for Cocoa (NSApp)"""
112 124 NSApp = _NSApp()
General Comments 0
You need to be logged in to leave comments. Login now