github.com/rajveermalviya/gamen@v0.1.2-0.20220930195403-9be15877c1aa/internal/wayland/output.go (about) 1 //go:build linux && !android 2 3 package wayland 4 5 /* 6 7 #include "wayland-client-protocol.h" 8 9 */ 10 import "C" 11 12 import ( 13 "runtime/cgo" 14 "unsafe" 15 ) 16 17 type Output struct { 18 output *C.struct_wl_output 19 name uint32 20 21 // from geometry event 22 x, y int32 23 physicalWidth, physicalHeight int32 24 subpixel enum_wl_output_subpixel 25 make, model string 26 transform enum_wl_output_transform 27 28 // from mode event 29 flags enum_wl_output_mode 30 width, height int32 31 refresh int32 32 33 scaleFactor int32 34 } 35 36 //export outputHandleGeometry 37 func outputHandleGeometry(data unsafe.Pointer, wl_output *C.struct_wl_output, 38 x, y C.int32_t, 39 physical_width, physical_height C.int32_t, 40 subpixel enum_wl_output_subpixel, 41 make, model *C.char, 42 transform enum_wl_output_transform, 43 ) { 44 d, ok := (*cgo.Handle)(data).Value().(*Display) 45 if !ok { 46 return 47 } 48 49 output, ok := d.outputs[wl_output] 50 if !ok { 51 return 52 } 53 54 output.x = int32(x) 55 output.y = int32(y) 56 output.physicalWidth = int32(physical_width) 57 output.physicalHeight = int32(physical_height) 58 output.subpixel = subpixel 59 output.make = C.GoString(make) 60 output.model = C.GoString(model) 61 output.transform = transform 62 } 63 64 //export outputHandleMode 65 func outputHandleMode(data unsafe.Pointer, wl_output *C.struct_wl_output, 66 flags enum_wl_output_mode, 67 width, height C.int32_t, 68 refresh C.int32_t, 69 ) { 70 d, ok := (*cgo.Handle)(data).Value().(*Display) 71 if !ok { 72 return 73 } 74 75 output, ok := d.outputs[wl_output] 76 if !ok { 77 return 78 } 79 80 output.flags = flags 81 output.width = int32(width) 82 output.height = int32(height) 83 output.refresh = int32(refresh) 84 } 85 86 //export outputHandleScale 87 func outputHandleScale(data unsafe.Pointer, wl_output *C.struct_wl_output, factor C.int32_t) { 88 d, ok := (*cgo.Handle)(data).Value().(*Display) 89 if !ok { 90 return 91 } 92 93 output, ok := d.outputs[wl_output] 94 if !ok { 95 return 96 } 97 98 output.scaleFactor = int32(factor) 99 } 100 101 //export outputHandleDone 102 func outputHandleDone(data unsafe.Pointer, wl_output *C.struct_wl_output) { 103 d, ok := (*cgo.Handle)(data).Value().(*Display) 104 if !ok { 105 return 106 } 107 108 for _, w := range d.windows { 109 w.updateScaleFactor() 110 } 111 }