github.com/rajveermalviya/gamen@v0.1.2-0.20220930195403-9be15877c1aa/display/display_linux.go (about) 1 //go:build linux && !android 2 3 package display 4 5 import ( 6 "os" 7 "unsafe" 8 9 "github.com/rajveermalviya/gamen/internal/wayland" 10 "github.com/rajveermalviya/gamen/internal/xcb" 11 ) 12 13 // NewDisplay initializes the event loop and returns 14 // a handle to manage it. 15 // 16 // Must only be called from main goroutine. 17 func NewDisplay() (Display, error) { 18 switch os.Getenv("GAMEN_DISPLAY_BACKEND") { 19 case "wayland": 20 return wayland.NewDisplay() 21 22 case "xcb": 23 return xcb.NewDisplay() 24 25 case "": 26 d, err := wayland.NewDisplay() 27 if err == nil { 28 return d, nil 29 } 30 31 return xcb.NewDisplay() 32 33 default: 34 panic("invalid GAMEN_DISPLAY_BACKEND") 35 } 36 } 37 38 // NewWindow creates a new window for the provided 39 // display event loop. 40 // 41 // To receive events you must set individual callbacks 42 // via Set[event]Callback methods. 43 // 44 // Must only be called from main goroutine. 45 func NewWindow(d Display) (Window, error) { 46 switch d := d.(type) { 47 case *wayland.Display: 48 return wayland.NewWindow(d) 49 case *xcb.Display: 50 return xcb.NewWindow(d) 51 52 default: 53 panic("invalid Display") 54 } 55 } 56 57 type WaylandWindow interface { 58 WlDisplay() unsafe.Pointer 59 WlSurface() unsafe.Pointer 60 } 61 62 type XcbWindow interface { 63 XcbConnection() unsafe.Pointer 64 XcbWindow() uint32 65 } 66 67 type XlibWindow interface { 68 XlibDisplay() unsafe.Pointer 69 XlibWindow() uint32 70 }