x11.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build linux && !android
  5. // +build linux,!android
  6. package app
  7. /*
  8. Simple on-screen app debugging for X11. Not an officially supported
  9. development target for apps, as screens with mice are very different
  10. than screens with touch panels.
  11. */
  12. /*
  13. #cgo LDFLAGS: -lEGL -lGLESv2 -lX11
  14. void createWindow(void);
  15. void processEvents(void);
  16. void swapBuffers(void);
  17. */
  18. import "C"
  19. import (
  20. "runtime"
  21. "time"
  22. "fyne.io/fyne/v2/internal/driver/mobile/event/lifecycle"
  23. "fyne.io/fyne/v2/internal/driver/mobile/event/paint"
  24. "fyne.io/fyne/v2/internal/driver/mobile/event/size"
  25. "fyne.io/fyne/v2/internal/driver/mobile/event/touch"
  26. )
  27. func init() {
  28. theApp.registerGLViewportFilter()
  29. }
  30. func main(f func(App)) {
  31. runtime.LockOSThread()
  32. workAvailable := theApp.worker.WorkAvailable()
  33. heartbeat := time.NewTicker(time.Second / 60)
  34. C.createWindow()
  35. // TODO: send lifecycle events when e.g. the X11 window is iconified or moved off-screen.
  36. theApp.sendLifecycle(lifecycle.StageFocused)
  37. // TODO: translate X11 expose events to shiny paint events, instead of
  38. // sending this synthetic paint event as a hack.
  39. theApp.events.In() <- paint.Event{}
  40. donec := make(chan struct{})
  41. go func() {
  42. f(theApp)
  43. close(donec)
  44. }()
  45. // TODO: can we get the actual vsync signal?
  46. ticker := time.NewTicker(time.Second / 60)
  47. defer ticker.Stop()
  48. var tc <-chan time.Time
  49. for {
  50. select {
  51. case <-donec:
  52. return
  53. case <-heartbeat.C:
  54. C.processEvents()
  55. case <-workAvailable:
  56. theApp.worker.DoWork()
  57. case <-theApp.publish:
  58. C.swapBuffers()
  59. tc = ticker.C
  60. case <-tc:
  61. tc = nil
  62. theApp.publishResult <- PublishResult{}
  63. }
  64. }
  65. }
  66. //export onResize
  67. func onResize(w, h int) {
  68. // TODO(nigeltao): don't assume 72 DPI. DisplayWidth and DisplayWidthMM
  69. // is probably the best place to start looking.
  70. pixelsPerPt := float32(1)
  71. theApp.events.In() <- size.Event{
  72. WidthPx: w,
  73. HeightPx: h,
  74. WidthPt: float32(w),
  75. HeightPt: float32(h),
  76. PixelsPerPt: pixelsPerPt,
  77. Orientation: screenOrientation(w, h),
  78. }
  79. }
  80. func sendTouch(t touch.Type, x, y float32) {
  81. theApp.events.In() <- touch.Event{
  82. X: x,
  83. Y: y,
  84. Sequence: 0, // TODO: button??
  85. Type: t,
  86. }
  87. }
  88. //export onTouchBegin
  89. func onTouchBegin(x, y float32) { sendTouch(touch.TypeBegin, x, y) }
  90. //export onTouchMove
  91. func onTouchMove(x, y float32) { sendTouch(touch.TypeMove, x, y) }
  92. //export onTouchEnd
  93. func onTouchEnd(x, y float32) { sendTouch(touch.TypeEnd, x, y) }
  94. var stopped bool
  95. //export onStop
  96. func onStop() {
  97. if stopped {
  98. return
  99. }
  100. stopped = true
  101. theApp.sendLifecycle(lifecycle.StageDead)
  102. theApp.events.Close()
  103. }
  104. // driverShowVirtualKeyboard does nothing on desktop
  105. func driverShowVirtualKeyboard(KeyboardType) {
  106. }
  107. // driverHideVirtualKeyboard does nothing on desktop
  108. func driverHideVirtualKeyboard() {
  109. }
  110. // driverShowFileOpenPicker does nothing on desktop
  111. func driverShowFileOpenPicker(func(string, func()), *FileFilter) {
  112. }
  113. // driverShowFileSavePicker does nothing on desktop
  114. func driverShowFileSavePicker(func(string, func()), *FileFilter, string) {
  115. }