DietPi icon indicating copy to clipboard operation
DietPi copied to clipboard

DietPi-Software | Chromium: Hide mouse in autostart kiosk mode

Open Zixim opened this issue 6 years ago • 27 comments

ADMIN EDIT: Solutions

If you still want to be able to use the mouse, only hide it when idle:

On RPi:

G_AGI unclutter && echo '/usr/bin/unclutter -idle 0.1 &' > /etc/chromium-browser/customizations/99-dietpi-unclutter

On all other devices:

G_AGI unclutter && echo '/usr/bin/unclutter -idle 0.1 &' > /etc/chromium.d/dietpi-unclutter

If you never want to use the mouse:

G_CONFIG_INJECT 'xinit[[:blank:]]' 'xinit $FP_CHROMIUM $CHROMIUM_OPTS -- -nocursor' /var/lib/dietpi/dietpi-software/installed/chromium-autostart.sh

Required Information

#!/bin/bash G_DIETPI_VERSION_CORE=6 G_DIETPI_VERSION_SUB=21 G_DIETPI_VERSION_RC=1 G_GITBRANCH=master G_GITOWNER=Fourdee

cat /etc/debian_version 9.8

uname -a Linux DietPi 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU/Linux SBC device Rpi3

Additional Information (if applicable)

  • Software title Chromium Autostart
  • installed freshly
  • Can this issue be replicated on a fresh installation of DietPi? Yes

Steps to reproduce

The Pi has no attached keyb nor mouse. as described here : https://github.com/Fourdee/DietPi/issues/2298#issuecomment-443406683 install unclutter add line to chromium-autostart.sh , before xinit line:

sleep 10 && unclutter -idle 0.1 &

xinit $FP_CHROMIUM $CHROMIUM_OPTS

Expected behaviour

Chromium starts and displays page. Cursor disappears after approx 10 seconds.

Actual behaviour

Cursor never disappears

Extra details

Have also tried

xinit $FP_CHROMIUM -nocursor $CHROMIUM_OPTS

No joy.

https://github.com/Fourdee/DietPi/issues/2298#issuecomment-443406683

Zixim avatar Feb 22 '19 11:02 Zixim

@Zixim Thanks for your report.

I remember this from the other topic, so indeed you tried out both method and non of them worked. I will check this out on x86 machine to verify it's either DietPi or RPi specific.

MichaIng avatar Feb 24 '19 13:02 MichaIng

This seems to do the trick using unclutter, I tested this on a Raspberry Pi 3B+.

/var/lib/dietpi/dietpi-software/installed/chromium-autostart.sh Change the last line to these 2 lines: xinit $FP_CHROMIUM $CHROMIUM_OPTS & sleep 1 && /usr/bin/unclutter -display :0 -idle 0.01 &

crawc avatar Feb 28 '19 20:02 crawc

I admit that I never added the display parameter when trying out dietpi. I do have unclutter working on Raspbian boards without the parameter.

Zixim avatar Mar 01 '19 09:03 Zixim

@crawc Okay, so unclutter has to be started after xinit, this is good to know. I guess xinit has to fully finish, why the sleep is required? Depending on the system 1 second might be not sufficient. For now I added the solution to the OT with sleep 5 and -idle 0.1 (from Fourdees suggestion) to be failsafe.

I still wonder why -nocursor does not work which looks like a cleaner integrated attempt which should apply to the correct display directly and work without any random sleep. I will have a closer look into this.

MichaIng avatar Mar 02 '19 18:03 MichaIng

Sorry for the delayed reply. Yes, without the sleep unclutter can't utilize display :0 until xinit creates it. You are correct 1 second might not be enough time for other platforms. Maybe a better way would be have a loop to check if xinit is started then execute unclutter. I will see what I can come up with and post back.

crawc avatar Mar 11 '19 18:03 crawc

@crawc @Zixim Found the solution with -nocursor. It is indeed an xinit/Xorg option, not a chromium option. But it needs to be added after the xinit chromium call that everything is recognized correctly and after closing the chromium args via --.

So the command entry needs to be: xinit $FP_CHROMIUM $CHROMIUM_OPTS -- -nocursor The cursor is still available. When moving it I see webpage elements highlighting, but it has no visible graphic.


However the noclutter option has the advantage that the cursor can show up when moved. Found some guides about how to add it as desktop autostart script:

  • https://jackbarber.co.uk/blog/2017-02-16-hide-raspberry-pi-mouse-cursor-in-raspbian-kiosk
  • https://www.raspberrypi.org/forums/viewtopic.php?p=405215

But this depends on LXDE desktop which is not always chosen, not must be any desktop chosen for chromium. So we need to find a way to add it as xinit/Xorg autostart script.


Lol actually unclutter should be already executed by default on all xinit calls:

root@VM-Stretch:~# cat /etc/X11/xinit/xinitrc
#!/bin/sh

# /etc/X11/xinit/xinitrc
#
# global xinitrc file, used by all X sessions started by xinit (startx)

# invoke global X session script
. /etc/X11/Xsession

root@VM-Stretch:~# cat /etc/X11/Xsession.d/90unclutter
# /etc/X11/Xsession.d/90unclutter
# This file is sourced by Xsession(5), not executed.

if [ -e /etc/default/unclutter ]
then
        . /etc/default/unclutter
fi

if [ -x /usr/bin/unclutter ] && [ "${START_UNCLUTTER}" = "true" ]
then
        /usr/bin/unclutter ${EXTRA_OPTS} &
fi

root@VM-Stretch:~# cat /etc/default/unclutter
# /etc/default/unclutter - configuration file for unclutter

# Set this option to 'true' if you want to start unclutter
# automagically after X has been started for a user.
# Otherwise, set it to 'false'.
START_UNCLUTTER="true"

# Options passed to unclutter, see 'man unclutter' for details.
EXTRA_OPTS="-idle 1 -root"
  • However it has no effect. Only running unclutter -display :0 -idle 0.1 & e.g. from SSH session works.
  • Note that I did a default chromium + Xorg install outside of DietPi-Software, so this is not DietPi related but related to the way how xinit start scripts are pulled in.
  • E.g. calling startx (without desktop opens xterm) works well. The cursor hides always after 1 second idle as defined in the above scripts.
  • But when calling xinit, it does not work, xterm opens just the same, but the cursor does not hide.

Ah understand it now:

  • startx is a xinit wrapper that pulls in xinitrc, while xinit itself does not.
  • So in this case indeed it is cleaner to start unclutter manually with chromium start.

MichaIng avatar Mar 12 '19 15:03 MichaIng

Okay found the best two solutions based on use case

  • If you still want to be able to use the mouse, only hide it when idle:

G_AGI unclutter && echo '/usr/bin/unclutter -idle 0.1 &' > /etc/chromium.d/dietpi-unclutter

(Requires validation on RPi, since other Chromium package is used there, but works well on Debian...)

  • If you never want to use the mouse:

G_CONFIG_INJECT 'xinit[[:blank:]]' 'xinit $FP_CHROMIUM $CHROMIUM_OPTS -- -nocursor' /var/lib/dietpi/dietpi-software/installed/chromium-autostart.sh

So the question is now which one we want to implement by default, if any, or leave choice to user via dietpi.txt setting?

@crawc @Zixim Any suggestion?

MichaIng avatar Mar 12 '19 17:03 MichaIng

I like the idea of having options: No cursor or Hide cursor when in chrome kiosk mode.

I just tried the unclutter option on the RPi3B+ and it did NOT hide the cursor.

crawc avatar Mar 12 '19 20:03 crawc

@crawc Thanks for testing on RPi. Does /etc/chromium.d even exist there? And if so are there example drop-ins inside? Perhaps this is handled differently by the chormium-browser package on RPi compared to the chromium package on Debian.


Just tested G_AGI unclutter && echo '/usr/bin/unclutter -idle 0.1 &' > /etc/chromium.d/dietpi-unclutter on top of DietPi-Software Chromium install and Chromium autostart and on VM the cursor hides as expected 🤔.

MichaIng avatar Mar 12 '19 21:03 MichaIng

Yes, the directory did exist with a single file custom_flags before I created the dietpi-unclutter file.

root@DietPi:~# ls -ltrh /etc/chromium.d/ total 8.0K -rw-r--r-- 1 root root 255 Feb 28 16:10 custom_flags -rw-r--r-- 1 root root 44 Mar 12 20:10 dietpi-unclutter

crawc avatar Mar 13 '19 14:03 crawc

@crawc Okay, can you please paste the content of the file, just to be sure? cat /etc/chromium.d/custom_flags

  • The xserver is definitely initiated before it runs Chromium (inside), so unclutter should work without sleep. However you could try to add a sleep 1 && to verify.
  • You could as well check if -display :0 is required, but actually when running inside an xserver session it should apply the correct display automatically 🤔.

MichaIng avatar Mar 13 '19 16:03 MichaIng

I tried with -display :0 , sleep 1 && , and the combination but its still showing the cursor.

root@DietPi:~# cat /etc/chromium.d/custom_flags export CHROMIUM_FLAGS="$CHROMIUM_FLAGS --test-type --no-sandbox --temp-profile --user-data-dir --disable-smooth-scrolling --disable-low-res-tiling --enable-low-end-device-mode --num-raster-threads=4 --profiler-timing=0 --disable-composited-antialiasing "

crawc avatar Mar 13 '19 18:03 crawc

@crawc Hmm the file is identical with the one from Debian. Pre shell script, so the unclutter command should work as desired. However perhaps the files are not sourced. Which user do you use to login? If not root, could you try to login as root? Perhaps non-root users read/source only from their home dir.

MichaIng avatar Mar 13 '19 20:03 MichaIng

I'm using the root user.

crawc avatar Mar 14 '19 12:03 crawc

@crawc Ahh just found another config dir for the chromium-browser package on RPi: /etc/chromium-browser/customizations Could you try to move the dietpi-unclutter inside there: mv /etc/chromium.d/dietpi-unclutter /etc/chromium-browser/customizations/99-dietpi-unclutter And to be sure revert to initial state: echo '/usr/bin/unclutter -idle 0.1 &' > /etc/chromium-browser/customizations/99-dietpi-unclutter

MichaIng avatar Mar 14 '19 20:03 MichaIng

@MichaIng That did it on the RPi3B+, I will test on RPi1 and RPi2 as well! Nice find!

crawc avatar Mar 18 '19 15:03 crawc

@crawc Finally, great! Veery important to know that there are indeed such main differences between RPi and Debian Chromium packages.

Did xinit $FP_CHROMIUM $CHROMIUM_OPTS -- -nocursor btw work as well to hide the cursor permanently?


I added this to v6.23 milestone, now that we finally found the solution on RPi.

MichaIng avatar Mar 18 '19 22:03 MichaIng

Implementation planned with some additional options: https://github.com/MichaIng/DietPi/issues/2938

MichaIng avatar Jun 28 '19 16:06 MichaIng

@MichaIng, xinit $FP_CHROMIUM $CHROMIUM_OPTS -- -nocursor worked for me on a RPI-3B+

mrbluecoat avatar Jan 08 '20 17:01 mrbluecoat

@mrbluecoat Thanks for testing, I guess the following works as well, doesn't it? xinit -nocursor $FP_CHROMIUM $CHROMIUM_OPTS Its all about having -nocursor as xinit option and not as chromium binary option. -- can be used as syntax to end chromium arguments, but having xinit options in the front should work the same way.

MichaIng avatar Jan 08 '20 17:01 MichaIng

With your version I get bad command line option "-nocursor" and connection to X server is lost

mrbluecoat avatar Jan 08 '20 18:01 mrbluecoat

@mrbluecoat Thanks for testing. Okay strange, then xinit requires some different syntax.

MichaIng avatar Jan 08 '20 19:01 MichaIng

Hi, for auto refresh of chromium every 20 seconds interval should I use 99-dietpi-autorefresh? or add the script code somewhere else?

arahasya avatar Oct 19 '20 10:10 arahasya

@arahasya I guess you raised same question on the forum https://dietpi.com/forum/t/autorefresh-chromium-kiosk-using-xdotool/4553

Joulinar avatar Oct 19 '20 12:10 Joulinar

Have you found a solution for this?

This command works for me on an Odroid C4 with DietPi 8.12.1

xinit /usr/bin/chromium --kiosk --window-size=1920,1080 --window-position=0,0 http://127.0.0.1:8080/basicui/app -- -nocursor & (I run this from Node-RED, or versions of it with the URL set dynamically)

Which I guess translates to the autostart.sh file as

exec "$STARTX" "$FP_CHROMIUM" $CHROMIUM_OPTS "${URL:-https://dietpi.com/}" -- -nocursor &

MDAR avatar Dec 22 '22 12:12 MDAR

I think this is the right syntax for "If you never want to use the mouse": exec "$STARTX" "$FP_CHROMIUM" $CHROMIUM_OPTS "${URL:-https://dietpi.com/}" -- -nocursor that has to got into /var/lib/dietpi/dietpi-software/installed/chromium-autostart.sh. So just added an -- -nocursor to the end of the last line. Maybe somebody could edit the initial posting's solution to this? Because, what's now there simply doesn't work on the current (DietPi 8.20.1) version of chromium-autostart.sh. Remember: this thread here has become part of the official documentation: https://dietpi.com/docs/software/desktop/#chromium Still took me half an hour to find the real correct solution.

pkoevesdi avatar Aug 29 '23 20:08 pkoevesdi

Ah right, many thanks. Indeed the config file location as well as the way the X server is invoked has changed. I'll adjust it this weekend.

MichaIng avatar Sep 01 '23 12:09 MichaIng