sceneFromServerWindows function

Scene sceneFromServerWindows(
  1. Map<String, Object?> reply,
  2. double dpr
)

Flat scene of the focused window in the server's windows reply (the top application window when none has focus).

Implementation

Scene sceneFromServerWindows(Map<String, Object?> reply, double dpr) {
  final windows = [for (final w in (reply['windows'] as List? ?? const [])) (w as Map).cast<String, Object?>()];
  final chosen = windows.where((w) => w['focused'] == true).firstOrNull ??
      windows.where((w) => w['type'] == 'application').firstOrNull;
  final nodes = <NativeNode>[];
  void walk(Map<String, Object?> n) {
    final b = (n['bounds'] as List?)?.cast<num>();
    final text = n['text'] as String? ?? '';
    if (b != null && b.length == 4) {
      nodes.add((
        cls: ((n['class'] as String?) ?? 'View').split('.').last,
        label: text.isNotEmpty ? text : (n['desc'] as String? ?? ''),
        clickable: n['clickable'] == true,
        x1: b[0].toInt(),
        y1: b[1].toInt(),
        x2: b[2].toInt(),
        y2: b[3].toInt(),
      ));
    }
    for (final c in (n['children'] as List? ?? const [])) {
      walk((c as Map).cast<String, Object?>());
    }
  }

  final root = chosen?['root'];
  if (root is Map) walk(root.cast<String, Object?>());
  return nativeScene(nodes, dpr);
}