MCPcopy Create free account
hub / github.com/cogentcore/core / recordPref

Method recordPref

core/windowgeometry.go:233–280  ·  view source on GitHub ↗

recordPref records current state of window as preference

(win *renderWindow)

Source from the content-addressed store, hash-verified

231
232// recordPref records current state of window as preference
233func (ws *windowGeometrySaver) recordPref(win *renderWindow) {
234 if !win.isVisible() {
235 return
236 }
237 wsz := win.SystemWindow.Size()
238 if wsz == (image.Point{}) {
239 if DebugSettings.WinGeomTrace {
240 log.Printf("WindowGeometry: RecordPref: NOT storing null size for win: %v\n", win.name)
241 }
242 return
243 }
244 pos := win.SystemWindow.Position()
245 if pos.X == -32000 || pos.Y == -32000 { // windows badness
246 if DebugSettings.WinGeomTrace {
247 log.Printf("WindowGeometry: RecordPref: NOT storing very negative pos: %v for win: %v\n", pos, win.name)
248 }
249 return
250 }
251 ws.mu.Lock()
252 if ws.settingNoSave {
253 if DebugSettings.WinGeomTrace {
254 log.Printf("WindowGeometry: RecordPref: SettingNoSave so NOT storing for win: %v\n", win.name)
255 }
256 ws.mu.Unlock()
257 return
258 }
259 ws.init()
260
261 winName := ws.windowName(win.title)
262 sc := win.SystemWindow.Screen()
263 wgr := windowGeometry{DPI: win.logicalDPI(), DPR: sc.DevicePixelRatio, Fullscreen: win.SystemWindow.Is(system.Fullscreen)}
264 wgr.setPos(pos)
265 wgr.setSize(wsz)
266
267 if ws.cache[winName] == nil {
268 ws.cache[winName] = make(map[string]windowGeometry)
269 }
270 ws.cache[winName][sc.Name] = wgr
271 if ws.saveTimer == nil {
272 ws.saveTimer = time.AfterFunc(time.Duration(ws.saveDelay), func() {
273 ws.mu.Lock()
274 ws.saveCached()
275 ws.saveTimer = nil
276 ws.mu.Unlock()
277 })
278 }
279 ws.mu.Unlock()
280}
281
282// saveCached saves the cached prefs -- called after timer delay,
283// under the Mu.Lock

Callers 2

resizedMethod · 0.80
handleWindowEventsMethod · 0.80

Calls 14

initMethod · 0.95
windowNameMethod · 0.95
setPosMethod · 0.95
setSizeMethod · 0.95
saveCachedMethod · 0.95
isVisibleMethod · 0.80
logicalDPIMethod · 0.80
SizeMethod · 0.65
PositionMethod · 0.65
LockMethod · 0.65
UnlockMethod · 0.65
ScreenMethod · 0.65

Tested by

no test coverage detected