Skip to content
6 changes: 3 additions & 3 deletions core/chooser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestChooserEditableClick(t *testing.T) {
}

func TestChooserEditableTextFieldClick(t *testing.T) {
t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
// t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
b := NewBody()
b.Styler(func(s *styles.Style) {
s.Min.Set(units.Em(20), units.Em(10))
Expand All @@ -112,7 +112,7 @@ func TestChooserAllowNewClick(t *testing.T) {
}

func TestChooserEditableAllowNewClick(t *testing.T) {
t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
// t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
b := NewBody()
b.Styler(func(s *styles.Style) {
s.Min.Set(units.Em(20), units.Em(10))
Expand All @@ -124,7 +124,7 @@ func TestChooserEditableAllowNewClick(t *testing.T) {
}

func TestChooserEditableAllowNewTextFieldClick(t *testing.T) {
t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
// t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
b := NewBody()
b.Styler(func(s *styles.Style) {
s.Min.Set(units.Em(20), units.Em(10))
Expand Down
2 changes: 1 addition & 1 deletion core/filepicker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestFilePicker(t *testing.T) {
t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
// t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
b := NewBody()
NewFilePicker(b)
b.AssertRender(t, "file-picker/basic")
Expand Down
2 changes: 1 addition & 1 deletion core/form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (mp *morePerson) FieldWidget(field string) Value {
}

func TestForm(t *testing.T) {
t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
// t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
b := NewBody()
NewForm(b).SetStruct(&person{Name: "Go", Age: 35})
b.AssertRender(t, "form/basic")
Expand Down
6 changes: 3 additions & 3 deletions core/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

func init() {
system.HandleRecover = handleRecover
system.InitScreenLogicalDPIFunc = AppearanceSettings.applyDPI // called when screens are initialized
TheApp.CogentCoreDataDir() // ensure it exists
theWindowGeometrySaver.needToReload() // gets time stamp associated with open, so it doesn't re-open
system.UpdateLogicalDPIScaleFunc = AppearanceSettings.updateLogicalDPI
TheApp.CogentCoreDataDir() // ensure it exists
theWindowGeometrySaver.needToReload() // gets time stamp associated with open, so it doesn't re-open
theWindowGeometrySaver.open()
}
7 changes: 5 additions & 2 deletions core/renderwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,12 @@ func (w *renderWindow) handleWindowEvents(e events.Event) {
}
if !TheApp.Platform().IsMobile() { // native desktop
if TheApp.NScreens() > 0 {
AppearanceSettings.Apply()
// if TheApp.Platform() == system.Offscreen { // note: this is not necessary,
// // but matches the testing results in subtle ways
// AppearanceSettings.Apply()
// }
UpdateAll()
theWindowGeometrySaver.restoreAll()
// theWindowGeometrySaver.restoreAll()
}
} else {
w.resized()
Expand Down
12 changes: 9 additions & 3 deletions core/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ func (as *AppearanceSettingsData) Apply() { //types:add
as.applyDPI()
}

// applyDPI updates the screen LogicalDPI values according to current
// settings and zoom factor, and then updates all open windows as well.
func (as *AppearanceSettingsData) applyDPI() {
// updateLogicalDPI updates the screen LogicalDPI values according to current
// settings and zoom factor. set this as [system.UpdateLogicalDPIFunc] function.
func (as *AppearanceSettingsData) updateLogicalDPI() {
// zoom is percentage, but LogicalDPIScale is multiplier
system.LogicalDPIScale = as.Zoom / 100
// fmt.Println("system ldpi:", system.LogicalDPIScale)
Expand All @@ -401,6 +401,12 @@ func (as *AppearanceSettingsData) applyDPI() {
}
sc.UpdateLogicalDPI()
}
}

// applyDPI updates the screen LogicalDPI values according to current
// settings and zoom factor, and then updates all open windows as well.
func (as *AppearanceSettingsData) applyDPI() {
as.updateLogicalDPI()
for _, w := range AllRenderWindows {
w.SystemWindow.SetLogicalDPI(w.SystemWindow.Screen().LogicalDPI)
// this isn't DPI-related, but this is the most efficient place to do it
Expand Down
4 changes: 2 additions & 2 deletions core/slider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestSliderStart(t *testing.T) {
}

func TestSliderChange(t *testing.T) {
t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
// t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
b := NewBody()
sr := NewSlider(b)
n := 0
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestSliderChangeClick(t *testing.T) {
}

func TestSliderInput(t *testing.T) {
t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
// t.Skip("todo: unreliable, https://github.com/cogentcore/core/issues/1641")
b := NewBody()
sr := NewSlider(b)
n := 0
Expand Down
7 changes: 4 additions & 3 deletions core/svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ func (sv *SVG) Render() {
if sv.SVG == nil {
return
}
needsRender := !sv.IsReadOnly()
needsRender := !sv.IsReadOnly() || sv.NeedsRebuild()
if !needsRender {
if sv.image == nil {
needsRender = true
} else {
sz := sv.image.Bounds().Size()
if sz != sv.prevSize || sz == (image.Point{}) {
sv.SVG.UpdateSize()
sz := sv.SVG.Geom.Size
if sz != sv.prevSize || sv.image.Bounds().Size() == (image.Point{}) {
needsRender = true
}
}
Expand Down
4 changes: 2 additions & 2 deletions system/driver/android/android.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ func (a *App) MainUI(vm, jniEnv, ctx uintptr) error {
a.Scrn.PhysicalDPI = dpi
a.Scrn.LogicalDPI = dpi

if system.InitScreenLogicalDPIFunc != nil {
system.InitScreenLogicalDPIFunc()
if system.UpdateLogicalDPIScaleFunc != nil {
system.UpdateLogicalDPIScaleFunc()
}

physX := 25.4 * float32(widthPx) / dpi
Expand Down
6 changes: 3 additions & 3 deletions system/driver/desktop/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ func (a *App) InitGPU() {
}

func (a *App) NewWindow(opts *system.NewWindowOptions) (system.Window, error) {
if len(a.Windows) == 0 && system.InitScreenLogicalDPIFunc != nil {
if len(a.Windows) == 0 && system.UpdateLogicalDPIScaleFunc != nil {
if ScreenDebug {
log.Println("app first new window calling InitScreenLogicalDPIFunc")
log.Println("app first new window calling UpdateLogicalDPIScaleFunc")
}
system.InitScreenLogicalDPIFunc()
system.UpdateLogicalDPIScaleFunc()
}

sc := a.Screens[0]
Expand Down
46 changes: 27 additions & 19 deletions system/driver/desktop/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,32 @@ var (
// MonitorChange is called when a monitor is connected to or
// disconnected from the system.
func (a *App) MonitorChange(monitor *glfw.Monitor, event glfw.PeripheralEvent) {
if ScreenDebug {
enm := "Unknown"
if event == glfw.Connected {
enm = "Connected"
} else {
enm = "Disconnected"
}
log.Printf("ScreenDebug: monitorChange: %v event: %v\n", monitor.GetName(), enm)
}
a.GetScreens()
if len(a.Windows) > 0 {
fw := a.Windows[0]
go func() {
if ScreenDebug {
log.Println("ScreenDebug: monitorChange: sending screen update")
enm := "Unknown"
if event == glfw.Connected {
enm = "Connected"
} else {
enm = "Disconnected"
}
log.Printf("ScreenDebug: monitorChange: %v event: %v\n", monitor.GetName(), enm)
}
fw.Event.Window(events.ScreenUpdate)
} else {
if ScreenDebug {
log.Println("ScreenDebug: monitorChange: no windows, NOT sending screen update")
a.GetScreens()
if len(a.Windows) > 0 {
if ScreenDebug {
log.Println("ScreenDebug: monitorChange: sending screen update")
}
for _, w := range a.Windows {
w.SetLogicalDPI(w.Screen().LogicalDPI)
}
fw := a.Windows[0]
fw.Event.Window(events.ScreenUpdate)
} else {
if ScreenDebug {
log.Println("ScreenDebug: monitorChange: no windows, NOT sending screen update")
}
}
}
}()
}

var lastScreenPoll time.Time
Expand Down Expand Up @@ -155,9 +160,9 @@ func (a *App) GetScreens() {
sc.DevicePixelRatio = 2
sc.PixelSize = sc.Geometry.Max.Mul(2)
sc.PhysicalSize = image.Point{344, 222}
sc.UpdatePhysicalDPI()
sc.Depth = 24
sc.RefreshRate = 60
sc.UpdatePhysicalDPI()
sc.UpdateLogicalDPI()
if ScreenDebug {
log.Printf("ScreenDebug: getScreens: MacOS unknown display set to Built-in Retina Display %d:\n%s\n", i, reflectx.StringJSON(sc))
Expand Down Expand Up @@ -232,6 +237,9 @@ func (a *App) GetScreens() {
a.Screens[1].ScreenNumber = 1
}
}
if system.UpdateLogicalDPIScaleFunc != nil {
system.UpdateLogicalDPIScaleFunc()
}
}

// SaveScreenInfo saves a copy of given screen info to screensAll list if unique
Expand Down
57 changes: 31 additions & 26 deletions system/driver/desktop/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ func (w *Window) Screen() *system.Screen {
if w == nil || w.Glw == nil {
return TheApp.Screens[0]
}
w.Mu.Lock()
defer w.Mu.Unlock()

var sc *system.Screen
mon := w.Glw.GetMonitor() // this returns nil for windowed windows -- i.e., most windows
// that is super useless it seems. only works for fullscreen
Expand All @@ -159,6 +156,8 @@ func (w *Window) Screen() *system.Screen {
// log.Printf("ScreenDebug: desktop.Window.GetScreenOverlap: %v: got screen: %v\n", w.Nm, sc.Name)
// }
setScreen:
w.Mu.Lock()
defer w.Mu.Unlock()
w.ScreenWindow = sc.Name
w.PhysDPI = sc.PhysicalDPI
if w.DevicePixelRatio != sc.DevicePixelRatio {
Expand Down Expand Up @@ -464,21 +463,25 @@ func (w *Window) SetCursorEnabled(enabled, raw bool) {
//////// Window Callbacks

func (w *Window) Moved(gw *glfw.Window, x, y int) {
w.Mu.Lock()
w.Pos = image.Pt(x, y)
w.Mu.Unlock()
// w.app.GetScreens() // this can crash here on win disconnect..
w.updateGeometry() // critical to update size etc here.
w.Event.Window(events.WinMove)
go func() {
w.Mu.Lock()
w.Pos = image.Pt(x, y)
w.Mu.Unlock()
// w.app.GetScreens() // this can crash here on win disconnect..
w.updateGeometry() // critical to update size etc here.
w.Event.Window(events.WinMove)
}()
}

func (w *Window) WinResized(gw *glfw.Window, width, height int) {
// w.app.GetScreens() // this can crash here on win disconnect..
if ScreenDebug {
log.Printf("desktop.Window.WinResized: %v: %v (was: %v)\n", w.Nm, image.Pt(width, height), w.PixelSize)
}
w.updateMaximized()
w.updateGeometry()
go func() {
// w.app.GetScreens() // this can crash here on win disconnect..
if ScreenDebug {
log.Printf("desktop.Window.WinResized: %v: %v (was: %v)\n", w.Nm, image.Pt(width, height), w.PixelSize)
}
w.updateMaximized()
w.updateGeometry()
}()
}

func (w *Window) updateMaximized() {
Expand Down Expand Up @@ -511,18 +514,20 @@ func (w *Window) updateGeometry() {
}

func (w *Window) FbResized(gw *glfw.Window, width, height int) {
if w.Is(system.Fullscreen) {
sc := w.Screen()
width = sc.PixelSize.X
height = sc.PixelSize.Y
}
fbsz := image.Point{width, height}
if w.PixelSize != fbsz {
if ScreenDebug {
log.Printf("desktop.Window.FbResized: %v: %v (was: %v)\n", w.Nm, fbsz, w.PixelSize)
go func() {
if w.Is(system.Fullscreen) {
sc := w.Screen()
width = sc.PixelSize.X
height = sc.PixelSize.Y
}
w.updateGeometry()
}
fbsz := image.Point{width, height}
if w.PixelSize != fbsz {
if ScreenDebug {
log.Printf("desktop.Window.FbResized: %v: %v (was: %v)\n", w.Nm, fbsz, w.PixelSize)
}
w.updateGeometry()
}
}()
}

func (w *Window) OnCloseReq(gw *glfw.Window) {
Expand Down
4 changes: 2 additions & 2 deletions system/driver/ios/ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func updateConfig(width, height, orientation int32) {
TheApp.Scrn.PhysicalDPI = DisplayMetrics.DPI
TheApp.Scrn.LogicalDPI = DisplayMetrics.DPI

if system.InitScreenLogicalDPIFunc != nil {
system.InitScreenLogicalDPIFunc()
if system.UpdateLogicalDPIScaleFunc != nil {
system.UpdateLogicalDPIScaleFunc()
}

physX := 25.4 * float32(width) / DisplayMetrics.DPI
Expand Down
4 changes: 2 additions & 2 deletions system/driver/offscreen/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func (a *App) GetScreens() {
sc.PhysicalDPI = dpi
sc.LogicalDPI = dpi

if system.InitScreenLogicalDPIFunc != nil {
system.InitScreenLogicalDPIFunc()
if system.UpdateLogicalDPIScaleFunc != nil {
system.UpdateLogicalDPIScaleFunc()
}

physX := 25.4 * float32(sc.PixelSize.X) / dpi
Expand Down
4 changes: 2 additions & 2 deletions system/driver/web/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func (a *App) Resize() {
a.Scrn.PhysicalDPI = dpi
a.Scrn.LogicalDPI = dpi

if system.InitScreenLogicalDPIFunc != nil {
system.InitScreenLogicalDPIFunc()
if system.UpdateLogicalDPIScaleFunc != nil {
system.UpdateLogicalDPIScaleFunc()
}

vv := js.Global().Get("visualViewport")
Expand Down
9 changes: 4 additions & 5 deletions system/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ var (
// these can be set from preferences (as in gi/prefs) on a per-screen
// basis.
LogicalDPIScales map[string]float32

// UpdateLogicalDPIScaleFunc is a function that updates the system
// LogicalDPIScale and the per-screen LogicalDPIScales map
UpdateLogicalDPIScaleFunc func()
)

// note: fields obtained from QScreen in Qt
Expand Down Expand Up @@ -217,8 +221,3 @@ func ConstrainWindowGeometry(pos, sz, scSize image.Point) (cpos, csz image.Point
}
return
}

// InitScreenLogicalDPIFunc is a function that can be set to initialize the
// screen LogicalDPI values based on user preferences etc. Called just before
// first window is opened.
var InitScreenLogicalDPIFunc func()
Loading
Loading