Skip to content
Merged
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
4 changes: 2 additions & 2 deletions VirtualDriverControl/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion VirtualDriverControl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "virtual-driver-control",
"version": "2.0.0",
"version": "2.0.1",
"description": "Modern control panel for the Virtual Display Driver (MttVDD)",
"main": "./out/main/index.js",
"author": "Virtual Driver Control",
Expand Down
35 changes: 33 additions & 2 deletions VirtualDriverControl/src/main/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BrowserWindow, ipcMain, nativeTheme, shell } from 'electron'
import { BrowserWindow, dialog, ipcMain, nativeTheme, shell } from 'electron'
import { MAX_STATIC_DESKTOP_REENCODE_COUNT } from '@shared/types'
import type { AppPreferences, ManagedDriverId, PipeToggleCommand, VddSettings } from '@shared/types'
import type { AudioService } from './services/audio-service'
import type { DisplayService } from './services/display-service'
Expand All @@ -20,7 +21,7 @@ const TOGGLE_COMMANDS: ReadonlySet<string> = new Set([
'LOG_DEBUG'
])

const QUERY_COMMANDS: ReadonlySet<string> = new Set(['D3DDEVICEGPU', 'IDDCXVERSION', 'GETASSIGNEDGPU', 'GETALLGPUS', 'GETSETTINGS', 'PING'])
const QUERY_COMMANDS: ReadonlySet<string> = new Set(['D3DDEVICEGPU', 'IDDCXVERSION', 'GETASSIGNEDGPU', 'GETALLGPUS', 'GETSETTINGS', 'PING', 'GETIDDCXFEATURES'])

/** Raw console commands: known verbs only, conservative charset for arguments. */
const RAW_COMMAND_PATTERN = /^[A-Za-z0-9_]+(?: [A-Za-z0-9_." -]{1,100})?$/
Expand Down Expand Up @@ -76,6 +77,11 @@ export function registerIpc(services: IpcServices, getWindow: () => BrowserWindo
})

ipcMain.handle('pipe:get-driver-settings', () => pipe.getDriverSettings())
ipcMain.handle('pipe:get-iddcx-features', () => pipe.getIddCxFeatures())
ipcMain.handle('pipe:set-reencode-count', (_e, count: unknown) => {
assertReencodeCount(count)
return pipe.setReencodeCount(count)
})

// --- vdd_settings.xml -------------------------------------------------------
ipcMain.handle('settings:load', () => settings.load())
Expand Down Expand Up @@ -104,6 +110,17 @@ export function registerIpc(services: IpcServices, getWindow: () => BrowserWindo
return settings.saveMonitorProfile(xml, edidBytes)
})

ipcMain.handle('settings:import-display-id', async () => {
const options: Electron.OpenDialogOptions = {
title: 'Import a standalone DisplayID descriptor',
filters: [{ name: 'DisplayID binary', extensions: ['bin'] }],
properties: ['openFile']
}
const window = getWindow()
const selection = await (window ? dialog.showOpenDialog(window, options) : dialog.showOpenDialog(options))
return selection.canceled || !selection.filePaths[0] ? null : settings.importDisplayId(selection.filePaths[0])
})

// --- Driver / system --------------------------------------------------------
ipcMain.handle('driver:status', (_e, force: unknown) => driver.status(force === true))
ipcMain.handle('driver:gpus', () => driver.gpus())
Expand Down Expand Up @@ -217,6 +234,12 @@ export function registerIpc(services: IpcServices, getWindow: () => BrowserWindo
ipcMain.on('window:close', () => getWindow()?.close())
}

function assertReencodeCount(count: unknown): asserts count is number {
if (typeof count !== 'number' || !Number.isInteger(count) || count < 0 || count > MAX_STATIC_DESKTOP_REENCODE_COUNT) {
throw new Error(`Reencode count must be an integer between 0 and ${MAX_STATIC_DESKTOP_REENCODE_COUNT}.`)
}
}

function assertSettingsShape(value: unknown): asserts value is VddSettings {
if (typeof value !== 'object' || value === null) throw new Error('Settings payload must be an object')
const v = value as Record<string, unknown>
Expand All @@ -229,6 +252,7 @@ function assertSettingsShape(value: unknown): asserts value is VddSettings {
'colour',
'cursor',
'edid',
'iddCx',
'edidIntegration',
'hdrAdvanced',
'autoResolutions',
Expand All @@ -237,4 +261,11 @@ function assertSettingsShape(value: unknown): asserts value is VddSettings {
if (!(key in v)) throw new Error(`Settings payload missing section: ${key}`)
}
if (!Array.isArray(v.resolutions)) throw new Error('resolutions must be an array')
const iddCx = v.iddCx as Partial<VddSettings['iddCx']> | null
const edid = v.edid as Partial<VddSettings['edid']> | null
if (typeof iddCx?.d3d12SwapChain !== 'boolean' || typeof iddCx.virtualI2c !== 'boolean' ||
typeof edid?.customDisplayId !== 'boolean') {
throw new Error('Invalid IddCx feature settings')
}
assertReencodeCount(iddCx.staticDesktopReencodeFrameCount)
}
33 changes: 30 additions & 3 deletions VirtualDriverControl/src/main/services/pipe-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createConnection, Socket } from 'net'
import { join } from 'path'
import { promisify } from 'util'
import { app } from 'electron'
import type { DriverLiveSettings, PipeResult, PipeToggleCommand } from '@shared/types'
import type { DriverIddCxFeatures, DriverLiveSettings, PipeResult, PipeToggleCommand } from '@shared/types'

const execFileAsync = promisify(execFile)

Expand All @@ -18,13 +18,15 @@ const PIPE_PATH = '\\\\.\\pipe\\MTTVirtualDisplayPipe'
* Only a client with an overlapped read already pending in the kernel receives
* the data - Node's net stack reads too late by design, .NET ReadAsync works.
*/
const RESPONSE_COMMANDS = new Set(['GETSETTINGS', 'GETALLGPUS', 'GETASSIGNEDGPU', 'IDDCXVERSION'])
const RESPONSE_COMMANDS = new Set([
'GETSETTINGS', 'GETALLGPUS', 'GETASSIGNEDGPU', 'IDDCXVERSION', 'GETIDDCXFEATURES', 'SETREENCODECOUNT'
])

/** Round-trip helper: arms an overlapped read before writing the command. */
const HELPER_PS1 = `param([Parameter(Mandatory=$true)][string]$CommandB64, [int]$TimeoutMs = 10000)
$ErrorActionPreference = 'Stop'
$cmd = [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($CommandB64))
$pipe = New-Object System.IO.Pipes.NamedPipeClientStream('.', 'MTTVirtualDisplayPipe', [System.IO.Pipes.PipeDirection]::InOut, [System.IO.Pipes.PipeOptions]::Asynchronous)
$pipe = New-Object System.IO.Pipes.NamedPipeClientStream('.', 'MTTVirtualDisplayPipe', [System.IO.Pipes.PipeDirection]::InOut, [System.IO.Pipes.PipeOptions]::Asynchronous, [System.Security.Principal.TokenImpersonationLevel]::Identification)
try {
try { $pipe.Connect(4000) } catch { exit 3 }
$buf = New-Object byte[] 65536
Expand Down Expand Up @@ -135,6 +137,31 @@ export class PipeClient extends EventEmitter {
return { debug: match[1].toLowerCase() === 'true', log: match[2].toLowerCase() === 'true' }
}

async getIddCxFeatures(): Promise<DriverIddCxFeatures | null> {
const result = await this.send('GETIDDCXFEATURES', { quiet: true })
const reply = result.response.match(/\bIDDCX_FEATURES (\d+)(?: I2C ([01]))?\b/)
if (!result.ok || !reply) return null
const features = Number(reply[1])
if (!Number.isInteger(features) || features > 0xffffffff) return null
return {
d3d12: (features & 1) !== 0,
displayId: (features & 2) !== 0,
staticDesktopReencode: (features & 4) !== 0,
atomicI2c: reply[2] === undefined ? null : reply[2] === '1'
}
}

async setReencodeCount(count: number): Promise<PipeResult> {
const result = await this.send(`SETREENCODECOUNT ${count}`)
if (!result.ok || result.response.includes('QUEUED REENCODECOUNT')) return result
const error = result.response.includes('REENCODECOUNT_ACCESS_DENIED')
? 'Run Virtual Driver Control as administrator to apply a live count.'
: result.response.includes('IDDCX_REENCODE_UNAVAILABLE')
? 'The running driver or Windows runtime does not support live reencode changes.'
: 'The driver did not acknowledge the reencode request.'
return { ...result, ok: false, error }
}

private isReloadCommand(command: string): boolean {
const head = command.split(' ')[0].toUpperCase()
return RELOAD_COMMANDS.has(head)
Expand Down
66 changes: 65 additions & 1 deletion VirtualDriverControl/src/main/services/settings-service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { XMLParser } from 'fast-xml-parser'
import { randomUUID } from 'crypto'
import { promises as fs } from 'fs'
import { existsSync, mkdirSync } from 'fs'
import { join } from 'path'
import { DEFAULT_VDD_SETTINGS } from '@shared/defaults'
import type { BackupInfo, ResolutionEntry, SaveResult, SettingsLoadResult, VddSettings } from '@shared/types'
import {
MAX_STATIC_DESKTOP_REENCODE_COUNT,
type BackupInfo,
type ResolutionEntry,
type SaveResult,
type SettingsLoadResult,
type VddSettings
} from '@shared/types'

const MAX_BACKUPS = 20
const MAX_DISPLAY_ID_BYTES = 64 * 1024
const EDID_HEADER = Buffer.from([0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00])

type Raw = Record<string, unknown>

Expand Down Expand Up @@ -157,6 +167,44 @@ export class SettingsService {
}
}

async importDisplayId(source: string): Promise<SaveResult> {
const folder = this.getBaseDir()
const target = join(folder, 'user_displayid.bin')
const temp = join(folder, `user_displayid.${randomUUID()}.tmp`)
try {
const file = await fs.open(source, 'r')
const buffer = Buffer.alloc(MAX_DISPLAY_ID_BYTES + 1)
let bytesRead: number
try {
const stat = await file.stat()
if (!stat.isFile() || stat.size < 5 || stat.size > MAX_DISPLAY_ID_BYTES) {
return { ok: false, error: 'Select a standalone DisplayID descriptor between 5 bytes and 64 KiB.' }
}
({ bytesRead } = await file.read(buffer, 0, buffer.length, 0))
if (bytesRead !== stat.size) return { ok: false, error: 'The descriptor changed or could not be read completely.' }
} finally {
await file.close()
}
if (bytesRead >= EDID_HEADER.length && buffer.subarray(0, EDID_HEADER.length).equals(EDID_HEADER)) {
return { ok: false, error: 'This file contains an EDID header. Select a standalone DisplayID descriptor.' }
}
await fs.mkdir(folder, { recursive: true })
await fs.writeFile(temp, buffer.subarray(0, bytesRead), { flag: 'wx' })
let backupCreated: string | undefined
if (existsSync(target)) {
await fs.mkdir(this.backupsDir, { recursive: true })
backupCreated = 'user_displayid.previous.bin'
await fs.copyFile(target, join(this.backupsDir, backupCreated))
}
await fs.rename(temp, target)
return { ok: true, backupCreated }
} catch (error) {
return { ok: false, error: error instanceof Error ? error.message : String(error) }
} finally {
await fs.rm(temp, { force: true }).catch(() => undefined)
}
}

private async backupCurrent(): Promise<string | undefined> {
if (!existsSync(this.settingsPath)) return undefined
mkdirSync(this.backupsDir, { recursive: true })
Expand Down Expand Up @@ -201,6 +249,7 @@ export class SettingsService {
const colourNode = asRaw(doc.colour)
const cursorNode = asRaw(doc.cursor)
const edidNode = asRaw(doc.edid)
const iddCxNode = asRaw(doc.iddcx)
const integrationNode = asRaw(doc.edid_integration)
const hdrNode = asRaw(doc.hdr_advanced)
const hdr10Node = asRaw(hdrNode.hdr10_static_metadata)
Expand Down Expand Up @@ -260,9 +309,17 @@ export class SettingsService {
},
edid: {
customEdid: toBool(edidNode.CustomEdid, d.edid.customEdid),
customDisplayId: toBool(edidNode.CustomDisplayId, d.edid.customDisplayId),
preventSpoof: toBool(edidNode.PreventSpoof, d.edid.preventSpoof),
edidCeaOverride: toBool(edidNode.EdidCeaOverride, d.edid.edidCeaOverride)
},
iddCx: {
d3d12SwapChain: toBool(iddCxNode.D3D12SwapChain, d.iddCx.d3d12SwapChain),
virtualI2c: toBool(iddCxNode.VirtualI2c, d.iddCx.virtualI2c),
staticDesktopReencodeFrameCount: Math.min(MAX_STATIC_DESKTOP_REENCODE_COUNT, Math.max(0,
Math.trunc(toNum(iddCxNode.StaticDesktopReencodeFrameCount, d.iddCx.staticDesktopReencodeFrameCount))
))
},
edidIntegration: {
enabled: toBool(integrationNode.enabled, d.edidIntegration.enabled),
autoConfigureFromEdid: toBool(integrationNode.auto_configure_from_edid, d.edidIntegration.autoConfigureFromEdid),
Expand Down Expand Up @@ -405,10 +462,17 @@ export class SettingsService {
lines.push(` <!-- === CUSTOM EDID CONFIGURATION === -->`)
lines.push(` <edid>`)
lines.push(` <CustomEdid>${b(s.edid.customEdid)}</CustomEdid>`)
lines.push(` <CustomDisplayId>${b(s.edid.customDisplayId)}</CustomDisplayId>`)
lines.push(` <PreventSpoof>${b(s.edid.preventSpoof)}</PreventSpoof>`)
lines.push(` <EdidCeaOverride>${b(s.edid.edidCeaOverride)}</EdidCeaOverride>`)
lines.push(` </edid>`)
lines.push(``)
lines.push(` <iddcx>`)
lines.push(` <D3D12SwapChain>${b(s.iddCx.d3d12SwapChain)}</D3D12SwapChain>`)
lines.push(` <VirtualI2c>${b(s.iddCx.virtualI2c)}</VirtualI2c>`)
lines.push(` <StaticDesktopReencodeFrameCount>${s.iddCx.staticDesktopReencodeFrameCount}</StaticDesktopReencodeFrameCount>`)
lines.push(` </iddcx>`)
lines.push(``)
lines.push(` <!-- === EDID INTEGRATION SYSTEM === -->`)
lines.push(` <edid_integration>`)
lines.push(` <enabled>${b(s.edidIntegration.enabled)}</enabled>`)
Expand Down
6 changes: 5 additions & 1 deletion VirtualDriverControl/src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
BackupInfo,
BaseDirResult,
DisplayLayoutInfo,
DriverIddCxFeatures,
DriverLiveSettings,
DriverStatus,
GpuInfo,
Expand Down Expand Up @@ -42,7 +43,9 @@ const api = {
setGpu: (name: string): Promise<PipeResult> => ipcRenderer.invoke('pipe:set-gpu', name),
query: (command: string): Promise<PipeResult> => ipcRenderer.invoke('pipe:query', command),
sendRaw: (command: string): Promise<PipeResult> => ipcRenderer.invoke('pipe:send-raw', command),
getDriverSettings: (): Promise<DriverLiveSettings | null> => ipcRenderer.invoke('pipe:get-driver-settings')
getDriverSettings: (): Promise<DriverLiveSettings | null> => ipcRenderer.invoke('pipe:get-driver-settings'),
getIddCxFeatures: (): Promise<DriverIddCxFeatures | null> => ipcRenderer.invoke('pipe:get-iddcx-features'),
setReencodeCount: (count: number): Promise<PipeResult> => ipcRenderer.invoke('pipe:set-reencode-count', count)
},
settings: {
load: (): Promise<SettingsLoadResult> => ipcRenderer.invoke('settings:load'),
Expand All @@ -51,6 +54,7 @@ const api = {
raw: (): Promise<string | null> => ipcRenderer.invoke('settings:raw'),
backups: (): Promise<BackupInfo[]> => ipcRenderer.invoke('settings:backups'),
restore: (fileName: string): Promise<SaveResult> => ipcRenderer.invoke('settings:restore', fileName),
importDisplayId: (): Promise<SaveResult | null> => ipcRenderer.invoke('settings:import-display-id'),
saveMonitorProfile: (xml: string, edidBytes?: Uint8Array): Promise<SaveResult> =>
ipcRenderer.invoke('settings:save-monitor-profile', xml, edidBytes)
},
Expand Down
Loading