Load glfw primary selection functions dynamically

Allows kitty to run on wayland. Also dont try to set the window
icon on wayland.
This commit is contained in:
Kovid Goyal
2017-10-18 12:46:32 +05:30
parent d4e5bc4141
commit e558880e8f
5 changed files with 72 additions and 76 deletions

View File

@@ -75,3 +75,47 @@ if ctypes.sizeof(GLfloat) != 4:
raise RuntimeError('float size is not 4')
if ctypes.sizeof(GLint) != 4:
raise RuntimeError('int size is not 4')
def get_glfw_lib_name():
try:
for line in open('/proc/{}/maps'.format(os.getpid())):
lib = line.split()[-1]
if '/libglfw.so' in lib:
return lib
except Exception as err:
try:
print(str(err), file=sys.stderr)
except Exception:
pass
return 'libglfw.so.3'
def glfw_lib():
ans = getattr(glfw_lib, 'ans', None)
if ans is None:
ans = glfw_lib.ans = ctypes.CDLL('libglfw.3.dylib' if isosx else get_glfw_lib_name())
return ans
def selection_clipboard_funcs():
ans = getattr(selection_clipboard_funcs, 'ans', None)
if ans is None:
lib = glfw_lib()
if hasattr(lib, 'glfwGetX11SelectionString'):
g = lib.glfwGetX11SelectionString
g.restype = ctypes.c_char_p
g.argtypes = []
s = lib.glfwSetX11SelectionString
s.restype = None
s.argtypes = [ctypes.c_char_p]
ans = g, s
else:
ans = None, None
selection_clipboard_funcs.ans = ans
return ans
iswayland = False
if not isosx:
iswayland = selection_clipboard_funcs()[0] is None