Skip to content

Commit

Permalink
start adding fullscreen compositor demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Zubnix committed Aug 16, 2024
1 parent f847b8e commit 5b5cce3
Show file tree
Hide file tree
Showing 7 changed files with 437 additions and 46 deletions.
15 changes: 11 additions & 4 deletions examples/compositor/fullscreen/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
JavaScript port of Weston's demo client "simple-shm".
About
=

Example of a compositor running a single remote GTK4 demo application. The GTK4 demo application is expected to be
provided externally by e.g. `packages/compositor-proxy-cli` in this repo.

Running
=

- `yarn install`
- `yarn start`
- Go to `http://localhost:8080`

The demo-compositor will now be able to launch this demo webapp.

Type `web://localhost:9002` in the compositor URL bar and press enter to launch it
The remote application can be installed as a [Progressive Web App](https://en.wikipedia.org/wiki/Progressive_web_app) by browsers that support it.
When installed as a PWA the application will still be running remotely but will be integrated as a local application.

44 changes: 9 additions & 35 deletions examples/compositor/fullscreen/index.html
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Greenfield Canvas Compositor Demo</title>
<meta charset="UTF-8">
<title>New Application</title>
<link rel="manifest" href="/app.webmanifest">
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}

.container {
display: flex;
gap: 20px;
}

.tile {
width: 200px;
height: 200px;
background-color: #4CAF50;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-size: 20px;
font-family: Arial, sans-serif;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
* { margin:0; padding:0; }
html, body { width:100%; height:100%; }
canvas { height: 100vh; width: 100vw; display:block; }
</style>
</head>
<body>
<div class="container">
<button class="tile" onclick="window.open('app.html?type=remote&url=http%3Alocalhost%3A8081%2Fgtk4-demo', '_blank', 'popup')">gtk4-demo</button>
<button class="tile" onclick="window.open('app.html?type=remote&url=http%3Alocalhost%3A8081%2Fkwrite', '_blank', 'popup')">KWrite</button>
<button class="tile" onclick="window.open('app.html?type=remote&url=http%3Alocalhost%3A8081%2Fxterm', '_blank', 'popup')">xterm</button>
</div>
<script type="module" src="src/index.ts"></script>
<canvas id="output"></canvas>
</body>
</html>
</html>
9 changes: 9 additions & 0 deletions examples/compositor/fullscreen/public/GTK_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions examples/compositor/fullscreen/public/app.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "gtk4-demo",
"display": "standalone",
"start_url": ".",
"icons": [
{
"src": "GTK_logo.svg",
"sizes": "any"
}
]
}
40 changes: 40 additions & 0 deletions examples/compositor/fullscreen/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { createAppLauncher, createCompositorSession, initWasm } from '@gfld/compositor'

const wasmLibs = initWasm()

async function main() {
await wasmLibs

// create new compositor context
const session = await createCompositorSession({ mode: 'fullscreen' })
// notify user of errors
session.userShell.events.notify = (variant: string, message: string) => window.alert(message)

// Get an HTML5 canvas for use as an output for the compositor.
const canvas = document.getElementById('output') as HTMLCanvasElement
// hook up the canvas to our compositor
session.userShell.actions.initScene(() => ({ canvas, id: canvas.id }))
// make compositor global protocol objects available to client
session.globals.register()

const appContext = createAppLauncher(session, 'remote').launch(new URL('http://localhost:8081/gtk4-demo'), (childAppContext) => {
childAppContext.onStateChange = (state) => {
// log child app state
console.log(`Child app is ${state}`)
}
})

// log app state
appContext.onStateChange = (state) => {
console.log(`App state is ${state}`)
}

appContext.onNameChanged = (name) => {
window.document.title = name
}
window.document.title = appContext.name
}

window.onload = () => {
main()
}
7 changes: 0 additions & 7 deletions examples/compositor/fullscreen/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ import { defineConfig } from "vite";

export default defineConfig({
base: "./",
build: {
rollupOptions: {
input: {
app: './app.html'
}
}
},
server: {
host: 'localhost',
port: 8080,
Expand Down
Loading

0 comments on commit 5b5cce3

Please sign in to comment.