Graphical Application without desktop environment


18 posts
by wally » Mon May 06, 2013 9:24 am
Hello,

i want to start a gambas3 graphical application immediately after boot
without starting the desktop environment.
Is this possible and how to do it ?

thx wally
Posts: 45
Joined: Mon Aug 06, 2012 12:07 pm
by DaveDriesen » Mon May 06, 2013 4:37 pm
Hi,

There's several ways to go about this, and the best solution depends on your desires or vision.

Have a look at this simplified 3-step method, for auto-booting into anything you want (mediaplayer, game emulator, ...)

- add startx to rc.local using a specific user
- allow that user to start an X session
- configure the user's X init script to launch the app

Step 1: add startx to /etc/rc.local
The easiest cheat to start an application after the linux boot process, is to modify /etc/rc.local. This file is executed as the last step in the init process and you can use it to put all kinds of geeky stuff in there. If you're looking for something more advanced then you can create a script and add it to /etc/init.d, but let's keep things simple. The rc.local file is more than enough for day-to-day needs.

Of course, we'll be wanting to launch the X server. Hence we'll add the startx command to /etc/rc.local.
Code: Select all
#/etc/rc.local
su -s /bin/bash -c startx your_user&
As a step-by-step clarification, this will:
- impersonate a user of your choice (here it is your_user)
- start a shell of your choice (here it is /bin/bash)
- and launch startx within that shell

Step 2: allow non-interactive processes to launch an X server
Your linux distro is likely to come configured so that only root or interactive sessions (consoles or shells) can launch the X server. Non-interactive processes, such as the boot process, are typically prohibited from doing so. Seeing as you want everything to launch automatically at boot, you will need a way around this, or your X session will refuse to start at boot and all you'll see is a bunch of "permission denied" messages on your console instead.

In raspbian, reconfiguring xorg so that any user can launch xorg is done as follows:
Code: Select all
dpkg-reconfigure x11-common
X11-common.png
X11-common.png (17.23 KiB) Viewed 29843 times

Alternatively, edit /etc/X11/Xwrapper.config and change allowed_users=console to allowed_users=anybody.

Step 3: add your application to ~/.xinitrc
Last but not least, you need to add an entry for your gambas3 application to the specified user's xinitrc so that this applications gets started when x comes up:
Code: Select all
#~your_user/.xinitrc
/usr/bin/gambas3
Note that this setup will launch one X session at boot time, and launch your application only once within that session. When the application exits, so will X, and you will be returned to the console. But you get the idea.

If you do need your x session or app to respawn then you'll be better off editing inittab, changing default runlevel, or whatnot.

I have tried to describe a very basic way of having X launch automatically during system startup, and having an application launch within that X session.

Let us know how this works out for you -- thanks!

Dave Driesen
Linux dev and oldskool elite.
User avatar
Posts: 112
Joined: Sun Mar 31, 2013 8:28 pm
Location: Top of the food chain
by bullwinkle » Wed Jul 24, 2013 5:29 am
worked for me.....
....many thanks
Posts: 114
Joined: Wed Jan 09, 2013 12:14 pm
by eng.sergiosoares » Mon Oct 07, 2013 8:22 pm
Awesome!

This worked for me with a JAVA Swing application on Raspberry PI.
On step 3, I had to change the permissions to my file ~/.xinitrc by using: sudo chmod 755 ~/.xinitrc

Thank you very much,

Sergio Soares (Brazil)
Posts: 4
Joined: Wed Jun 26, 2013 7:44 pm
by cjnslm » Thu Jan 16, 2014 11:42 am
Works like a charm in Ubuntu 13.04 with java swing application. Thanks :) !

I do have an extra question:
Can i add to the same x session a remote desktop app such as tightvnc? The idea behind it was to have remote control capabilities for the purpose of technical support to the application.

Thanks in advance to anyone that can help.
User avatar
Posts: 4
Joined: Thu Jan 16, 2014 11:33 am
by AndyD » Thu Jan 16, 2014 9:32 pm
cjnslm wrote: Can i add to the same x session a remote desktop app such as tightvnc?

Yes, have a look at x11vnc.
User avatar
Posts: 2300
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
by cjnslm » Fri Jan 17, 2014 10:33 am
Thanks for the quick response Andy.
I'm checking out x11vnc but it seems it needs a specific display to attach to and the method described in this post does not initialize any display (checked it with root@localhost> w).
I'm doing further digging for a solution on how to attach vnc server to the x display on which i'm running my java app and if i find a solution i'll be sure to post it back to this thread.
Any help is welcome though :).
User avatar
Posts: 4
Joined: Thu Jan 16, 2014 11:33 am
by cjnslm » Fri Jan 17, 2014 1:03 pm
It seems that whenever i start the application with startx the default display setting is ignored. If i do call startx without .xinitrc, a xterm is initialized and a display is set (as can be seen w output bellow)

Code: Select all
 13:02:39 up 43 min,  4 users,  load average: 0,06, 0,10, 0,13
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty2                      12:59    2:47   0.54s  0.00s xinit /etc/X11/xinit/xinitrc -- /etc/X11/xinit/xserverrc :0
pos      tty1                      12:53    8:39   0.79s  0.24s -bash
root     pts/0    192.168.1.73     12:24    7.00s  0.69s  0.01s w
root     pts/1    :0               12:59   23.00s  0.35s  0.30s -su


Help? :P
User avatar
Posts: 4
Joined: Thu Jan 16, 2014 11:33 am
by cjnslm » Fri Jan 17, 2014 3:20 pm
Finally got it :) .
The problem was that the application was being ran by a normal user and i was trying to "attach" a vnc software to that session with the user root.
Once i tried to call x11vnc as the user that runs the java application i got vnc access with no problem.
Hope this helps anyone that has to find a solution to a problem similar to mine.

Thanks for the help Andy, x11vnc is great!
User avatar
Posts: 4
Joined: Thu Jan 16, 2014 11:33 am
by Greener » Sat Dec 27, 2014 3:22 am
Image
I get this always, i'm trying to run PureData Extended, but no results
What does it mean?

Thanks
Posts: 1
Joined: Sat Dec 27, 2014 3:18 am
Location: Bogotá, Colombia
by ghans » Sat Dec 27, 2014 10:53 am
Use approach 3 posted by Dave Driesen above.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
Posts: 6796
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany
by GlasgowGrin » Mon Mar 16, 2015 1:57 pm
I don't understand what i need to do in step 3? :/ can someone clarify please?

One more thing, i run my app like this: sudo java -jar AppName.jar
will it work this way?
Posts: 4
Joined: Sun Mar 15, 2015 12:19 pm
by topguy » Mon Mar 16, 2015 2:34 pm
If you can run that from shell without entering password it will probably also run from script.
So if you are "pi" user, then according to the description above you do "nano ~/.xinitrc" and enter your command in that file.

I would recommend that this is done in a system that does not automatically start the desktop. Then you can test that it works with "startx" before enabling "boot to desktop".
User avatar
Posts: 2014
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway
by GlasgowGrin » Mon Mar 16, 2015 3:03 pm
oh, i got it to work, thank you for reply :) i was confused with that xinitrc file
now one more question, how do i kill the app that started and get back to gui/console?
Posts: 4
Joined: Sun Mar 15, 2015 12:19 pm
by topguy » Mon Mar 16, 2015 3:24 pm
Click on the "close" button ?
Choose "file->quit" in the menu ?
Press escape ?

Its your Java application, how should we know ;-)
User avatar
Posts: 2014
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway
by GlasgowGrin » Mon Mar 16, 2015 3:31 pm
it's just a dummy window but lets not get off topic, ill get it somehow :) tyvm anyway
Posts: 4
Joined: Sun Mar 15, 2015 12:19 pm
by mflach » Wed Feb 10, 2016 7:31 pm
I can get my graphical application to launch but I don't have a mouse cursor. I'm using a Logitech wireless keyboard that has an integrated track-pad. The mouse input (button press) works and the UI changes when I move the mouse around but I don't see the mouse cursor.

I've tried a simple gtk application and a xwWidgets application and get the same result.

Any thoughts?
Posts: 1
Joined: Wed Feb 10, 2016 7:25 pm
by zoomz » Thu Jul 14, 2016 10:12 am
mflach wrote:I can get my graphical application to launch but I don't have a mouse cursor.


I have the same problem. I run a python script on a raspberry pi raspbian jessie distribution. The window is displayed but with no mouse cursor and no title. Can you help?
Thanks
Posts: 3
Joined: Mon Apr 25, 2016 5:39 am