-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SteamOS: fixes & official controller layout (#194)
- Loading branch information
1 parent
3262e08
commit 1e9c70e
Showing
7 changed files
with
131 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0 | ||
* Vesktop, a desktop app aiming to give you a snappier Discord Experience | ||
* Copyright (c) 2023 Vendicated and Vencord contributors | ||
*/ | ||
|
||
import { exec as callbackExec } from "child_process"; | ||
import { BrowserWindow, dialog } from "electron"; | ||
import { promisify } from "util"; | ||
|
||
import { sleep } from "../../shared/utils/sleep"; | ||
import { MessageBoxChoice } from "../constants"; | ||
import { Settings } from "../settings"; | ||
|
||
const exec = promisify(callbackExec); | ||
|
||
// Bump this to re-show the prompt | ||
const layoutVersion = 1; | ||
// Get this from "show details" on the profile after exporting as a shared personal layout or using share with community | ||
const layoutId = "3063409873"; // Vesktop Layout v1 | ||
const numberRegex = /^[0-9]*$/; | ||
|
||
export const isDeckGameMode = process.env.SteamOS === "1" && process.env.SteamGamepadUI === "1"; | ||
|
||
export function applyDeckKeyboardFix() { | ||
if (!isDeckGameMode) return; | ||
// Prevent constant virtual keyboard spam that eventually crashes Steam. | ||
process.env.GTK_IM_MODULE = "None"; | ||
} | ||
|
||
// For some reason SteamAppId is always 0 for non-steam apps so we do this insanity instead. | ||
function getAppId(): string | null { | ||
// /home/deck/.local/share/Steam/steamapps/shadercache/APPID/fozmediav1 | ||
const path = process.env.STEAM_COMPAT_MEDIA_PATH; | ||
if (!path) return null; | ||
const pathElems = path?.split("/"); | ||
const appId = pathElems[pathElems.length - 2]; | ||
if (appId.match(numberRegex)) { | ||
console.log(`Got Steam App ID ${appId}`); | ||
return appId; | ||
} | ||
return null; | ||
} | ||
|
||
async function execSteamURL(url: string): Promise<void> { | ||
await exec(`steam -ifrunning ${url}`); | ||
} | ||
|
||
async function showLayout(appId: string) { | ||
await execSteamURL(`steam://controllerconfig/${appId}/${layoutId}`); | ||
// because the UI doesn't consistently reload after the data for the config has loaded... | ||
// HOW HAS NOBODY AT VALVE RUN INTO THIS YET | ||
await sleep(300); | ||
await execSteamURL(`steam://controllerconfig/${appId}/${layoutId}`); | ||
} | ||
|
||
export async function askToApplySteamLayout(win: BrowserWindow) { | ||
const appId = getAppId(); | ||
if (!appId) return; | ||
if (Settings.store.steamOSLayoutVersion === layoutVersion) return; | ||
const update = Boolean(Settings.store.steamOSLayoutVersion); | ||
|
||
// Touch screen breaks in some menus when native touch mode is enabled on latest SteamOS beta, remove most of the update specific text once that's fixed. | ||
const { response } = await dialog.showMessageBox(win, { | ||
message: `${update ? "Update" : "Apply"} Vesktop Steam Input Layout?`, | ||
detail: `Would you like to ${update ? "Update" : "Apply"} Vesktop's recommended Steam Deck controller settings? | ||
${update ? "Click yes using the touchpad" : "Tap yes"}, then press the X button or tap Apply Layout to confirm.${ | ||
update ? " Doing so will undo any customizations you have made." : "" | ||
} | ||
${update ? "Click" : "Tap"} no to keep your current layout.`, | ||
buttons: ["Yes", "No"], | ||
cancelId: MessageBoxChoice.Cancel, | ||
defaultId: MessageBoxChoice.Default, | ||
type: "question" | ||
}); | ||
|
||
if (Settings.store.steamOSLayoutVersion !== layoutVersion) { | ||
Settings.store.steamOSLayoutVersion = layoutVersion; | ||
} | ||
|
||
if (response === MessageBoxChoice.Cancel) return; | ||
|
||
await showLayout(appId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0 | ||
* Vesktop, a desktop app aiming to give you a snappier Discord Experience | ||
* Copyright (c) 2023 Vendicated and Vencord contributors | ||
*/ | ||
|
||
export function sleep(ms: number): Promise<void> { | ||
return new Promise(r => setTimeout(r, ms)); | ||
} |