golang-design / clipboard

📋 cross-platform clipboard package that supports accessing text and image in Go (macOS/Linux/Windows/Android/iOS)
https://golang.design/x/clipboard
MIT License
579 stars 64 forks source link

linux: dynamically load libX11 #20

Closed microo8 closed 2 years ago

microo8 commented 2 years ago

Removing linking of libX11 and replacing it with dlopen to call the functions dynamically. For the future wayland support, the library will not require the libX11 library to be installed on the running system. For compiling it we need it, because of the huge and complicated type definitions, but the compiled binary will run also on a system without libX11.

Maybe in the future we can eliminate also the X11/Xlib.h and X11/Xatom.h. The only thing that really needs to be declared is the XEvent and it's attributes, other things can be a void pointer or some c primitives.

microo8 commented 2 years ago

So I changed it to load libX11 only once when calling a function. Tests are ok.

changkun commented 2 years ago

Thanks, I'll merge it first and then dig more about this. After a quick inspection on the Go's plugin package, it turns out they are the exact same appraoch.

microo8 commented 2 years ago

Thanks! It's always a great feeling when some of my work is merged. Now I'll try to find out how to wayland :)