libx11.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2024 The libXdmcp-go Authors. All rights reserved.
  2. // Use of the source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:generate go run generator.go
  5. // Package libx11 is a ccgo/v4 version of libX11.a, a library implementing the
  6. // Core X11 client protocol.
  7. package libx11 // import "modernc.org/libx11"
  8. import (
  9. "os"
  10. "unsafe"
  11. "modernc.org/libc"
  12. )
  13. // see https://gitlab.com/cznic/libx11/-/issues/2
  14. // This is not ideal, but will have to do for now.
  15. func init() {
  16. const localeDir = "XLOCALEDIR"
  17. if os.Getenv(localeDir) != "" {
  18. // Respect user setting, if any.
  19. return
  20. }
  21. possibleX11LocaleDirs := []string{
  22. "/usr/share/X11/locale",
  23. "/usr/local/share/X11/locale",
  24. }
  25. for _, dir := range possibleX11LocaleDirs {
  26. if fi, err := os.Stat(dir); err == nil && fi.IsDir() {
  27. if err = os.Setenv(localeDir, dir); err == nil {
  28. return
  29. }
  30. panic(err)
  31. }
  32. }
  33. }
  34. // int __darwin_check_fd_set_overflow(int, void *, int);
  35. var __darwin_check_fd_set_overflow func(*libc.TLS, int32, uintptr, int32) int32
  36. var utf8 = [...]byte{'U', 'T', 'F', '-', '8', 0}
  37. func __XkbGetCharset(tls *libc.TLS) (r uintptr) {
  38. // For Go we support utf-8 encoding only.
  39. return uintptr(unsafe.Pointer(&utf8))
  40. }
  41. func ____mb_cur_max(tls *libc.TLS) int32 {
  42. return 4
  43. }
  44. type socklen_t = uint32
  45. func ___inet_ntop(tls *libc.TLS, af int32, a0 uintptr, s uintptr, l socklen_t) uintptr {
  46. return libc.Xinet_ntop(tls, af, a0, s, l)
  47. }
  48. func ___inet_pton(tls *libc.TLS, af int32, s uintptr, a0 uintptr) int32 {
  49. return libc.Xinet_pton(tls, af, s, a0)
  50. }