Friday 20 April 2018

Setting up Linux to automatically launch a browser in a "kiosk" session

At work, we have some monitoring systems which we like to display on separate screens. These screens are connected to old computers which have been reinstalled with Windows. We have them set to auto-launch the displays, but it took some fiddling to get the chrome windows launched and positioned correctly. These instructions use xorg - I'm still not sure on Wayland... will be great when they figure out quick solution for "remote desktop".

Bringing it all together..

Step 1. Install packages

I use several applications in the setup:
  • Display manager
    This is a default thing for most linuxes these days - it provides the graphical login prompt. You can, if you like, not use one and directly launch X in a smaller setup. LightDM is most common on Ubuntu. Previously gdm was used.
    Ubuntu Package: lightdm
  • A browser
    I use chromium for its kiosk and other window positioning switches.
    Ubuntu Package: chromium-browser
  • A window manager
    This is what helps the graphical environment locate, place and otherwise manage the application windows that are open. Without one, it can be difficult to get windows to show full screen.
    Ubuntu Package: metacity
  • Display configuration tools - xset and xrandr
    If you have an information display running, chances are you don't want it to go to sleep due to a screen saver kicking in.

    xset can allow tweaking of screen blanking and DPMS settings.

    xrandr is a command that speaks the X "Resize and Rotate" protocol. This allows for the scripting of display port settings (resolution), output rotation, and position relative to other displays. I use this on dual monitor instances to instruct the window manager that one display is beneath the other.
    Ubuntu Package: x11-xserver-utils
If not installed, these packages may all be installed by using `apt-get install`

Step 2. Create a script to launch your chosen applications

Normally when you log into an X session, a series of default applications are started (desktop environment, window manager, perhaps some sound library programs etc.). We only want to load a specific set of programs with no room for distraction/abuse by the user.

In my case, I've created a script in the /usr/share/xsessions folder, alongside the desktop file that will link to it.
metacity &
xset s 0 0
xset -dpms
xrandr --output LVDS-1 --below VGA-1
chromium-browser --temp-profile --kiosk --new-window --window-position=0,0 &
exec chromium-browser --temp-profile --kiosk --new-window --window-position=0,1367
In this configuration, I'm:
  1. Starting (and backgrounding) the display manager
  2. Disabling screen blanking
  3. Disabling DPMS power management
  4. Telling the computer (a notebook) that its internal LCD is to be logically positioned below the monitor connected to its VGA output
  5. Launching a fresh, temporary profile in Chrome and having it open a new window to a specific web address on the primary VGA display (coordinates 0,0). I end the command line with an ampersand to background the browser so the script can keep running
  6. Launching an additional chrome instance, but to a different URL with different coordinates that target the internal display. I call it via exec so that the former script process is now bound to the browser. The result is that as soon as the profile is logged in, it displays two, full screen browser windows, one on each display. If someone quits the second browser, it'll log out.
I still need to figure out the argument to tell Chromium to stop asking me to sign into a Google account.

Step 3. Create a session file to invoke the script

Display managers like lightdm offer users the option to log in as one of several sessions, defined by files in /usr/share/xsessions. These are .desktop files, like the ones used to populate the various menus and desktop shortcuts in Linux. They're kind of similar, in some ways, to Windows shortcut .lnk files, but they're plain text. In /usr/share/xsessions, I've created a file:
[Desktop Entry]
Name=Kiosk Mode
Comment=Show the kiosk mode

Step 4. Configuring the display manager

Now that we have a session that launches the script we've created, we need to tell the display manager to use it. In /etc/lightdm/lightdm.conf.d, I've created a file called 70-lightdm-kioskmode.conf:
Comments and suggestions?

No comments:

Post a Comment

Hey... thanks for leaving a comment! Due to Casino spam, I've had to turn on moderation for some of the posts. Apologies - I do read every comment left!