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

8
  • That seems a very strange rc.local. Did you add the startx or is that an Ubuntu surprise? Commented Nov 9, 2017 at 20:34
  • 1
    @roaima, see unix.stackexchange.com/questions/402780 and unix.stackexchange.com/questions/401884 for how people here have told the questioner to do this.
    – JdeBP
    Commented Nov 10, 2017 at 6:10
  • @JdeBP that's really helpful. The context also suggests that the OP's first sentence is wrong - and (in this case) actually misleading. Commented Nov 10, 2017 at 8:52
  • When you run /home/m/img & on a terminal, does your application work?
    – Zip
    Commented Nov 10, 2017 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. Commented Nov 10, 2017 at 18:48

2 Answers 2

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.

16
  • 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! Commented Nov 23, 2017 at 5: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? Commented Nov 23, 2017 at 6: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.
    – 林果皞
    Commented Nov 23, 2017 at 6: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). Commented Nov 23, 2017 at 6:51
  • I think I must use something like this inside /etc/rc.local : su - m -c startx. Is this true? Commented Nov 23, 2017 at 7:05
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

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .