Skip to content

Instantly share code, notes, and snippets.

@stevebrun
Last active April 14, 2024 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevebrun/f6739e84be26e60dfdf3c0516d580532 to your computer and use it in GitHub Desktop.
Save stevebrun/f6739e84be26e60dfdf3c0516d580532 to your computer and use it in GitHub Desktop.
Launch Firefox from Steam Deck's "Gaming Mode".
#!/bin/bash
##
## Launch Firefox from Steam Deck's "Gaming Mode".
##
## Although it doesn't provide a perfect browsing experience, this script
## at least makes sure that menus and windows appear as they're supposed to.
##
## INSTRUCTIONS:
##
## - Save this file to the ~/.local/bin directory.
## - In Dolphin, click on the Menu button and enable "Show Hidden Files".
## Go to your "Home" directory and open the ".local" folder.
## Create a "bin" folder if needed, and save this file to it.
## - Or, in Konsole, use the following commands:
## mkdir -p ~/.local/bin
## mv ~/Downloads/firefox.sh ~/.local/bin/firefox.sh
## - Mark the file as executable.
## - In Dolphin, right-click the file and open Properties.
## In the Permissions tab, enable the "Is executable" checkbox.
## - Or, in Konsole, use the following command:
## chmod +x ~/.local/bin/firefox.sh
## - Add the script to Steam as a non-Steam game.
## - In the Games menu, select "Add a Non-Steam Game to My Library...".
## - Click "BROWSE..." and navigate to "/home/deck/.local/bin".
## - Change the "File type" from "Applications (*.desktop)" to "All Files".
## - Select "firefox.sh", click "OPEN", then "ADD SELECTED PROGRAMS'.
## - Give the script a proper name in your Steam library.
## - Navigate to the "firefox.sh" page in your Steam library.
## - Click on the gear icon and select "Properties...".
## - Use the first textbox to change the name to "Mozilla Firefox".
##
## You can use BoilR to give the "Mozilla Firefox" page proper icons and
## images from SteamGridDB.
##
## - Download and install BoilR from Flathub:
## https://flathub.org/apps/details/io.github.philipk.boilr
## - Get an API key from SteamGridDB for BoilR.
## - Sign in to SteamGridDB with your Steam account.
## https://www.steamgriddb.com/login
## - Copy the SteamGridDB API key for your account.
## https://www.steamgriddb.com/profile/preferences/api
## - In BoilR, go to "Settings" and paste your SteamGridDB API key into
## the "Authentication key" field. Make sure to check "Download images".
## - Click the floppy disk icon at the bottom of the window to save.
## - Set the SteamGridDB ID for "Mozilla Firefox" to download Steam Deck icons.
## https://www.steamgriddb.com/game/5248361
## - In BoilR, go to "Images" and click on "Mozilla Firefox".
## - Click "Click here if the images are for a wrong game".
## - Change the "SteamGridDB ID" to 5248361.
## - Set the grid image, hero image, and icon.
## - In BoilR, go to "Images" and click on "Mozilla Firefox".
## - Click on "Grid", "Hero", "Icon", etc. to select images.
## - When you're done, click on "Import Games".
## - Click on the button at the bottom of the window with the picture of an
## arrow pointing from a game controller to the Steam icon to save your
## changes.
## - Restart Steam to see the new images on the "Mozilla Firefox" library page.
##
## ----------------------------------------------------------------------------
##
## Copyright (c) 2022 Steven Brunwasser
##
## Permission is hereby granted, free of charge, to any person obtaining a
## copy of this software and associated documentation files (the "Software"),
## to deal in the Software without restriction, including without limitation
## the rights to use, copy, modify, merge, publish, distribute, sublicense,
## and/or sell copies of the Software, and to permit persons to whom the
## Software is furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in
## all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
## DEALINGS IN THE SOFTWARE.
# Exit on any failure.
set -eo pipefail
# Check to make sure we have information about the screen.
if [ -z "${DISPLAY:-}" ]; then
echo 'No $DISPLAY attached to the current session.' >&2
exit 2
fi
# Check to make sure we're running in "Gaming Mode".
if [ -z "${GAMESCOPE_WAYLAND_DISPLAY:-}" ]; then
# Run Firefox normally if we're in "Desktop Mode".
exec /usr/bin/flatpak run \
--arch=x86_64 --branch=stable \
--file-forwarding --die-with-parent \
--command=firefox org.mozilla.firefox
fi
# Point KDE to use our customized config files for "Gaming Mode".
export XDG_CONFIG_HOME=$HOME/.local/config/gamescope/firefox
# Make sure KDE uses the user's config values for default settings.
export XDG_CONFIG_DIRS=$HOME/.config:$XDG_CONFIG_DIRS
# Check to make sure our config directory exists.
if [ ! -e $XDG_CONFIG_HOME ]; then
# Create the missing config directory.
mkdir -p $XDG_CONFIG_HOME
# Create a kwin config to hide title bars for maximized windows.
cat >$XDG_CONFIG_HOME/kwinrc <<KWINRC
[Windows]
BorderlessMaximizedWindows=true
KWINRC
# Save a window rule to force maximized windows.
cat >$XDG_CONFIG_HOME/kwinrulesrc <<KWINRULES
[gamescope-fullscreen-windows]
Description=Fullscreen Windows
closeablerule=2
maximizehoriz=true
maximizehorizrule=2
maximizevert=true
maximizevertrule=2
minimizerule=2
noborder=true
noborderrule=2
position=0,0
positionrule=2
shaderule=2
wmclasscomplete=true
wmclassmatch=2
types=66051
[General]
count=2
rules=1,gamescope-fullscreen-windows
KWINRULES
fi
# Get information about the screen's resolution.
# We use this to make sure the desktop uses the full screen.
_DISPLAY_RESOLUTION="$(xdpyinfo | awk '/dimensions/ {print $2}')"
# Make sure all shared libraries are loaded in their default order.
unset LD_PRELOAD
# Launch Firefox in its own KDE environment.
exec kwin_wayland --no-lockscreen --drm \
--width "${_DISPLAY_RESOLUTION%x*}" \
--height "${_DISPLAY_RESOLUTION#*x}" \
--xwayland --x11-display "${DISPLAY}" \
--exit-with-session=" \
/usr/bin/flatpak run \
--arch=x86_64 --branch=stable \
--file-forwarding --die-with-parent \
--command=firefox org.mozilla.firefox"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment