STEAM GROUP
Steam Universe Steam U
STEAM GROUP
Steam Universe Steam U
65,825
IN-GAME
434,985
ONLINE
Founded
September 23, 2013
All Discussions > Steam OS > Topic Details
Shark Nov 1, 2014 @ 3:41am
The "launching programs in new Xsessions from Steam bpm" thread
Currently there are 3 threads going in which people have been trying to start Chrome on a secondary Xsession to watch things like Youtube and Netflix.

Here are the links:
http://steamcommunity.com/groups/steamuniverse/discussions/1/619569341038744776/
http://steamcommunity.com/groups/steamuniverse/discussions/1/648814841962418009/
http://steamcommunity.com/groups/steamuniverse/discussions/1/619568793780476575/

So far Dubigrasu has figured out how to do it with xinit, but I feel that we should be able to a way to automate this a lot more while using a lower amount of files. Xinit has a major disadvantage unfortunately, which is that if :1 is already used by the desktop, you can't use it.

Anyway, I'll tell you guys what I've been trying.

Here is what does work:

I created a session file for launching Youtube, the file is: /usr/local/bin/youtube-session
#! /bin/bash openbox & google-chrome --kiosk https://www.youtube.com/tv#/
I use openbox as window manager and launch Chrome in kiosk mode. That way you will not have any menu bars. You can kill the session by pressing ctrl+w.

Now to be able to start this session I created a session desktop file: /usr/share/xsession/youtube.desktop
[Desktop Entry] Encoding=UTF-8 Name=youtube Comment=Switch to youtube Exec=youtube-session Icon=steamicon.png Type=Application
Most of these statements can probably be left out, though.

Then I created a new user with:
useradd -m -s /bin/bash youtube
I set default xsession for that user by changing the file: /var/lib/AccountsService/users/youtube
[User] XSession=youtube

Now, after a reboot, if I open xterm through bpm and use this command:
dm-tool switch-to-user youtube
Youtube will launch as the youtube user.

I am running into some issues, though:

I created this file to add to Steam bpm: /home/steam/.local/share/applications/youtube.desktop
[Desktop Entry] Name=Youtube-switcher Comment=Switches to youtube Exec=/usr/bin/dm-tool switch-to-user youtube Icon=steam Terminal=false Type=Application Categories=Network;FileTransfer;Game; MimeType=x-scheme-handler/steam;
Again, most of the lines in this file are probably not required. I was able to add this to steam, but when launching it I get an error from dm-tool that I'm not using correct options.

Another thing that doesn't work, but should is choosing a session with dm-tool. I just can't figure it out, according to --help it should work like this:
switch-to-user USERNAME [SESSION] Switch to a user session
So, you'd think this would work:
dm-tool youtube youtube
Or even:
dm-tool desktop youtube
But it doesn't, I haven't figured this out yet.


Anyway, I hope this helps people out and open up some more discussion on this topic. It would be great if we were to figure this out. Not having to create new users and multiple scripts for every website would be awesome :D
Last edited by Shark; Nov 1, 2014 @ 3:42am
< >
Showing 1-15 of 29 comments
dubigrasu Nov 1, 2014 @ 4:20am 
Originally posted by Shark:
init has a major disadvantage unfortunately, which is that if :1 is already used by the desktop, you can't use it.

You can change the script to run on :2 (or :3)

"xinit $HOME/.netflix -- :2 &&"

and leave :1 free for the Desktop session and even run Netflix, BPM and Desktop session all three at the same time.
dubigrasu Nov 1, 2014 @ 5:21am 
Or even four sessions at the same time:)
First Steamos :0, and switching to Desktop :1, then from Desktop starting a third Youtube :2 session and back to Steamos to start a fourth Netflix :3 session. (and some Phoronix viewing on the Desktop session.)
Then closing them one by one.

Yeah, I kinda lost my way in there switching from session to session and it takes few seconds to make the switch (with Ctrl +Alt +F#) so is a bit confusing. Also some of my F keys are a bit wonky so...
And again, the video is crap, I know :(
https://www.youtube.com/watch?v=W3E_z5VnNrg&feature=youtu.be
Last edited by dubigrasu; Nov 1, 2014 @ 5:28am
Shark Nov 1, 2014 @ 6:13am 
Well, you are correct. Ijust think that hardcoding the x display into every script can become a problem if you have a lot of scripts. You only have a limited amount of F buttons, but unlimited posibilities in you scripts.

I want to try to make a script which can be used by either a lot of different sites or a lot of different applications. Imagine having multiple desktop environments, multiple media players, multiple voip applications and multiple streaming sites available to you in Steam.
Shark Nov 1, 2014 @ 8:20am 
Oh wow, I feel like an idiot now. You can avoid most of the issues with creating a new Xsession to load stuff that doesn't work on Steamcompmgr by using a different wm on Xephyr. I got Xephyr working with Steam overlay. If you start it like this from bpm it just works:
~/.steam/steam/ubuntu12_32/steam-runtime/run.sh /usr/bin/Xephyr :15 -ac -screen 1920x1080 -fullscreen -host-cursor -once &
Then just put this in your script:
export DISPLAY=:15
If you've done that you can start whatever you want in your script, window managers, desktop environments and applications. And the Steam overlay will work, recording would too.
Last edited by Shark; Nov 1, 2014 @ 9:10am
Ryochan7 Nov 1, 2014 @ 9:44am 
Originally posted by Shark:
Again, most of the lines in this file are probably not required. I was able to add this to steam, but when launching it I get an error from dm-tool that I'm not using correct options.

This is due to the way Steam parses the Exec line in desktop files. It stops processing once it hits a space or hits the end of the line so the parameters are not actually grabbed. Also, non-Steam apps have to have a unique executable. In this case, once an app has been added that uses dm-tool, no other desktop files using dm-tool will be listed. You should put the dm-tool command into its own script with a unique filename.

dm-tool always errors out for me when I try to set the session parameter. Using the equivalent dbus-send command and specifying the second string hasn't done anything different in my testing. It always ends up launching the default session for that user. I would think the only way around this would be to edit the session that will be used, using the technique discovered yesterday, before running dm-tool to start the session.

As for the X display problem, it looks like scanning through the /tmp directory is the main way that scripts check for the next available X display. The following page can possibly be used as a reference.

https://wiki.archlinux.org/index.php/Running_program_in_separate_X_display

How is the performance with Xephyr?
dubigrasu Nov 1, 2014 @ 10:30am 
OK, first impression: this is one awesome solution.

I still have to figure it out why it chokes for me when I use it for Netflix.
With Youtube it works perfectly so far, but with Netflix I can't use the gamepad to start it and I have to insist two or three times with the mouse to get it to start.
Sometimes just doesn't want to start...

First one Youtube (this one is working )
https://www.youtube.com/watch?v=XpOqHDOHYUc&feature=youtu.be

Then Netflix:
https://www.youtube.com/watch?v=Tu7TqxMZGes&feature=youtu.be
Shark Nov 1, 2014 @ 11:53am 
It probably chokes on Netflix because you're not loading a window manager, which is pretty bad for performance.
dubigrasu Nov 1, 2014 @ 12:19pm 
Originally posted by Shark:
It probably chokes on Netflix because you're not loading a window manager, which is pretty bad for performance.

I use the same script for both, just the google address is different.
Anyway, it was apparently the way the address was entered, is it working now.
So far is working just fine and the whole method is very clean.
https://www.youtube.com/watch?v=a-NXNaZeKwc&feature=youtu.be
Shark Nov 1, 2014 @ 12:28pm 
Originally posted by dubigrasu:
I use the same script for both, just the google address is different.
Anyway, it was apparently the way the address was entered, is it working now.
So far is working just fine and the whole method is very clean.
Any chance you could share your script, I'm having some issues Chrome starting in a very odd place.
dubigrasu Nov 1, 2014 @ 12:38pm 
Originally posted by Ryochan7:
As for the X display problem, it looks like scanning through the /tmp directory is the main way that scripts check for the next available X display.
Yes, just before Shark to come up with Xephyr I was about to use this:
#!/bin/sh for display in 0 1 2 3 4 5 # checks for open display, starts X on next available do if [ ! -f "/tmp/.X$display-lock" ] then exec xinit -- :$display # or startx for a full environment exit0 fi done
to avoid hardcoding. (it checks for .X0-lock, .X1-lock, .X2-lock and so on)
Startx is using something similar:
# Automatically determine an unused $DISPLAY d=0 while true ; do [ -e /tmp/.X$d-lock ] || break d=$(($d + 1)) done defaultdisplay=":$d" unset d
It could be still used but the Xephyr method is much more clean and elegant.
Last edited by dubigrasu; Nov 1, 2014 @ 10:27pm
dubigrasu Nov 1, 2014 @ 12:44pm 
For the moment it looks like this:
#!/bin/sh #~/.steam/steam/ubuntu12_32/steam-runtime/run.sh /usr/bin/Xephyr :15 -ac -screen 1920x1080 -fullscreen -host-cursor -once & /usr/bin/Xephyr :15 -ac -screen 1920x1080 -fullscreen -host-cursor -once & export DISPLAY=:15 LD_PRELOAD= google-chrome-unstable www.netflix.com --window-size=1920,1080 && #google-chrome-unstable www.netflix.com --window-size=1920,1080 && sleep 2 killall Xephyr killall -9 Xephyr
Last edited by dubigrasu; Nov 1, 2014 @ 12:45pm
Ryochan7 Nov 2, 2014 @ 1:10am 
The Xephyr method performs pretty well. It definitely would be the better method to use for a lot of use cases.

Also, I have a couple of recommendations that might help improve the script. The first is a way to get the X display resolution automatically. I found that the following works for getting the resolution information from display :0.

WIN_RES=$(DISPLAY=:0 xdpyinfo | grep dimensions | awk '{print $2}') COMMA_WIN_RES=$(echo $WIN_RES | awk '{sub(/x/, ","); print}')

WIN_RES is in the form of WIDTHxHEIGHT and COMMA_WIN_RES is WIDTH,HEIGHT.

Also, I wouldn't think that killall would need to be used twice to close Xephyr. What I have been doing is grabbing the Xephyr PID after launching the process in the background and killing it directly.

/usr/bin/Xephyr :15.0 -ac -screen $WIN_RES -fullscreen -host-cursor -once & ZEPHYR_PID=$! # Put whatever code you want here. kill $ZEPHYR_PID
Last edited by Ryochan7; Nov 2, 2014 @ 1:12am
dubigrasu Nov 2, 2014 @ 1:44am 
Originally posted by Ryochan7:

Also, I wouldn't think that killall would need to be used twice to close Xephyr. What I have been doing is grabbing the Xephyr PID after launching the process in the background and killing it directly.

/usr/bin/Xephyr :15.0 -ac -screen $WIN_RES -fullscreen -host-cursor -once & ZEPHYR_PID=$! # Put whatever code you want here. kill $ZEPHYR_PID

On my system simply killing zephyr it works a bit randomly, that's why I had to force kill it with -9, can't figure it out why.
And it does the same with kill $XEPHYR_PID so I end up with killall -9 anyway.

There is also something bugging me, but just a little; running (especially) Netflix feels a bit sluggish at times compared with running on a fresh new session.
I don't seem to get this with Youtube and some other less intensive apps, but with some more demanding apps there is a slight loss of performance and random hangs.

All and all though I think this is the way to go, it feels more "right".

WIN_RES=$(DISPLAY=:0 xdpyinfo | grep dimensions | awk '{print $2}') COMMA_WIN_RES=$(echo $WIN_RES | awk '{sub(/x/, ","); print}')
Great, thanks!
Last edited by dubigrasu; Apr 5, 2015 @ 10:14am
Shark Nov 2, 2014 @ 2:58am 
Originally posted by Ryochan7:
Also, I have a couple of recommendations that might help improve the script. The first is a way to get the X display resolution automatically. I found that the following works for getting the resolution information from display :0.

WIN_RES=$(DISPLAY=:0 xdpyinfo | grep dimensions | awk '{print $2}') COMMA_WIN_RES=$(echo $WIN_RES | awk '{sub(/x/, ","); print}')
Good idea,I should add that to my recording script as well since it's pretty short. You can make it even shorter, though, like this:
WIN_RES=$(xdpyinfo|grep dimensions|awk '{print $2}'|tr x \,)

Right now this is my script, I still need to change a few things:
#! /bin/bash Xephyr :15 -ac -screen 1920x1080 -fullscreen -host-cursor -once & export DISPLAY=:15 openbox-session & LP=$LD_PRELOAD unset LD_PRELOAD google-chrome http://www.youtube.com/tv#/ --kiosk --windows-size=1920,1080 export LD_PRELOAD=$LP killall Xephyr
If I close the Chrome tab, the session ends.
Last edited by Shark; Nov 2, 2014 @ 3:22am
dubigrasu Nov 2, 2014 @ 10:44am 
Partially related to this, here is the xboxdrv shell I use to control both Youtube and Netflix.
It can be triggered from the scripts of course, ex:
$HOME/.xboxshell & .......... killall xboxdrv
or similar.

Youtube is more suited to be controlled with a gamepad, it has several useful keyboards control while basically Netflix requires a mouse.

(this is for Xbox 360 wired controller)
http://pastebin.com/raw.php?i=Y1sqCpUt
Last edited by dubigrasu; Nov 2, 2014 @ 12:08pm
< >
Showing 1-15 of 29 comments
Per page: 1530 50

All Discussions > Steam OS > Topic Details