Skip to content

Instantly share code, notes, and snippets.

@davidedmundson
Last active April 19, 2024 14:27
Show Gist options
  • Star 91 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save davidedmundson/8e1732b2c8b539fd3e6ab41a65bcab74 to your computer and use it in GitHub Desktop.
Save davidedmundson/8e1732b2c8b539fd3e6ab41a65bcab74 to your computer and use it in GitHub Desktop.
Run plasma from within gamescope
#!/bin/sh
# Remove the performance overlay, it meddles with some tasks
unset LD_PRELOAD
## Shadow kwin_wayland_wrapper so that we can pass args to kwin wrapper
## whilst being launched by plasma-session
mkdir $XDG_RUNTIME_DIR/nested_plasma -p
cat <<EOF > $XDG_RUNTIME_DIR/nested_plasma/kwin_wayland_wrapper
#!/bin/sh
/usr/bin/kwin_wayland_wrapper --width 1280 --height 800 --no-lockscreen \$@
EOF
chmod a+x $XDG_RUNTIME_DIR/nested_plasma/kwin_wayland_wrapper
export PATH=$XDG_RUNTIME_DIR/nested_plasma:$PATH
dbus-run-session startplasma-wayland
rm $XDG_RUNTIME_DIR/nested_plasma/kwin_wayland_wrapper
@hendricha
Copy link

I have a weird issue with it. I'm using it on my Deck while its docked, with a Full HD monitor. I did edit the file so it will assume that resolution and it does actually uses that resolution.

Except the mouse is locked fom reaching the last approx 40 pixel wide column on the right edge. Do you have any idea why that might be?

@lucsoft
Copy link

lucsoft commented Jan 28, 2023

Look at my fork I have dynamic resolution so you don’t have to deal with editing the file always

@elyckir
Copy link

elyckir commented Mar 1, 2023

When using this, what is the optimal way to close it?

  • Steam menu -> Exit game
  • Desktop -> Return to Gaming Mode

@davidedmundson
Copy link
Author

When using this, what is the optimal way to close it?

Both will work.
Return to gaming mode, will trigger a graceful logout which is better if you want your text editor to prompt about unsaved changes and so on.

@lucsoft
Copy link

lucsoft commented Mar 10, 2023

Any news why flatpaks still don't have access to the freedesktop portals?
Simple stuff like OpenURI don't work with this script

@davidedmundson can you help figure my issue out?

@lucsoft
Copy link

lucsoft commented Mar 11, 2023

okay i could narrow it down current issue is that xdg-desktop-portal-kde doesn't start as it can connect to the display

@teddybee-r
Copy link

Cool stuff but I have some weird behavior when it comes to the steam keyboard inside a nested run.

Desktop keyboard locale is German. If I use the English keyboard layout inside the nested Desktop I get the German layout.
If I use the German keyboard layout I have no idea what I'm getting, a bunch of keys give me 1s instead.

@unicornsandcandies
Copy link

Is it possible to add a specific command to run a game automatically after the launch of the command?
Would be useful.

What's the use-case? If you want a fullscreen game, you're better off in gamescope without kwin. But in answer to your question, yes, append the game + args to the end of line 16 and it should all proxy through.

I cant get it to work with flatpak Firefox. Is it possibile?

@Lucaspec72
Copy link

Lucaspec72 commented Jul 25, 2023

tested it, for some reason the mouse doesn't displays when using barrier... t̶h̶e̶ ̶m̶o̶u̶s̶e̶ ̶i̶t̶s̶e̶l̶f̶ ̶i̶s̶ ̶t̶h̶e̶r̶e̶ ̶i̶t̶ ̶s̶e̶e̶m̶s̶,̶ ̶c̶a̶n̶ ̶s̶e̶e̶ ̶b̶u̶t̶t̶o̶n̶s̶ ̶h̶i̶g̶h̶l̶i̶g̶h̶t̶i̶n̶g̶ ̶w̶h̶e̶n̶ ̶i̶ ̶m̶o̶v̶e̶ ̶t̶h̶e̶ ̶m̶o̶u̶s̶e̶ (edit : lol no, mouse seems to actually be completely bugged), and if a text box is selected keyboard works. (edit : keyboard does seem to be bugged too, since window key doesn't open start menu)

(edit : I've also tried running barrier as a system service, and confirmed that barrier works fine in gamescope, but it doesn't in the nested plasma desktop. mouse does, however, show up when using the touchscreen or mouse controls set in the steam input settings.)

(edit 2 : so it appears to be a problem with gamescope, not the nested plasma. keyboard & mouse work fine in the menus but aren't read by games, probably some bug with steaminput overriding stuff

@Haxorzz
Copy link

Haxorzz commented Aug 7, 2023

Using native touchscreen steam input, crashes? Closes? The nested session.

@Haxorzz
Copy link

Haxorzz commented Aug 30, 2023

you just remove the steam shortcut and delete the file

@goofedup
Copy link

Any idea why Firefox downloads don't work when running this through game mode? No popups come up to save as or anything. Normal desktop mode still works fine.

@roel0064
Copy link

roel0064 commented Sep 11, 2023

I wanted to share my addition to the code to make plasma automatically start up with the maximum display resolution. (Or whatever game resolution the user selected from the game settings page on steam). This should improve the lives of people using different display resolutions.

(Updated the script according to the feedback from zetaPRIME & cornerdebug)

#!/bin/sh

# Remove the performance overlay, it meddles with some tasks
unset LD_PRELOAD

# Get screen resolution
X=$(xdpyinfo -display :0 | awk '/dimensions/{print $2}' | cut -d 'x' -f1)
Y=$(xdpyinfo -display :0 | awk '/dimensions/{print $2}' | cut -d 'x' -f2)

## Shadow kwin_wayland_wrapper so that we can pass args to kwin wrapper 
## whilst being launched by plasma-session
mkdir $XDG_RUNTIME_DIR/nested_plasma -p
cat <<EOF > $XDG_RUNTIME_DIR/nested_plasma/kwin_wayland_wrapper
#!/bin/sh
/usr/bin/kwin_wayland_wrapper --width $X --height $Y --no-lockscreen \$@
EOF
chmod a+x $XDG_RUNTIME_DIR/nested_plasma/kwin_wayland_wrapper
export PATH=$XDG_RUNTIME_DIR/nested_plasma:$PATH

dbus-run-session startplasma-wayland

rm $XDG_RUNTIME_DIR/nested_plasma/kwin_wayland_wrapper

@spacecowboyx
Copy link

I cannot get chrome running either. Just a black screen. Is there a way to append the code so flat packs work?

@hendricha
Copy link

Okay, I finally had the time to play with this again. roel's way of determining height/width suprisingly fixed the weird "barrier" issue I had where I could not manipulate parts of the right sides of the screen.

However we still have the issue with the missing xdg portals... Not that annoying, but you know, having the option to actually open the downloaded stuff from firefox instead of opening from Dolphin would make this perfect(ish).

@parkerlreed
Copy link

Oddly enough Chrome is running for me but I tried launching Discord and the whole gamescope session crashed and reloaded Steam

@spacecowboyx
Copy link

Downloads work fine in chrome and I got it working. However you can't really launch any apps within dolphin like an unzip program or media player for files or even txt docs. The only way to open any files so far for me was to open the corresponding app and drag and drop the file into it which is tedious. I'm using this to do quick mod adjustments for some games like Starfield without having to reboot and it works just not well.

It will crash from time to time or I'll get a black screen out of nowhere and have to force reboot the deck. It may run for a short time and even can be suspended with PauseGames but eventually it will crash your deck and a reboot is required to get it working or even the standard desktop mode working. Hoping someone can contribute to the script to address any other issues

@zetaPRIME
Copy link

Adding DISPLAY=:0 to the xdpyinfo lines there will ensure the values are taken from the actual screen resolution that SteamOS sets up, so you can set the "display resolution" field of the game entry to a higher value in order to ensure that the mouse boundaries don't randomly get snapped back to 1280x800 on you.

@cornerdebug
Copy link

cornerdebug commented Oct 17, 2023

Adding DISPLAY=:0 to the xdpyinfo lines there will ensure the values are taken from the actual screen resolution that SteamOS sets up, so you can set the "display resolution" field of the game entry to a higher value in order to ensure that the mouse boundaries don't randomly get snapped back to 1280x800 on you.

For reference, the lines should be:

X=$(xdpyinfo -display :0 | awk '/dimensions/{print $2}' | cut -d 'x' -f1)
Y=$(xdpyinfo -display :0 | awk '/dimensions/{print $2}' | cut -d 'x' -f2)

@eVen-gits
Copy link

I have an issue with this. My image is displaced and so is the cursor. I think I might have caused it by trying to rotate the screen at one point (an app was too large to be displayed vertically).

I don't know what I can do to fix it, but here's how it looks. Any pointers would be welcome.

@Zelaf
Copy link

Zelaf commented Oct 22, 2023

This is working great in general, awesome to have full KDE inside of game mode!

One is I experience is however, I run with my native resolution on my 4K TV and then run another game on top the mouse gets locked into the other games resolution so I can only move it within a 720p border. Anyone know how to fix that without putting the other game in 4K too?

A temporary workaround seems to be restarting the script every time a new game launches. But that's a bit annoying.

@zetaPRIME
Copy link

Set the resolution in game properties to "Native" and set the game to put itself at the desired resolution. Windowed mode shouldn't have any difference in performance from borderless or fullscreen with Gamescope involved.

@Kazlehoff
Copy link

Kazlehoff commented Oct 25, 2023

I've found that trying to use Copy Paste (Ctrl C/Ctrl V) from the nested desktop results in an immeidate crash causing SteamOS to reboot.

Edit, Hmm. using roel0064's code above, along with zetaPRIME's and cornerdebug's recommendations, have fixed both the letterbox mouse cursor issue, and the copy/paste issues i was experiencing.

Recommend setting the resolution in the properties of nesteddesktop.sh to "Native"

@zetaPRIME
Copy link

Update on mouse bounds issue, I think it's a SteamOS/Gamescope bug; the mouse bounds are set on launching a game according to the resolution settings on whichever game it is, but don't correctly update when the application sets its own window size or when switching between open games. 🤔

@usaginoshoujo
Copy link

As of the past few versions of the Preview channel, copy/pasting (files?) no longer works when running in Gamescope.

@gustakasn0v
Copy link

+1 on the above, which is now more relevant as 3.5.5 has hit the Stable channel https://store.steampowered.com/news/app/1675200/view/5484882897552407488

Since 3.5.5 I also experience a minor UI bug: double-clicking "Return to Gaming Mode" on the KDE desktop doesn't fully work, but instead renders a black screen with 'Steam Menu' and 'Back' icons on the lower left and right corners respectively, instead of opening the shortcut's detail page; pressing B in this screen does take you back to the details page and finishes closing Desktop mode however

@roel0064
Copy link

roel0064 commented Nov 20, 2023

I believe it has something to do with DBus.

For the copy issue I found this probably related bug report: https://bugs.kde.org/show_bug.cgi?id=473733
When copying a file it fails and the clipboard reports this as "Message recipient disconnected from message bus without replying"
Edit: The desktop itself has no copy issue & other file managers like KDE's Index (can be found in Discover) also don't have this issue. When a file is already in the clipboard you can paste it just fine with Dolphin as well. When updating to steam OS 3.5 the entire desktop with its default applications also updated. This included Dolphin.

If I understand it correctly. DBus is also responsible for things like "save as" and "upload" windows. Probably the reason why those don't show up. (goofedub's problem)

Not a clue what is wrong with DBus in combination with the NestedPlasma.sh setup though, but the solution is probably related to this.

@rsn8887
Copy link

rsn8887 commented Nov 30, 2023

Thank you for the script. It seems to work at first glance. However, I was hoping this trick would allow VRR in desktop mode when docked with the official dock. But the adaptive sync option is still missing in the KDE Display Settings, just like with x11. Also, with this trick, the display name is now just shown as X11-0 instead of LG Electronics LG FULL HD.

Is there maybe another trick to specifically enable VRR in Plasma Wayland when docked? Maybe the information that VRR is supported, and which refresh rates are supported is somehow lost with this script?

(The game mode performance menu overlay correctly shows VRR as active, and the slider there shows all refresh rates up to 75 Hz.)

@oars
Copy link

oars commented Jan 9, 2024

Any idea why notifications don't have a proper background when running in this mode. This is the case for action set change notifications.

@roel0064
Copy link

I found a reddit post that solves my copy paste issue:
https://www.reddit.com/r/SteamDeck/comments/zqgx9g/desktop_mode_within_gaming_mode_updated_for_new/

Might be of interest to any of you.

I've changed it up a little to add the dynamic resolution functionality from my previous comment:

#!/bin/sh

# Remove the performance overlay, it meddles with some tasks
unset LD_PRELOAD

# Get screen resolution
X=$(xdpyinfo -display :0 | awk '/dimensions/{print $2}' | cut -d 'x' -f1)
Y=$(xdpyinfo -display :0 | awk '/dimensions/{print $2}' | cut -d 'x' -f2)

rm -rf /tmp/desktop-mode
mkdir -p /tmp/desktop-mode
cat > /tmp/desktop-mode/kwin_wayland_wrapper << EOF
#!/bin/sh
$(which kwin_wayland_wrapper) --width $X --height $Y --no-lockscreen --x11-display $DISPLAY \$@
EOF
chmod +x /tmp/desktop-mode/kwin_wayland_wrapper

kwriteconfig5 --file startkderc --group General --key systemdBoot false
PATH=/tmp/desktop-mode:$PATH startplasma-wayland
kwriteconfig5 --file startkderc --group General --key systemdBoot --delete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment