Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cmake.sourceDirectory": "/Users/mehmetfiskindal/Developer/linux/targets/sailfish-os"
}
14 changes: 13 additions & 1 deletion targets/sailfish-os/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED IMPORTED_TARGET sdl2)
pkg_check_modules(CURL REQUIRED IMPORTED_TARGET libcurl)
pkg_check_modules(MALIIT REQUIRED IMPORTED_TARGET maliit-glib)
include(${CMAKE_CURRENT_SOURCE_DIR}/sources.cmake)

add_executable(${GEA_PACKAGE_NAME} ${GEA_C_SOURCES} ${GEA_CXX_SOURCES})
Expand All @@ -20,14 +21,25 @@ target_compile_options(${GEA_PACKAGE_NAME} PRIVATE
target_compile_definitions(${GEA_PACKAGE_NAME} PRIVATE
GEA_EMBEDDED_HAS_GENERATED_FONTS=1
GEA_EMBEDDED_TTF_RUNTIME_FONTS=1
# The Sailfish keyboard (Maliit, main/sailfish_keyboard.cpp) handles text
# entry; the engine's own on-screen keyboard would open on top of it.
GEA_EMBEDDED_ENABLE_VIRTUAL_KEYBOARD=0
$<$<COMPILE_LANGUAGE:C>:GEA_EMBEDDED_GIF_C_API>
GEA_SAILFISH_APP_ID="${GEA_APP_ID}"
GEA_SAILFISH_APP_TITLE="${GEA_APP_TITLE}"
GEA_SAILFISH_ORGANIZATION_NAME="${GEA_SAILFISH_ORGANIZATION_NAME}"
GEA_SAILFISH_APPLICATION_NAME="${GEA_SAILFISH_APPLICATION_NAME}")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/platform/main/sailfish_main.cpp
PROPERTIES COMPILE_DEFINITIONS GEA_SAILFISH_DEFAULT_DPR=${GEA_SAILFISH_DEFAULT_DPR})
target_link_libraries(${GEA_PACKAGE_NAME} PRIVATE PkgConfig::SDL2 PkgConfig::CURL pthread m rt)
target_link_libraries(${GEA_PACKAGE_NAME} PRIVATE PkgConfig::SDL2 PkgConfig::CURL PkgConfig::MALIIT pthread m rt)
# App-declared link dependencies (gea.sailfish.pkgConfigModules and
# nativeSystemLibraries); the spec lists each module as a BuildRequires.
foreach(GEA_APP_PKG_MODULE IN LISTS GEA_APP_PKG_MODULES)
string(MAKE_C_IDENTIFIER "GEA_APP_PKG_${GEA_APP_PKG_MODULE}" GEA_APP_PKG_PREFIX)
pkg_check_modules(${GEA_APP_PKG_PREFIX} REQUIRED IMPORTED_TARGET ${GEA_APP_PKG_MODULE})
target_link_libraries(${GEA_PACKAGE_NAME} PRIVATE PkgConfig::${GEA_APP_PKG_PREFIX})
endforeach()
target_link_libraries(${GEA_PACKAGE_NAME} PRIVATE ${GEA_APP_SYSTEM_LIBRARIES})
target_link_options(${GEA_PACKAGE_NAME} PRIVATE -Wl,--export-dynamic)

install(TARGETS ${GEA_PACKAGE_NAME} RUNTIME DESTINATION bin)
Expand Down
92 changes: 74 additions & 18 deletions targets/sailfish-os/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ npm install --no-save @geastack/core@"$(node -p "require('../core/packages/core/

Local core edits are still included in the build.

From the Linux repository on Linux:
Build output goes to `<app>/.gea-sailfish/`, never into the installed package;
add that directory to the app's `.gitignore`.

From the app directory on Linux:

```sh
./targets/sailfish-os/build-sailfish-os.sh ../examples/apps/tic-tac-toe --arch i486
./node_modules/@geastack/linux/targets/sailfish-os/build-sailfish-os.sh . --arch aarch64
```

The script finds `sfdk` on `PATH`. Pass `--sfdk /path/to/SailfishOS/bin/sfdk`
Expand All @@ -55,6 +58,23 @@ Set only permissions the app actually needs, such as `Audio` for sound and
`"permissions": ["Audio", "Internet"]`. An empty list does not allow networking;
permissions are not inferred from app source code.

`"sandboxing": false` in `gea.sailfish` writes `Sandboxing=Disabled` to the
`[X-Sailjail]` section, for apps that must run other programs or see the whole
file system, such as a terminal. Harbour does not accept unsandboxed apps.

App-owned native code is listed in `gea.nativeSources` (app-relative `.c`,
`.cc`, `.cpp` or `.cxx` files). They are copied into the project under
`app_native/` with their relative paths and compiled with the app. Link
dependencies go in `gea.sailfish`:

| Key | Meaning |
| --- | --- |
| `nativeIncludeDirectories` | App-relative directories added to the include path |
| `nativeSystemLibraries` | Library names linked with `-l`, such as `util` for `openpty` |
| `pkgConfigModules` | pkg-config modules, such as `maliit-glib`; each one is also a `BuildRequires` |

Paths must stay inside the app directory.

From the Linux repository on Windows:

```powershell
Expand All @@ -64,7 +84,7 @@ From the Linux repository on Windows:
Use `-SdkRoot` when Sailfish SDK is installed outside `C:\SailfishOS`.

The RPM is written to
`targets/sailfish-os/build/<app-id>-<architecture>/project/RPMS/`.
`<app>/.gea-sailfish/build/<app-id>-<architecture>/project/RPMS/`.
Use `-PrepareOnly` in PowerShell for code generation without invoking `sfdk`.
Before submitting a device package to Harbour, run `sfdk check` on its RPM.
The `i486` build is for the emulator; build for the architecture of the target
Expand All @@ -81,21 +101,57 @@ configuration use the `sailfish_` and `GEA_SAILFISH_` prefixes. Storage uses
the organization and application names from the app's Sailjail identity.

Runtime overrides are `GEA_SAILFISH_WIDTH`, `GEA_SAILFISH_HEIGHT`,
`GEA_SAILFISH_SCALE`, `GEA_SAILFISH_DPR`, and `GEA_SAILFISH_STORAGE_DIR`.

Scale and DPR both default to 1: one CSS pixel is one canvas pixel and one SDL
window coordinate unit. The initial canvas is 410x502; resize events update it
to the available window dimensions divided by scale. DPR controls canvas pixels
per CSS pixel, while scale controls presentation magnification. Font generation
uses the same initial 410x502 viewport and the app's DPR; runtime TTF fonts adapt
to the current viewport and DPR after resize. CMake defaults to a Release build.

Set `gea.sailfish.devicePixelRatio` in the app's `package.json` to change its
CSS density (default 1). For example, `"devicePixelRatio": 2` renders one CSS
pixel as two canvas pixels while keeping the SDL window scale at 1. A 720x1527
window then provides a 360x763.5 CSS viewport. The same setting is used for font
generation and the executable's default DPR; `GEA_SAILFISH_DPR` overrides it at
runtime. This is useful for phone layouts designed around a 360 CSS pixel width.
`GEA_SAILFISH_SCALE`, `GEA_SAILFISH_DPR`, `GEA_SAILFISH_HIGHDPI` (`0` creates
the window without `SDL_WINDOW_ALLOW_HIGHDPI`), and `GEA_SAILFISH_STORAGE_DIR`.

Hardware keys and text use the same SDL keyboard producer as the Raspberry Pi
OS target (`rpios_keyboard.h`). Key events carry `key`, `code`, `keyCode` and
the Shift/Control/Alt/Meta flags, and Escape is delivered to the app like any
other key; the app quits on the window close request or SIGTERM. Text from
`SDL_TEXTINPUT` is inserted into the focused input as UTF-8, and Backspace
removes one whole character. F11 toggles fullscreen.

The Sailfish on-screen keyboard (Maliit, through `maliit-glib`) opens while an
input is focused and closes when focus leaves it; `type="password"` inputs ask
for hidden text. Committed text and special keys (Backspace, Enter, Tab,
arrows, Home/End, Delete, Escape) are delivered as SDL events, so they reach the
app exactly like a hardware keyboard. Word prediction and auto-correction are
turned off because the target does not draw pre-edit text. When the keyboard
opens, the compositor shrinks the window and the app receives a resize.

Scale defaults to 1. The canvas
covers the window's drawable in physical pixels divided by scale, at startup and
after every resize, so a Wayland output scale does not stretch a low-resolution
canvas (which made text blocky). The texture is presented with nearest
filtering and integer scaling only, so one canvas pixel is exactly one panel
pixel at scale 1. DPR controls canvas pixels per CSS pixel, while scale controls
presentation magnification. CMake defaults to a Release build.

`gea.sailfish.devicePixelRatio` in the app's `package.json` sets the CSS
density. It defaults to `"auto"`. On ARM builds (`aarch64`, `armv7hl`) auto is
pixel-perfect: the executable takes the largest integer DPR that keeps the
panel's short side at least 360 CSS pixels, so every CSS pixel is a whole NxN
block of panel pixels and edges never fall between pixels. The DPR is derived
from the panel, not the window, so it does not change when the on-screen
keyboard shrinks the window. On the current Sailfish phones this gives:

| Device | Panel | Auto DPR | CSS viewport |
|---|---|---|---|
| Jolla C2 | 720x1600 | 2 | 360x800 |
| Xperia XA2, XA2 Plus, XA2 Ultra | 1080x1920 (XA2 Plus 1080x2160) | 3 | 360x640 (360x720) |
| Xperia 10, 10 Plus, 10 II, 10 III, 10 IV, 10 V | 1080x2520 | 3 | 360x840 |
| Jolla Phone (2026) | 1080x2340 | 3 | 360x780 |

On the i486 emulator, auto is 1 (one CSS pixel per canvas pixel). A number
(0.5 to 8) is used as given on every architecture and multiplied by the Wayland
output scale (physical pixels per window point). `GEA_SAILFISH_DPR` (a number or
`auto`) overrides the setting at runtime; the startup log shows the chosen DPR
and CSS viewport. A non-integer DPR is not pixel-perfect: CSS edges can land
between panel pixels.

Font generation uses the initial 410x502 viewport and the app's DPR; an auto
ARM build generates fonts for DPR 2 and 3. Runtime TTF fonts adapt to the
current viewport and DPR after resize.

Fonts declared with `@font-face` are embedded as TTF files and rasterized at
runtime. Character coverage depends on the core checkout's runtime TTF
Expand Down
3 changes: 2 additions & 1 deletion targets/sailfish-os/build-sailfish-os.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ if ($CoreRepository) { $argsForNode += (Resolve-Path $CoreRepository).Path }
& node @argsForNode
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
if ($PrepareOnly) { exit 0 }
$project = Join-Path $here "build/$((Get-Content (Join-Path $AppDirectory 'package.json') | ConvertFrom-Json).gea.id)-$Architecture/project"
$appRoot = (Resolve-Path $AppDirectory).Path
$project = Join-Path $appRoot ".gea-sailfish/build/$((Get-Content (Join-Path $appRoot 'package.json') | ConvertFrom-Json).gea.id)-$Architecture/project"
$sfdk = Join-Path $SdkRoot 'bin/sfdk.exe'
if (!(Test-Path $sfdk)) { throw "Sailfish SDK missing at $sfdk" }
Push-Location $project
Expand Down
2 changes: 1 addition & 1 deletion targets/sailfish-os/build-sailfish-os.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ if [[ "$SFDK_BIN" == */* ]]; then
fi
command -v "$SFDK_BIN" >/dev/null || { echo "sfdk not found: $SFDK_BIN" >&2; exit 1; }
APP_ID="$(node -e 'const fs=require("node:fs"); const p=JSON.parse(fs.readFileSync(process.argv[1],"utf8")); process.stdout.write(p.gea.id)' "$APP_DIR/package.json")"
PROJECT_DIR="$TARGET_DIR/build/$APP_ID-$ARCH/project"
PROJECT_DIR="$APP_DIR/.gea-sailfish/build/$APP_ID-$ARCH/project"
(cd "$PROJECT_DIR" && "$SFDK_BIN" -c "target=SailfishOS-5.1.0.11-$ARCH" build)
119 changes: 119 additions & 0 deletions targets/sailfish-os/config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Reads and validates an app's package.json for the Sailfish OS target, and
// renders the .desktop entry and RPM spec. No side effects besides reading the
// files the app names, so it can be tested without the SDK or the framework.
import fs from 'node:fs'
import path from 'node:path'

const NATIVE_SOURCE = /\.(c|cc|cpp|cxx)$/
const LIBRARY_NAME = /^[A-Za-z][A-Za-z0-9_.+-]*$/
const PKG_CONFIG_MODULE = /^[A-Za-z0-9][A-Za-z0-9_.+-]*$/

const stringList = (value, name) => {
if (value === undefined) return []
if (!Array.isArray(value) || value.some((item) => typeof item !== 'string' || !item)) throw new Error(`${name} must be an array of nonempty strings`)
return [...new Set(value)]
}

// An app-relative path that stays inside the app after symlinks are resolved.
const appPath = (appDir, value, name, kind) => {
if (path.isAbsolute(value) || value.split(/[\\/]/).includes('..') || /[\x00-\x1f\x7f"$;\\]/.test(value)) throw new Error(`${name}: invalid path ${value}`)
const realApp = fs.realpathSync(appDir)
let real
try {
real = fs.realpathSync(path.join(appDir, value))
} catch {
throw new Error(`${name}: missing ${value}`)
}
const relative = path.relative(realApp, real)
if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) throw new Error(`${name}: ${value} escapes the app directory`)
const stat = fs.statSync(real)
if (kind === 'file' ? !stat.isFile() : !stat.isDirectory()) throw new Error(`${name}: ${value} is not a ${kind === 'file' ? 'regular file' : 'directory'}`)
return { relative: relative.split(path.sep).join('/'), absolute: real }
}

export function readSailfishConfig(appDir, meta) {
const app = meta.gea
if (!app?.id || !/^[a-z0-9][a-z0-9-]*$/.test(app.id)) throw new Error('gea.id must be a lowercase package identifier')
const appName = String(app.name || app.id)
const rpmLicense = String(meta.license || 'MIT')
if (/[\x00-\x1f\x7f%\\";$]/.test(appName)) throw new Error('gea.name must not contain control characters or RPM/CMake syntax')
if (/[\x00-\x1f\x7f%]/.test(rpmLicense)) throw new Error('package license must not contain control characters or RPM macros')
const sailfish = app.sailfish || {}
const organizationName = sailfish.organizationName || 'org.geastack'
const applicationName = sailfish.applicationName || app.id.replaceAll('-', '_')
const permissions = sailfish.permissions || []
const devicePixelRatio = sailfish.devicePixelRatio ?? 'auto'
const sandboxing = sailfish.sandboxing ?? true
if (devicePixelRatio !== 'auto' && (typeof devicePixelRatio !== 'number' || !Number.isFinite(devicePixelRatio) || devicePixelRatio < 0.5 || devicePixelRatio > 8)) throw new Error('gea.sailfish.devicePixelRatio must be "auto" or a number between 0.5 and 8')
if (!/^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)+$/.test(organizationName)) throw new Error('gea.sailfish.organizationName must be a reverse-domain name')
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(applicationName)) throw new Error('gea.sailfish.applicationName must contain only letters, digits, and underscores')
if (!Array.isArray(permissions) || !permissions.every((item) => typeof item === 'string' && /^[A-Za-z]+$/.test(item))) throw new Error('gea.sailfish.permissions must be an array of permission names')
if (typeof sandboxing !== 'boolean') throw new Error('gea.sailfish.sandboxing must be true or false')

const npmVersion = meta.version || '0.1.0'
const versionMatch = typeof npmVersion === 'string' && npmVersion.match(/^(\d+\.\d+\.\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/)
if (!versionMatch) throw new Error('package.json version must be a valid x.y.z version with optional prerelease and build metadata')
const rpmVersion = versionMatch[1] + (versionMatch[2] ? `~${versionMatch[2].replaceAll('-', '.')}` : '')

const nativeSources = stringList(app.nativeSources, 'gea.nativeSources').map((value) => {
if (!NATIVE_SOURCE.test(value)) throw new Error(`gea.nativeSources: unsupported source ${value} (use .c, .cc, .cpp or .cxx)`)
return appPath(appDir, value, 'gea.nativeSources', 'file')
})
const nativeIncludeDirectories = stringList(sailfish.nativeIncludeDirectories, 'gea.sailfish.nativeIncludeDirectories')
.map((value) => appPath(appDir, value, 'gea.sailfish.nativeIncludeDirectories', 'directory'))
const nativeSystemLibraries = stringList(sailfish.nativeSystemLibraries, 'gea.sailfish.nativeSystemLibraries')
for (const name of nativeSystemLibraries) if (!LIBRARY_NAME.test(name)) throw new Error(`gea.sailfish.nativeSystemLibraries: invalid library ${name}`)
const pkgConfigModules = stringList(sailfish.pkgConfigModules, 'gea.sailfish.pkgConfigModules')
for (const name of pkgConfigModules) if (!PKG_CONFIG_MODULE.test(name)) throw new Error(`gea.sailfish.pkgConfigModules: invalid module ${name}`)

return {
id: app.id,
entry: app.entry || 'index.tsx',
icons: app.icons || {},
appName,
rpmLicense,
rpmVersion,
packageName: `harbour-gea-${app.id}`,
organizationName,
applicationName,
permissions: [...new Set(permissions)],
devicePixelRatio,
sandboxing,
nativeSources,
nativeIncludeDirectories,
nativeSystemLibraries,
pkgConfigModules,
}
}

// Integer DPRs an "auto" build is expected to pick on Sailfish phones: 2 on
// 720-pixel-wide panels (Jolla C2) and 3 on 1080-pixel-wide panels (Xperia XA2,
// Xperia 10 through 10 V, Jolla Phone). Build-time fonts are generated for both;
// other sizes fall back to the runtime TTF rasterizer.
const PHONE_DENSITIES = [2, 3]

// The DPR compiled into the executable (0: derive an integer DPR from the
// panel at startup, see sailfish_main.cpp) and the ratios fonts are generated
// for. "auto" is panel-derived on ARM phones; the x86 emulator keeps one CSS
// pixel per canvas pixel.
export function sailfishDensity(config, arch) {
const ratio = config.devicePixelRatio
if (ratio !== 'auto') return { runtime: ratio, fontRatios: [ratio] }
if (arch === 'i486') return { runtime: 1, fontRatios: [1] }
return { runtime: 0, fontRatios: [...PHONE_DENSITIES] }
}

export function desktopEntry(config) {
const sailjail = [
...(config.sandboxing ? [] : ['Sandboxing=Disabled']),
`OrganizationName=${config.organizationName}`,
`ApplicationName=${config.applicationName}`,
`Permissions=${config.permissions.join(';')}`,
]
return `[Desktop Entry]\nType=Application\nName=${config.appName}\nExec=${config.packageName}\nIcon=${config.packageName}\nX-Nemo-Application-Type=generic\n\n[X-Sailjail]\n${sailjail.join('\n')}\n`
}

export function rpmSpec(config) {
const buildRequires = [...new Set(['cmake', 'pkgconfig(sdl2)', 'pkgconfig(libcurl)', 'pkgconfig(maliit-glib)', ...config.pkgConfigModules.map((name) => `pkgconfig(${name})`)])]
return `Name: ${config.packageName}\nVersion: ${config.rpmVersion}\nRelease: 1\nSummary: Gea ${config.appName} for Sailfish OS\nLicense: ${config.rpmLicense}\n${buildRequires.map((item) => `BuildRequires: ${item}\n`).join('')}\n%description\nGea JSX application for Sailfish OS.\n\n%build\n%cmake .\n%make_build\n\n%install\n%make_install\n\n%files\n%{_bindir}/${config.packageName}\n%{_datadir}/applications/${config.packageName}.desktop\n%{_datadir}/icons/hicolor/*/apps/${config.packageName}.png\n`
}
9 changes: 9 additions & 0 deletions targets/sailfish-os/include/sailfish_keyboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
/* Sailfish OS on-screen keyboard (Maliit) client; see main/sailfish_keyboard.cpp. */

void sailfish_keyboard_init();
// Runs pending Maliit D-Bus work; call before reading SDL events each frame.
void sailfish_keyboard_pump();
// Shows the keyboard while an input is focused (-1: none) and hides it after.
void sailfish_keyboard_update(int activeInputId, bool hiddenText);
void sailfish_keyboard_shutdown();
Loading
Loading