Skip to content

Commit

Permalink
make floating & fullscreen mode configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Zubnix committed Aug 14, 2024
1 parent 14efb71 commit cc64118
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/compositor-shell/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function main() {
await wasmLibs

// create new compositor context
const session = await createCompositorSession()
const session = await createCompositorSession({ mode: 'floating' })
const remoteAppLauncher = createAppLauncher(session, 'remote')
const webAppLauncher = createAppLauncher(session, 'web')

Expand Down
2 changes: 1 addition & 1 deletion packages/compositor-shell/src/AppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function AppLaunchInput(props: AppInputProps) {
onKeyPress={onKeyPress}
placeholder="Type a web: or rem:// URL"
name="remote"
onfocusin={selectAllOnFocus}
onFocusIn={selectAllOnFocus}
/>
</div>
)
Expand Down
23 changes: 10 additions & 13 deletions packages/compositor/src/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@

import { Display } from '@gfld/compositor-protocol'
import Globals from './Globals'
import { ButtonCode, CompositorSession } from './index'
import { ButtonCode, CompositorSession, SessionConfig } from './index'
import { FrameDecoder } from './remote/buffer-decoder'
import { createWasmFrameDecoder } from './remote/wasm-buffer-decoder'
import {
hardwareDecoderConfig,
softwareDecoderConfig,
webCodecFrameDecoderFactory,
} from './remote/webcodec-buffer-decoder'
import { softwareDecoderConfig, webCodecFrameDecoderFactory } from './remote/webcodec-buffer-decoder'
import Renderer from './render/Renderer'
import { createUserShellApi, UserShellApi } from './UserShellApi'
import { InputQueue } from './InputQueue'
import { KeyboardModifier } from './Seat'
import { s } from '@gfld/common/dist'

export interface LogFn {
/* tslint:disable:no-unnecessary-generics */
Expand Down Expand Up @@ -119,7 +116,7 @@ class Session implements CompositorSession {

private constructor(
public readonly display: Display,
public readonly compositorSessionId: string,
public readonly config: Required<SessionConfig>,
public readonly logger: GreenfieldLogger,
frameDecoderFactory: FrameDecoderFactory,
) {
Expand All @@ -131,7 +128,7 @@ class Session implements CompositorSession {
}

static async create(
sessionId?: string,
sessionConfig: SessionConfig,
logger: GreenfieldLogger = {
error: console.error,
warn: console.warn,
Expand All @@ -145,8 +142,8 @@ class Session implements CompositorSession {
},
): Promise<Session> {
const display = new Display()
const compositorSessionId =
sessionId ??
const id =
sessionConfig.id ??
((): string => {
const randomBytes = new Uint8Array(8)
crypto.getRandomValues(randomBytes)
Expand All @@ -163,11 +160,11 @@ class Session implements CompositorSession {
decoderFactory = createWasmFrameDecoder
}

const session = new Session(display, compositorSessionId, logger, decoderFactory)
const session = new Session(display, { ...sessionConfig, id }, logger, decoderFactory)
session.globals.seat.buttonBindings.push({
modifiers: 0,
button: ButtonCode.MAIN,
handler: (pointer, event) => {
handler: (pointer, _event) => {
if (pointer.grab !== pointer.defaultGrab) {
return
}
Expand All @@ -181,7 +178,7 @@ class Session implements CompositorSession {
session.globals.seat.buttonBindings.push({
modifiers: KeyboardModifier.NONE,
button: ButtonCode.SECONDARY,
handler: (pointer, event) => {
handler: (pointer, _event) => {
if (pointer.grab !== pointer.defaultGrab) {
return
}
Expand Down
11 changes: 8 additions & 3 deletions packages/compositor/src/desktop/Desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { RectWithInfo } from '../math/Rect'
import { Size } from '../math/Size'
import SurfaceRole from '../SurfaceRole'
import { AlwaysFullscreenDesktopSurface } from './AlwaysFullScreenDesktopSurface'
import { FloatingDesktopSurface } from './FloatingDesktopSurface'

export interface DesktopSurfaceRole extends SurfaceRole {
requestClose(): void
Expand Down Expand Up @@ -55,7 +56,11 @@ export interface DesktopSurface {
}

export function createDesktopSurface(surface: Surface, desktopSurfaceRole: DesktopSurfaceRole): DesktopSurface {
// TODO from session config
// return new FloatingDesktopSurface(surface, desktopSurfaceRole)
return new AlwaysFullscreenDesktopSurface(surface, desktopSurfaceRole)
switch (surface.session.config.mode) {
case 'fullscreen':
return new AlwaysFullscreenDesktopSurface(surface, desktopSurfaceRole)
case 'floating':
default:
return new FloatingDesktopSurface(surface, desktopSurfaceRole)
}
}
14 changes: 11 additions & 3 deletions packages/compositor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ export * from './KeyEvent'
export type { nrmlvo }
export type { GreenfieldLogger }

export function createCompositorSession(sessionId?: string, logger?: GreenfieldLogger): Promise<CompositorSession> {
return Session.create(sessionId, logger)
export function createCompositorSession(
sessionConfig: SessionConfig,
logger?: GreenfieldLogger,
): Promise<CompositorSession> {
return Session.create(sessionConfig, logger)
}

export interface CompositorPointer {
Expand All @@ -51,7 +54,7 @@ export interface CompositorSeat {
export interface CompositorSession {
userShell: UserShellApi
globals: CompositorGlobals
compositorSessionId: string
config: SessionConfig
}

export interface CompositorGlobals {
Expand Down Expand Up @@ -107,3 +110,8 @@ export function createAppLauncher(session: CompositorSession, type: 'web' | 'rem
throw new Error(`Connector type must be 'remote' or 'web'.`)
}
}

export interface SessionConfig {
id?: string
mode: 'floating' | 'fullscreen'
}
4 changes: 2 additions & 2 deletions packages/compositor/src/remote/RemoteAppLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class RemoteAppLauncher implements AppLauncher {
launch(appURL: URL, onChildAppContext: (childAppContext: AppContext) => void): AppContext {
const remoteAppContext = new RemoteAppContext(this.session, onChildAppContext)
const headers: HeadersInit = {
'x-compositor-session-id': this.session.compositorSessionId,
'x-compositor-session-id': this.session.config.id,
}

const user = appURL.username
Expand Down Expand Up @@ -331,7 +331,7 @@ class RemoteAppContext implements AppContext {
throw new Error(`BUG. Unknown channel description: ${JSON.stringify(desc)}`)
}
this.clientConnections.push(channel)
this.onChannel(channel, this.session.compositorSessionId, proxySessionProps)
this.onChannel(channel, this.session.config.id, proxySessionProps)
break
}
case SignalingMessageType.DISCONNECT_CHANNEL: {
Expand Down

0 comments on commit cc64118

Please sign in to comment.