Making my HTPC easier for non-technical people to use

I have a Ubuntu 16.04 instance (I’m not proud) because at the time, Kodi only supported 16.04 of the Ubuntu family and I didn’t feel like compiling it myself on another platform, or depending on prebuilt binaries (if that’s even an option). I ended up not really liking the 10-foot interface that Kodi had to offer (as well as it seemed to really stink at populating its indices of my own local content!), and I really like the paradigm of a desktop environment with traditional file manager and media player programs. So I will reimage the system with Devuan at some point, but that’s another day’s problem.
One of the little issues that I have discovered somehow between PulseAudio and HDMI is that upon each boot, the default audio out is the built-in speakers in the computer case. I have to manually adjust pavucontrol to set it to be the HDMI out audio that sends it to the big screen.
I decided to automate this so others don’t have to know what option to select on what tab in what program, in order to get the sound to goto the TV. I remember (fondly, actually) my automation days in obsolete, proprietary OSes using AutoHotKey. A great way to simulate key presses in X11 (because Wayland seems as scary as systemd or pulseaudio) is to use xdotool (which I’ve written about before).
Using my tried-and-true desktop-file-calls-shell-script method, I have whipped up a nice desktop icon for the user to call after first logging in.

[Desktop Entry]
Name=Output audio to HDMI
Exec=/home/kodi/bin/set-sound.sh
Type=Application
StartupNotify=true
Path=/home/kodi
Icon=multimedia-volume-control
StartupWMClass=pavucontrol
Terminal=true
Comment=Configures pulseaudio to send audio to HDMI automatically

And the shell script:

#!/bin/sh -x
# goal: set sound to have audio output to HDMI for the television.
# startdate: 2019-08-01 22:09
# dependencies:
#    pavucontrol
#    xdotool

pavucontrol &
sleep .5
xdotool key --delay 25 alt+c Down alt+Down End Up Up Up Return
# Return
# 3 up buttons to select the option fourth from the bottom in the list.
# this is very hard-coded for the kodi machine in the living room.

The hard part of course was finding how to notate the different keystrokes very precisely, with the capitalization and special characters.

Auxiliary info and asides

Pro tip: Don’t ever configure “Alt+F4” in an xdotool script, especially when you load it up into ~/.config/autostart, and not bound to a specific window class. I really messed up the Xfce session almost permanently because I magically closed out xfwm, xfdesktop, and I think even xfpanel. That was embarrassing, big-time. Took me a while to even figure out what I had done. I couldn’t figure out how to use the “search” window stack population function of xdotool, to identify the pavucontrol window, so I couldn’t restrict my simulated keypresses to just pavucontrol. I also learned later that when the terminal window running the shell script is terminated, it kills even the backgrounded job of pavucontrol, so no ALT+F4 was required.

I am now an open source contributor!

Overview

I use open-source software every day, since November 2015. That was the year of Linux on the Desktop for me. I picked as my desktop environment Cinnamon.

I normally don’t use virtual desktops or “workspaces,” but on one laptop I was for a while. It was actually a KDE Plasma 5 installation, which reinforced my plans to stick to Cinnamon as my heavyweight DE. However, the KDE Plasma virtual workspaces worked fine, and provided all sorts of options for the window list and alt-tab switcher for listing windows across all the workspaces. Cinnamon did not have such an offering, so when I finally replaced KDE with Cinnamon on that workstation, I just reverted to my single-workspace workflow.

I told someone online (probably in the #korora channel at irc.freenode.net) that I was willing to pay money for Cinnamon to provide a window list option for displaying the windows from all workspaces. Well, as of October 2, I guess I owe myself $50.

Check out my merged pull request to Cinnamon! I added the feature, as a boolean setting, to the mainline Cinnamon window list applet. So eventually my option will be included in the Fedora Cinnamon build down the line. For the time being, though, I’m going to continue to use my separate applet that provides my feature.

Restart cinnamon from command line

When cinnamon freezes up and needs to be restarted, you can restart it from Cinnamon itself or from a different terminal.

In Cinnamon

Press ALT+F2. Type in the letter r and press enter.

On the command line

To switch to another console terminal, press CTRL+ALT+F2.
On this terminal, type this command.

pkill -HUP -f "cinnamon --replace"

References

Weblinks

  1. User sim at askubuntu.com https://askubuntu.com/questions/143838/how-do-i-restart-cinnamon-from-the-tty/523436#523436

Cinnamon on VNC on CentOS 7

Overview

This document describes how to install Cinnamon desktop environment on CentOS 7 for use in VNC. Basically, you can take a headless server and turn it into a virtual desktop controller.

Caveats

Limitations of this design prevent this from scaling up past so many users, so this would be best suited for home or small office use.
VNC uses no security. Consider alternatives or additions to this process when security is a consideration.

Installing Cinnamon for VNC

Installing the components

Install the vnc server.

yum install tigervnc-server tigervnc vnc

Install the desktop environment.

yum install cinnamon

Install any applications to be used.

yum install firefox gnome-terminal

Configuring the components

For each user that uses a virtual desktop on this host, you will need a separate systemd service, as well as a vnc password which is separate from the regular user password. Also set up the xstartup file for vnc.

tu=bgstack15
tn=1
sudo cp -p /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@\:${tn}.service
sed -r -i -e "s//${tu}/g;' /etc/systemd/system/vncserver@\:${tn}.service
systemctl enable vncserver@\:${tn}.service
firewall-cmd --permanent --add-port 59$( printf '%02i' "${tn}")/tcp
printf "For user ${tu} please provide new "
su - ${tu} -c vncpasswd
tf=~/.vnc/xstartup
test -f "${tf}" && \cp -p "${tf}" "${tf}.$( date "+%Y-%m-%dT%H%M%S" )"; touch "${tf}"; chmod 0755 "${tf}"
cat <<EOF > "${tf}"
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
exec /usr/bin/cinnamon-session
EOF
systemctl start vncserver@\:${tn}.service

Connecting to the desktop

On a client, run

vncviewer hostname:1

Logout from Different Desktop Environments from Command Line

Rambling

Some people spend all day in terminals, even though there’s a desktop environment running. I normally have four different terminals open on my main screen, in a normal quadrant pattern. I arrange them on the taskbar so they are clockwise, starting in the upper left quadrant.

Problem

Suppose you want to close your session, without having to use the mouse or pressing the Super key or anything like that.

You want to enter a command from your terminal that will close your session. Here is a list of how to do that, for each different desktop environment (DE) I’ve collected so far.

Logout from desktop environments

Logout from cinnamon from command line

cinnamon-session-quit --logout --force

Logout from xfce from command line

xfce-session-quit -l

Logout from GNOME Shell from command line

­gnome-session-quit

Logout from KDE4 from command line

qdbus org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout -1 -1 -1

Logout from KDE5 from command line

With confirmation

qdbus org.kde.ksmserver /KSMServer logout 1 3 3

Without confirmation

qdbus org.kde.ksmserver /KSMServer logout 0 3 3

Logout from desktop environment from command line

loginctl terminate-user username

References

Weblinks

  1. Cinnamon https://forums.linuxmint.com/viewtopic.php?t=177547
  2. Gnome https://askubuntu.com/questions/15795/how-can-you-log-out-via-the-terminal#15796
  3. KDE4 http://www.techlw.com/2012/07/log-out-in-ubuntu-from-command-line.html
  4. KDE5 Plasma https://forum.kde.org/viewtopic.php?f=289&t=135065
  5. Extra reading for KDE https://majewsky.wordpress.com/2009/07/11/shutdown-your-machine-automatically-or-from-remote/