1

I have Ubuntu-server 16.04. Installed gtk3 and can execute my program manually by this command: ./img when I go to it's directory /home/m. enter image description here

But when I tried to add this line to my /etc/rc.local file:

/home/m/img &

It didn't work. This is my rc.local full content:

startx
/home/m/img &
exit 0

Then I tried to create ~/.xinitrc file with this content:

 #!/usr/bin/env bash
/home/m/img &
exec openbox-session

Then made it executable by this command: chmod +x ~/.xinitrc

But I got nothing(even it didn't show my openbox after reboot), So I executed this command too:

ln -s ~/.xinitrc ~/.xsession

After that my openbox came back but my program didn't start after boot! or any other time!

My goal is this: when I turned on my board, after boot, it runs my gtk-based program and shows my image. It's something like Kiosk but a c++ program should only show an image!

How should I do that?

EDIT: I did add this line: /home/m/img & to my /etc/xdg/openbox/autostart file, and it works after login but doesn't show my image, it shows only a file icon at center of the screen. But when I go to this address /home/m/ and run this command ./img it shows my image in full screen!

Why this happens?

**Also I like to hide my mouse pointer and my windows borders but don't know how?

EDIT2: This is what I see after boot: enter image description here

And this is what I see after trying this command(in write buttom corner an icon appears): /home/m/img & enter image description here

user3486308
  • 609
  • 3
  • 17
  • 37
  • That seems a very strange rc.local. Did you add the startx or is that an Ubuntu surprise? – Chris Davies Nov 09 '17 at 20:34
  • 1
    @roaima, see https://unix.stackexchange.com/questions/402780/ and https://unix.stackexchange.com/questions/401884/ for how people here have told the questioner to do this. – JdeBP Nov 10 '17 at 06:10
  • @JdeBP that's really helpful. The context also suggests that the OP's first sentence is wrong - and (in this case) actually misleading. – Chris Davies Nov 10 '17 at 08:52
  • When you run /home/m/img & on a terminal, does your application work? – Zip Nov 10 '17 at 16:50
  • @Zip: No, it shows an icon in bottom right of the page...it's a window that I can extent it and there is that icon in center of that. I put 2 new pics in my post. – user3486308 Nov 10 '17 at 18:48
  • You need to either make your application work even on background (the & does that) or make your startup scripts run your application in a way it'll work, like without the &. You can make your app run without hanging the terminal by itself... – Zip Nov 10 '17 at 23:01
  • @Zip: I want to hide the mouse pointer and windows borders. And don't want any other programs run after my program. this is a single purpose computer. So which method is better you think? – user3486308 Nov 11 '17 at 06:07
  • You can probably obtain more useful answers if you state in the question what the contents of your /home/m directory are. My educated guess is that that will make it blatantly obvious to answerers why there's no image if the program is run with a different working directory. – JdeBP Nov 22 '17 at 14:51

2 Answers2

3

**Also I like to hide my mouse pointer and my windows borders but don't know how?

You can append -- -nocursor to your startx to hide mouse pointer:

exec startx -- -nocursor

There are files ~/.config/openbox/rc.xml and /etc/xdg/openbox/rc.xml for you to edit (ref: http://openbox.org/wiki/Help:Configuration) , e.g. (bottom in that files):

    ...
  </menu>
    <applications>

    <application class="*">
        <decor>no</decor>
        <position force="yes">
              <x>50</x>
              <y>50</y>
              <monitor>1</monitor>
        </position>
        <size>
              <width>300</width>
              <height>300</height>
        </size>
        <focus>yes</focus>
        <desktop>1</desktop>
        <layer>normal</layer>
        <iconic>no</iconic>
        <skip_pager>no</skip_pager>
        <skip_taskbar>no</skip_taskbar>
        <fullscreen>no</fullscreen>
        <maximized>false</maximized>
    </application>

</applications>
</openbox_config>

In which <decor>no</decor> above will make the image app become borderless. Adjust the <width> and <height> if you found your image doesn't show the complete size. You can also adjust <x>, <y> of the app.

There are more, e.g. comment out the menu tags (there are multiple <context tags has this <menu> entry):

  <mousebind button="Right" action="Press">
    <action name="ShowMenu">
        <!-- menu>root-menu</menu -->
    </action>
  </mousebind>

It will disable the right-click to shows menu (startx -- -nocursor hide mouse cursor not prevent you to right-click open menu).

There are also openbox/menu.xml to customize the right-click menu item, e.g.:

  <item label="Run Image app">
    <action name="Execute"><execute>/home/m/img</execute></action>
  </item>

You can choose right-click menu item Reconfigure once menu.xml or rc.xml edited to take effect.

I also posted answer here, to solve auto start issue as non-root.

林果皞
  • 5,156
  • 3
  • 33
  • 46
  • I will do what you said soon and say the results, but before that, I have a question: I think the only way I can do what you said above is putting startx inside /etc/rc.local, and when I do that, my board startups as root user, and because of this, pulseaudio or gtk-based programs will not start for root user! – user3486308 Nov 23 '17 at 05:39
  • I think the problem is system autologins as root user and because of that it can't execute my gtk code true! If I could change it to non-root user I think it would be OK? – user3486308 Nov 23 '17 at 06:07
  • @user145959 You can always do su - m -c "exec /home/m/img" to run as m user. You can also debug your ~/.xinitrc, rc.local by doing something like echo 5 > /tmp/my.log to know it's run to the first line, last line, created file with root(ls -l /tmp/my.log to know), or even do env > /tmp/env.log to know the env is correct to run your img program. – 林果皞 Nov 23 '17 at 06:45
  • What about something like pulseaudio, I know it doesn't start as root user, how can I fix it? (I ask because some functions in my code need it). – user3486308 Nov 23 '17 at 06:51
  • I think I must use something like this inside /etc/rc.local : su - m -c startx. Is this true? – user3486308 Nov 23 '17 at 07:05
  • Also another user here told me to make a systemd unit file: https://unix.stackexchange.com/questions/405618/how-to-change-autologin-from-root-to-non-root-user – user3486308 Nov 23 '17 at 07:08
  • https://www.raspberrypi.org/forums/viewtopic.php?t=42888 shows you can do su -s /bin/bash -c startx m& . I'm not sure your system has systemd or not, you should use systemd if exists. – 林果皞 Nov 23 '17 at 07:14
  • unfortunately su -s /bin/bash -c startx m& doesn't work! If I put startx inside /etc/rc.local it works but when I add something to it, it doesn't work :( – user3486308 Nov 23 '17 at 07:29
  • About systemd, I did what that user told me in other topic, but it didn't work too! – user3486308 Nov 23 '17 at 07:31
  • @user145959 Is your system has systemd installed before you try this ? Or you perform new install systemd because of this ? – 林果皞 Nov 23 '17 at 08:21
  • Really I don't know if my system has systemd or not. I only searched the folder /etc/systemd/system and found it. then I did create autologin.service file inside it! I use Armbian 5.30 that claims is Ubuntu server 16.04(3.4.113-sun8i #16 SMP PREEMPT Tue Jun 13 14:15:57 CEST 2017 armv7l armv7l armv7l GNU/Linux) – user3486308 Nov 23 '17 at 08:27
  • @user145959 What is the output of systemctl get-default ? – 林果皞 Nov 23 '17 at 08:32
  • graphical.target – user3486308 Nov 23 '17 at 08:46
  • @user145959 I posted the answer here – 林果皞 Nov 23 '17 at 12:09
  • I did change this line <decor>yes</decor> to <decor>no</decor> but I have borders yet! – user3486308 Nov 29 '17 at 15:35
  • @user145959 The bottom part of original files rc.xmlhas been comment out, you need to uncomment all of them. Better backup the file first, then copy my bottom part and replace the part between </menu> and </applications>. Be careful xml is sensitive, it will cause entire config file stop working if missing single tag or set the wrong value. And also local rc.xml values will override /etc/'s rc.xml. – 林果皞 Nov 29 '17 at 15:39
1

With openbox (which is what you're using according to one of the logs) a better option to open a graphical application (after logging in) for a single user would be to use ~/.config/openbox/autostart.

For all users, try /etc/xdg/openbox/autostart.

Source: http://openbox.org/wiki/Help:Autostart

Zip
  • 992