os_unix.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: Unlicense OR MIT
  2. //go:build (linux && !android) || freebsd || openbsd
  3. // +build linux,!android freebsd openbsd
  4. package app
  5. import (
  6. "errors"
  7. "unsafe"
  8. "gioui.org/io/pointer"
  9. )
  10. type X11ViewEvent struct {
  11. // Display is a pointer to the X11 Display created by XOpenDisplay.
  12. Display unsafe.Pointer
  13. // Window is the X11 window ID as returned by XCreateWindow.
  14. Window uintptr
  15. }
  16. func (X11ViewEvent) implementsViewEvent() {}
  17. func (X11ViewEvent) ImplementsEvent() {}
  18. func (x X11ViewEvent) Valid() bool {
  19. return x != (X11ViewEvent{})
  20. }
  21. type WaylandViewEvent struct {
  22. // Display is the *wl_display returned by wl_display_connect.
  23. Display unsafe.Pointer
  24. // Surface is the *wl_surface returned by wl_compositor_create_surface.
  25. Surface unsafe.Pointer
  26. }
  27. func (WaylandViewEvent) implementsViewEvent() {}
  28. func (WaylandViewEvent) ImplementsEvent() {}
  29. func (w WaylandViewEvent) Valid() bool {
  30. return w != (WaylandViewEvent{})
  31. }
  32. func osMain() {
  33. select {}
  34. }
  35. type windowDriver func(*callbacks, []Option) error
  36. // Instead of creating files with build tags for each combination of wayland +/- x11
  37. // let each driver initialize these variables with their own version of createWindow.
  38. var wlDriver, x11Driver windowDriver
  39. func newWindow(window *callbacks, options []Option) {
  40. var errFirst error
  41. for _, d := range []windowDriver{wlDriver, x11Driver} {
  42. if d == nil {
  43. continue
  44. }
  45. err := d(window, options)
  46. if err == nil {
  47. return
  48. }
  49. if errFirst == nil {
  50. errFirst = err
  51. }
  52. }
  53. if errFirst == nil {
  54. errFirst = errors.New("app: no window driver available")
  55. }
  56. window.ProcessEvent(DestroyEvent{Err: errFirst})
  57. }
  58. // xCursor contains mapping from pointer.Cursor to XCursor.
  59. var xCursor = [...]string{
  60. pointer.CursorDefault: "left_ptr",
  61. pointer.CursorNone: "",
  62. pointer.CursorText: "xterm",
  63. pointer.CursorVerticalText: "vertical-text",
  64. pointer.CursorPointer: "hand2",
  65. pointer.CursorCrosshair: "crosshair",
  66. pointer.CursorAllScroll: "fleur",
  67. pointer.CursorColResize: "sb_h_double_arrow",
  68. pointer.CursorRowResize: "sb_v_double_arrow",
  69. pointer.CursorGrab: "hand1",
  70. pointer.CursorGrabbing: "move",
  71. pointer.CursorNotAllowed: "crossed_circle",
  72. pointer.CursorWait: "watch",
  73. pointer.CursorProgress: "left_ptr_watch",
  74. pointer.CursorNorthWestResize: "top_left_corner",
  75. pointer.CursorNorthEastResize: "top_right_corner",
  76. pointer.CursorSouthWestResize: "bottom_left_corner",
  77. pointer.CursorSouthEastResize: "bottom_right_corner",
  78. pointer.CursorNorthSouthResize: "sb_v_double_arrow",
  79. pointer.CursorEastWestResize: "sb_h_double_arrow",
  80. pointer.CursorWestResize: "left_side",
  81. pointer.CursorEastResize: "right_side",
  82. pointer.CursorNorthResize: "top_side",
  83. pointer.CursorSouthResize: "bottom_side",
  84. pointer.CursorNorthEastSouthWestResize: "fd_double_arrow",
  85. pointer.CursorNorthWestSouthEastResize: "bd_double_arrow",
  86. }