Page 1 of 1

Naive and heretical questions about X11 on the Pi

Posted: Sat Dec 31, 2016 1:54 am
by JohnBeardmore
I’m trying to put together a public display to show the output power of a large PV system. The power measurement bit all works fine, so now I’m looking at the ‘minor’ matter of the public display. What I want to do is pretty simple. It’s just displaying some very big digits, possibly with a couple of logos and a small graph or two.

The idea is to mount the system high on a wall with no keyboard or mouse for user input. This is an output only program, taking a data feed via a file in /tmp. My hope is to plug an HDMI monitor into the Pi and use this as the display. (Access to the system for maintenance and development is by ssh and xrdp.)

Screen refresh will be every 15 seconds which hopefully won’t be too challenging, and this seems to be OK at the moment even on a Pi B.

I want to do this project on a Raspberry Pi so it will be cheap, and play nicely with the other open source energy bits and pieces I’m writing on the Pi.

Digging into the X documentation and online examples, my initial experiments have gone well, but all are based on examples which tell you how to do things the usual way, within windows, and on the display that’s in front of you. All the examples basically start XopenDisplay(), XcreateSimpleWindow(), then XmapWindow(). Subsequent calls to do useful things like write the text like XdrawString() take Display and Window as parameters. XnextEvent() is used to get things out of the message queue, with XcheckWindowEvent() called to see if there’s an event waiting. If there isn’t, I can check to see if the message I’m displaying needs updating, which matters to me far more than any of the standard X events, as in normal operation there shouldn’t be any.

At the moment I’ve got as far as an x11 application which runs in a window with lovely big digits, which I can see in my development environment over xrdp. See enclosed code.

There are a few things I need to know.

Can I force this to run on the (virtual ?) display which will output to the HDMI monitor ?

Do I need to do x11 graphics in the context of a window at all ? Is it possible to write directly to the display in the absence of any window ?

Do I have to read the X event queue ? I tried only reading it when XcheckWindowEvent() said there was something, but it would still sometimes block on the subsequent call of XnextEvent() which stopped the program looking for data updates to display.

To avoid the problem in 3) above, I’ve now taken out all references to the X event handling and the program seems to be doing pretty much what I need. Are there any downsides to this ? Will the program eventually become deranged if the event queue isn’t read ?

If I can force the program to send its output to the HDMI display, can I also remove all the other screen furniture from this display (login prompts, backdrops etc).

If 2) above isn’t possible, is it possible to make the window completely borderless so it can’t be differentiated from the background ?

Many thanks, J/.

Re: Naive and heretical questions about X11 on the Pi

Posted: Sat Dec 31, 2016 2:09 am
by topguy
If you have two x-servers running (one on HDMi and another as vncserver), you select which one by using the "-display" option.

Code: Select all

xeyes -display :0.0
xeyes -display :1.0
You can also set "DISPLAY" environment variable "export DISPLAY=:0.0"

You could avoid anything X11 related by using SDL for example. You could have taken a look at "raylib" also.

If you just start the X-server by just running "X" instead of "startx" you will get a barebones version without sessionmanager and windowmanager (which is the desktop stuff).
You can also google up "xinit" which also people use to start single application X sessions.

Re: Naive and heretical questions about X11 on the Pi

Posted: Tue Jan 03, 2017 10:11 pm
by JohnBeardmore
Thanks for the know how ! I'm setting up a new test machine with an HDMI monitor connected so I should be able to see what's going on shortly.

Cheers, J/.

Re: Naive and heretical questions about X11 on the Pi

Posted: Thu Jan 05, 2017 3:51 am
by Gavinmc42
I have used Python with Pygame on Raspbian desktop(X11) for solar panel etc 5 years ago.
Headless, I then moved to JavaFX, no need for X11.
I looked at tcl/tk but decided to move forwards not backwards :D

You are at where I was 4 years ago, I had to make a decision.
Use stuff that has been around for decades or learn the new stuff.
Probably not a good idea as my head nearly exploded with the learning?

Most on my solar monitoring stuff is now done via a Pi webserver running piCore/busybox-httpd.
To view the JS/HTML5 stuff I needed to use Raspbian with Chromium on the display unit.
Midnight Commander + ssh for maintenance.

As everyone now knows Linux/busybox is not secure so I am now moving to Ultibo.
The Sensomatic3000 example code is a good place to start as it shows text and graphics windows with plotting.
Ultibo also works fine with the 7" Pi display and even smaller LCDs.

Why Ultibo?
Well I got tired of filling up my hard drive with 8GB backup images.
In fact we had to put in a server to handle all the OS's backups, versions, software/Linux books, manuals etc
Sensormatic code folder is 12 files < 1MB source

Reason 2 is speed, Laz/FPC/Delphi is well known as RAD (Rapid Application Development) tools.
Ultibo is like the Arduino type IDE but for baremetal Pi's.
Coding can be done in minutes/hours/days instead of days/weeks/months.
The graphic stuff is just about usable now, lots still needs documentation and it is early days as it is only 1 year old.

Re: Naive and heretical questions about X11 on the Pi

Posted: Tue Jan 10, 2017 1:03 pm
by Morphology
+1 for RayLib

Comes with loads of examples for displaying text, graphics etc. no X / Pixel needed.


Re: Naive and heretical questions about X11 on the Pi

Posted: Tue Jan 10, 2017 2:03 pm
by scruss
Some other possibilities:
  • Electron — an embedded JavaScipt/browser. I've seen this used to build really impressive UIs for embedded equipment that were just a Raspberry Pi + a small touchscreen.
  • Processing — a sketch with a very slow refresh rate, like once every few seconds, could read the file, parse it, and redraw the screen
  • Python/Tkinter — use root.after() at the end of your refresh subroutine to schedule a call to itself every few seconds.
  • Format the text in appropriate Pango markup, and use pango-view or ImageMagick to render it to an image. Display that image in a slideshow program that polls for changes in the image.
Processing would likely be the least work of all of these.

Re: Naive and heretical questions about X11 on the Pi

Posted: Sat Jan 14, 2017 12:22 am
by Gavinmc42
Just been using the new ver 3 of Processing on the Pi's.
Slow on a B+ but usable on a Pi 3.
Ver 3 uses JavaFX which is hardware accelerated.

Been doing some network stuff from Windows or Linux to a Pi 3.
The network draw example was fun.
Processing is also quick to learn with a good library/extension management.

It proved so easy to use it got bumped to the top of the list for quick prototyping, one off apps.
It is being used to telnet to a Pi controller running Ultibo shell.
It will allow a Windows or Linux PC or a Pi3 to network control Pi based controllers :P