| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- // Copyright 2014 The Go Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style
- // license that can be found in the LICENSE file.
- //go:build (linux && !android) || freebsd
- // +build linux,!android freebsd
- package app
- /*
- Simple on-screen app debugging for X11. Not an officially supported
- development target for apps, as screens with mice are very different
- than screens with touch panels.
- */
- /*
- #cgo LDFLAGS: -lEGL -lGLESv2 -lX11
- #cgo freebsd CFLAGS: -I/usr/local/include/
- void createWindow(void);
- void processEvents(void);
- void swapBuffers(void);
- */
- import "C"
- import (
- "runtime"
- "time"
- "fyne.io/fyne/v2/internal/driver/mobile/event/lifecycle"
- "fyne.io/fyne/v2/internal/driver/mobile/event/paint"
- "fyne.io/fyne/v2/internal/driver/mobile/event/size"
- "fyne.io/fyne/v2/internal/driver/mobile/event/touch"
- )
- func init() {
- theApp.registerGLViewportFilter()
- }
- func main(f func(App)) {
- runtime.LockOSThread()
- workAvailable := theApp.worker.WorkAvailable()
- heartbeat := time.NewTicker(time.Second / 60)
- C.createWindow()
- // TODO: send lifecycle events when e.g. the X11 window is iconified or moved off-screen.
- theApp.sendLifecycle(lifecycle.StageFocused)
- // TODO: translate X11 expose events to shiny paint events, instead of
- // sending this synthetic paint event as a hack.
- theApp.events.In() <- paint.Event{}
- donec := make(chan struct{})
- go func() {
- f(theApp)
- close(donec)
- }()
- // TODO: can we get the actual vsync signal?
- ticker := time.NewTicker(time.Second / 60)
- defer ticker.Stop()
- var tc <-chan time.Time
- for {
- select {
- case <-donec:
- return
- case <-heartbeat.C:
- C.processEvents()
- case <-workAvailable:
- theApp.worker.DoWork()
- case <-theApp.publish:
- C.swapBuffers()
- tc = ticker.C
- case <-tc:
- tc = nil
- theApp.publishResult <- PublishResult{}
- }
- }
- }
- func GoBack() {
- // When simulating mobile there are no other activities open (and we can't just force background)
- }
- //export onResize
- func onResize(w, h int) {
- // TODO(nigeltao): don't assume 72 DPI. DisplayWidth and DisplayWidthMM
- // is probably the best place to start looking.
- pixelsPerPt := float32(1)
- theApp.events.In() <- size.Event{
- WidthPx: w,
- HeightPx: h,
- WidthPt: float32(w),
- HeightPt: float32(h),
- PixelsPerPt: pixelsPerPt,
- Orientation: screenOrientation(w, h),
- }
- }
- func sendTouch(t touch.Type, x, y float32) {
- theApp.events.In() <- touch.Event{
- X: x,
- Y: y,
- Sequence: 0, // TODO: button??
- Type: t,
- }
- }
- //export onTouchBegin
- func onTouchBegin(x, y float32) { sendTouch(touch.TypeBegin, x, y) }
- //export onTouchMove
- func onTouchMove(x, y float32) { sendTouch(touch.TypeMove, x, y) }
- //export onTouchEnd
- func onTouchEnd(x, y float32) { sendTouch(touch.TypeEnd, x, y) }
- var stopped bool
- //export onStop
- func onStop() {
- if stopped {
- return
- }
- stopped = true
- theApp.sendLifecycle(lifecycle.StageDead)
- theApp.events.Close()
- }
- // driverShowVirtualKeyboard does nothing on desktop
- func driverShowVirtualKeyboard(KeyboardType) {
- }
- // driverHideVirtualKeyboard does nothing on desktop
- func driverHideVirtualKeyboard() {
- }
- // driverShowFileOpenPicker does nothing on desktop
- func driverShowFileOpenPicker(func(string, func()), *FileFilter) {
- }
- // driverShowFileSavePicker does nothing on desktop
- func driverShowFileSavePicker(func(string, func()), *FileFilter, string) {
- }
|