recordPref records current state of window as preference
(win *renderWindow)
| 231 | |
| 232 | // recordPref records current state of window as preference |
| 233 | func (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 |
no test coverage detected