Skip to content

Latest commit

 

History

History
324 lines (293 loc) · 20.1 KB

ARCHITECTURE.md

File metadata and controls

324 lines (293 loc) · 20.1 KB

Architecture

How Omalauncher is put together, for anyone working on it.

An Android home-screen launcher that runs Arch Linux ARM under proot and acts as its Wayland compositor. The home screen (widgets, pinned apps, the bar and its app list) is Jetpack Compose; every Linux window opens as its own Android task, so it gets a Recents card and behaves like a separate app.

Linux is optional. Without it the launcher still has Omarchy's themes and wallpapers, Android apps from the bar and the widgets that don't run commands. Everything else is offered as an install from settings › linux and wherever it appears: Linux apps, terminal widgets, coding agents, pacman and Files. Widgets that need Linux (Program.needsLinux: cmd, stream and file sources that aren't optional, Terminal, run/terminal/app actions, requires) show as placeholders in their cells until it's installed. Removing Linux deletes files/arch only.

Launcher data that the guest also uses lives outside the rootfs and is bound into it by proot (storage/LauncherData.kt), so installing or removing Linux never touches it: files/omarchy is ~/.local/share/omarchy and files/widgets is ~/.config/omalauncher/widgets.

Source layout

Paths are under app/src/main/kotlin/dev/omalauncher/ unless they start with a module folder; the OWL language is under owl/src/main/kotlin/dev/omalauncher/widgets/.

  • the package root: the Application, Runtime (the one object that holds the launcher's services and wires them together), and the activities and services the manifest names (but theme/OmarchyWallpaperService and widgets/runtime/MediaListener). Their class names are public (the home-screen choice, pinned shortcuts, am start), so they stay where they are
  • app/src/main/cpp/wlbridge.c: JNI for unix sockets with fd passing, shm mapping, per-surface pixel stores, and compositing them into a window's ANativeWindow
  • app/src/main/cpp/scene3d.c: a 3D scene's work per triangle, a port of the Kotlin in owl's Space3d.kt that gives the same numbers (SceneNativeTest); Scene3d takes it as its SceneKernel and works without one
  • app/src/main/cpp/mesh3d.c: building a mesh (smooth corner normals, the Bsp tree, reading OBJ files), in the same library; owl's MeshKernels holds it, set in App, and the Kotlin it ports runs where it isn't set (MeshNativeTest). The native tests build the C for the machine they run on (HostNative) and are skipped without a compiler
  • app/src/main/cpp/pixels.c: frost's blur and icon masks, with the Kotlin kept as the fallback (PixelsNativeTest)
  • app/src/main/cpp/procstat.c: ProcShim's count of CPU time, with the Kotlin kept as the fallback (ProcStatNativeTest)
  • app/src/main/cpp/pty.c and vt.c: the built-in terminal's pseudo-terminal and its screen, libghostty-vt (scripts/fetch-ghostty-vt.sh); without that library noterminal.c stands in and there is no built-in terminal
  • app/src/main/cpp/aap.c: the classic L2CAP socket android.airpods talks AAP on
  • terminal/: the built-in terminal's session, pty and screen (TerminalSession, PtyNative, Vt) and its keys; ui/terminal/ draws it (NativeTerminalView, the glyph atlas, box drawing)
  • wayland/: the Wayland server in Kotlin (wl_compositor, wl_shm, wl_subcompositor, wl_seat, wl_output, wl_data_device_manager, xdg_wm_base, xdg-decoration, KDE server decoration, and text-input-v3 for where a client's text cursor is) and WindowRenderer, which draws one window into its activity's SurfaceView (or, for a widget's Terminal, into a TextureView in the tile)
  • linux/: proot, the rootfs setup and its update steps, pacman, coding agents, and the bridges to Android (audio, URLs, /proc)
  • ui/: Compose. The package itself holds what every screen shares (the palette, panels and dialogs, icons, key focus, the keyboard); home/ is the home screen, the bar and its app list, folders and tiles; settings/ the settings pages and first-run setup; files/ Files and the editor; store/ the widget store and sharing; voice/ the Voice screen
  • voice/: what Voice runs on: its session with an agent, the agents' links, speech to text (the phone's recognizer or Parakeet) and text to speech
  • apps/: the phone's Android apps, their shortcuts, usage and icon packs
  • net/: HTTPS with pinning, WebSocket, the local network
  • storage/: the launcher's own data directories (LauncherData) and the phone's folders and shared storage that Files and Linux reach
  • system/: small Android helpers (notifications, broadcasts, permissions, URLs and sharing, the app language)
  • widgets/: the widget engine (render/ draws nodes, runtime/ holds a running widget and its android.* sources); the language itself, its compiler (lang/) and the store's checks (market/) are in the owl module. A widget's state and sources live in its WidgetInstance, which runs while its page or a neighbour is on screen, but the pager composes only the current page: a node drawn in Kotlin loses its remember state when its page is swiped away, and keeps anything lasting in the instance
  • theme/: Omarchy themes, applied to the launcher and the guest
  • upgrade/: how installs follow app updates (see below)

Rendering

A client's commit copies only the damaged rectangles of its shm buffer into the surface's pixel store, outside the server lock, and hands the buffer back right away. Each window's WindowRenderer runs on its own thread: at vsync it snapshots the surface tree, redraws only the dirty region of the SurfaceView (everything, if a surface moved or appeared), posts, and then sends the frame callbacks. The SurfaceView has a few buffers that take turns, and the whole window is locked each time: locking only the dirty region makes Android copy the rest of the frame from the buffer on screen, which cost more than the drawing. BufferDamage keeps what each buffer missed while the others were drawn, and that is what gets repainted. Hidden windows get no frame callbacks, so their clients stop drawing.

Browser tiles

A widget's Browser node draws an Android System WebView inside the tile (ui/BrowserView.kt), not a client of the Wayland compositor. Nothing runs in the guest, so a file with a Browser needs no Linux, and its frames go into the tile the way any other view's do. What the page may reach is decided there and nowhere else: https only, no file or content access, script and DOM storage only when the node asks for js, and no JavaScript bridge. Every Browser in the app shares one WebView profile, so cookies and sign-ins are shared between tiles. Home's input owner, TerminalTiles, takes a Browser tile in as it takes a terminal: the page's view takes no touch until the tile is tapped (TileWebView.dispatchTouchEvent says so), so a swipe still turns the page and a long press still lifts the tile. The tap that gives it the tile, a tap outside it, a page turn and Back are the same code path a terminal's and a widget's text field are, and the page is what the home screen lifts above the keyboard. A field in the page keeps the WebView's own IME connection.

GPU acceleration

Opt-in, in settings › linux. The device node picks the driver. Mali (v10+: Pixel 7 and newer, recent MediaTek) uses the pinned PanVK-kbase driver on /dev/mali0, from zenithblue-oss/panvk-kbase-android. Adreno 6xx and newer use the pinned Turnip KGSL driver on /dev/kgsl-3d0, the Arch vulkan-freedreno package from lfdevs/mesa-for-android-container (turnip-26.3.0-devel-20260824). The model comes from /sys/class/kgsl/kgsl-3d0/gpu_model. An older Adreno, or a model that cannot be read, is not offered. Arch's own Mesa talks to DRM, so it would not see /dev/kgsl-3d0. Both blobs are checked against their sha256 and installed under /usr/local, and both ICD manifests live under /usr/local/share/vulkan/icd.d, which pacman does not own. A download that fails deletes its temp files on the way out. Turning one on also installs Mesa and the Vulkan loader with pacman. OpenGL is zink. On both Adreno and Mali the guest uses a patched Mesa 26.2.4 (scripts/mesa/0001-egl-wayland-keep-zink-on-shm.patch, and 0002-zink-acquire-swapchain-resolve-before-use.patch for zink acquiring a swapchain image it hasn't): the compositor only offers wl_shm, stock Mesa clears zink after the Wayland DRM path fails, and the shm buffer stays black while frames still count. MESA_LOADER_DRIVER_OVERRIDE=zink keeps zink set so kopper presents through Vulkan WSI. The patched libraries live under /usr/local/omalauncher-mesa, off the default linker path. Frames still arrive as wl_shm buffers (MESA_VK_WSI_DEBUG=sw), so the compositor is the same either way.

linux/Gpu.kt only switches guest apps to the GPU (Proot.graphicsEnv) after a check passes (vulkaninfo finds PanVK or Turnip, eglinfo gets zink), and checks again after every system update; if that fails, the ICD manifest is removed and apps render in software (llvmpipe). Software mode sets LIBGL_ALWAYS_SOFTWARE=1, and VK_ICD_FILENAMES and VK_DRIVER_FILES to lavapipe's manifest alone (LAVAPIPE_ICD), so the loader does not scan the default ICD directories and a GPU driver left behind can't be picked, while Vulkan apps still run on the CPU. The loader prefers VK_DRIVER_FILES, so turning the GPU on sets both names to the real manifest. The check unsets the software values before it exports those. Settings offers a retry. One app can opt out with GALLIUM_DRIVER=llvmpipe app. Terminal apps (foot) draw on the CPU and don't change.

Updates

The app writes into the rootfs and keeps state of its own, so an update must reach existing installs without breaking them. There are four mechanisms:

  • Rootfs steps (linux/Bootstrap.kt): an ordered list of idempotent steps (/etc configuration, packages, the keymap, cliamp). Each one's id is recorded once it succeeds (files/rootfs-steps.json). To change what a step does on existing installs, give it a new id, for example packages-1 → packages-2 after changing the package list. A fresh install runs every step in the background, with progress in settings › linux and the notification. After an update, new offline steps before the first pending network step run before Linux starts, and steps that need the network run in the background. Their progress and failures show in settings, and they retry on the next start.
  • Launcher-provided files (upgrade/ManagedFiles.kt): shims, desktop entries, default configs, default widgets, the style defaults and the widget docs. Every file written is recorded with its hash: the launcher's own (default widgets) in files/launcher-managed.json, the guest's in files/managed.json, which only syncs while Linux is installed and is forgotten with it.
    • Owned files (plumbing) always match the APK.
    • Seeded files are defaults the user may edit. They are updated only while unchanged since we wrote them, and never brought back once deleted.
    • Files dropped from the APK are deleted if they're unchanged.
    • The sync runs on every start and only hashes files when nothing changed.
  • Saved data (upgrade/Versioned.kt): preferences and JSON files are stored as {"v": N, "data": …}. A format change bumps N and adds a migration step to the reader. Entries are parsed one at a time, so a bad one is skipped instead of losing the rest.
  • Widgets: Compiler.LEVEL in the owl module is the language version. Widgets that need a newer one declare meta { owl: N }, and store entries carry it. An older launcher then shows "needs a newer launcher" instead of failing. Bump the level with every addition a widget could depend on. The store's index.json format number only changes for incompatible changes.

System updates (linux/SystemUpdates.kt) are the user's own: pacman packages and the tools mise installed (the coding agents). The launcher checks at most every 6 hours while it's on screen: pacman against a private copy of the databases in /tmp, so the real ones and pacman's lock are untouched, plus mise outdated. When updates are pending, a dot shows on the app list's settings gear. "update all" in settings runs pacman -Syyu and then mise upgrade as one job. Nothing updates automatically.

The launcher itself updates through whatever installed it. The play build flavor asks Google Play when settings opens (LauncherUpdates.kt in app/src/play) and lists a newer version in the same updates box; its "update" opens Play's own update screen. The foss flavor (GitHub releases, F-Droid) has a twin of that class without Play's closed-source library: it asks GitHub's releases API instead (at most hourly) and "update" opens the release page. Installs made by an F-Droid client never ask; F-Droid updates them.

Pinned versions: ThemeStore.OMARCHY_REF (the Omarchy commit) with ThemeStore.BACKGROUNDS_REF (the omarchy-themes-backgrounds commit, where the themes' backgrounds live since Omarchy 4.6), and CLIAMP_VERSION in Bootstrap.kt. Changing either of the first two makes every install download the new themes on its next start (ThemeStore.ensureRelease, with or without Linux); rerun scripts/fetch-theme-colors.sh with it, since first run fetches only the picked theme's colors and first background by the names that script bundles, and the download fetches the files it lists in assets/omarchy-files.txt one by one (about 80 MB, where the repo's tarball is 180), keeping what arrived across interrupted attempts. Changing CLIAMP_VERSION updates Linux installs through the steps above.

Guest processes die with the app, so the Wayland protocol, the socket and the guest environment carry no state across an update. A guest command's leftover children die when it exits (--kill-on-exit), except an app's, whose command may only start it (Proot.process, Runtime.launchApp).

Settings › Linux can stop an installed Linux (Runtime.stopLinux): every guest process is killed, the foreground service goes, and Proot.process refuses to start another until it's started again. The linux_stopped preference keeps it stopped across restarts; meanwhile the Wayland server and the bridges stay up, and whatever needs Linux opens its settings.

Speech

voice/Speech.kt turns speech into text for Voice, the prompt bar and widgets' dictation. It listens with Parakeet (Parakeet.kt) when the user has downloaded it in the voice settings and the language is one of its 25; otherwise with the phone's recognizer: Google's on-device one first, then the default RecognitionService, then a "speak now" screen. Parakeet is NVIDIA's Parakeet TDT 0.6B v3 run by sherpa-onnx on the CPU: the launcher records the microphone itself, Silero VAD splits phrases and each is decoded whole, with the unfinished phrase decoded again for the live text. ParakeetModel.kt downloads its 670 MB (resumable, SHA-256 checked) into noBackupFilesDir. sherpa-onnx isn't on Maven: scripts/fetch-sherpa.sh builds its AAR from source into the gitignored app/libs, linked against onnxruntime's Android release. The model loads on a tap with the microphone already open, and stays loaded while Voice is in sight.

Two builds

The app has two build flavors. foss (GitHub releases, F-Droid, the default) may do what Google Play doesn't allow: it asks for permissions Play restricts, like the call log. play is what goes on the Play Store. Apart from the updater (see Updates), both builds run the same code:

  • The manifest decides. A permission only the foss build has goes in app/src/foss/AndroidManifest.xml, which Gradle merges over the main one. Code checks context.declares(permission) (system/Permissions.kt) and does without it when it isn't declared. Code never checks the flavor (BuildConfig.FLAVOR is only for announcements aimed at one build).
  • Play's permissions are listed. app/play-permissions.txt lists every permission the play build asks for, libraries' included. checkPlay<Variant>Permissions compares it with the merged manifest and fails assemble, bundle and lint of a play variant when they differ, so a restricted permission can't reach Play by mistake. A change to that file is a change to the Play listing's permissions.
  • Widgets are the same in both. Widgets move between the builds through the store, so OWL and its level don't change between them. What the play build can't do shows up as data that isn't there (android.calls' log is false), the way a permission the user refused does. The widget docs say which fields only the foss build fills.
  • Settings follow the manifest. The permissions screen shows a row only for a permission the build declares.

A flavor-specific class (app/src/foss and app/src/play) is only for code the other build can't ship, like Play's closed-source update library.

Where to change what

Each recipe lists what a complete change touches. Tests go next to the code they cover, in owl/src/test or app/src/test.

  • A coding agent: an Agent entry in linux/Agents.kt (with an OwnInstaller when mise has no package for it, like Hermes); its description as linux_agent_<id> in every strings_linux.xml; an SVG in art/icons/, turned into PNGs by scripts/make-icons.sh; an activity-alias in AndroidManifest.xml so its window gets its own icon and label; a case in AgentsTest. Voice talks to it only with an entry in voice/AgentLink.kt.
  • OWL syntax, a node or a builtin: the compiler in lang/ (Schema.kt for what's allowed where, plus SINCE with the level, Compiler.kt, Builtins.kt); drawing in widgets/render/; state in widgets/runtime/WidgetInstance.kt; the page in assets/widgets/docs/ and the line in docs/versions.md; LangTest. See AGENTS.md for when to bump Compiler.LEVEL.
  • An android.* source for widgets: a file in widgets/runtime/, wired in WidgetServices.kt and WidgetInstance.kt; its name in the compiler as above; assets/widgets/docs/android.md. If it reads something private, add a warning to market/Review.kt so store reviewers check the widget, and update the privacy policy (store/omalauncher.txt). A new Android permission is asked through ui/AskPermission.kt and listed on the permissions screen (ui/settings/PermissionsScreen.kt). It goes in app/play-permissions.txt too, or, if Play restricts it, in app/src/foss/AndroidManifest.xml only (see Two builds).
  • A stock widget (assets/widgets/*.owl): these are Seeded files, so an edit reaches every install that hasn't changed its copy. Raise the version in its meta { } and keep its strings { } sets in every app language.
  • An omalauncher command (the guest's way to the phone): the script assets/omalauncher.sh (its usage text and the argument check in its last case), the answer in linux/PhoneBridge.kt (the when (args[0]) and COMMANDS, which omalauncher version lists), the paragraph about it in the guest's AGENTS.md (WidgetEngine.kt) and the README. OmalauncherScriptTest.commandsAgree fails until the script, its usage and PhoneBridge list the same commands. Errors go back as usage:, denied: or error: answers, which the script turns into exit codes 2, 3 and 1; keep those meanings, since scripts depend on them. Commands never ask for permissions.
  • UI text: res/values/strings_<area>.xml and the same key in each values-* folder.
  • A message to users (a contest, news): no app change. Edit announcements.json in the omarchy-widgets repo, published next to the store's catalog; settings shows it once in a dialog (net/Announcements.kt, ui/home/AnnouncementDialog.kt). Old launchers read new files, so only add fields; a message that needs a newer launcher sets minVersionCode. Times need their Z. A debug build reads files/announcements.json instead.
  • What Linux gets set up with: a rootfs step in linux/Bootstrap.kt (a changed step needs a new id), or a file the launcher writes, listed in a managed() list (like the one in linux/Agents.kt, collected in Runtime.kt), synced by upgrade/ManagedFiles.kt. See "Updates" above.
  • A saved format (preferences, JSON in files/): it is stored through upgrade/Versioned.kt: bump its version and add a migration; never drop the old reader.