简体   繁体   中英

Have my GTK application started on startup on Linux

I have an C++ executable that include some GTK code. I want this application to be started on startup of my machine (as root).

I tried with a init script (that is working perfectly when I use it from my user session), but having a look at the log file of my application I see that the latest logged line is before to call Gtk::Application::create() so it seems that it too earlier to initialize GTK.

How can I have my application started after the user session opened so that GTK initialisation is not failing ?

Create a .desktop file of your application, and put it to /etc/xdg/autostart/ for each user, or to $HOME/.config/autostart/ for current user.

If you want to load that application as root for general users, you may choose to use gksu or other tools to authorize priviledge.

Alternatively, you can see how network-manager is designed. It inits network-manager module as a init-script when system starts, and loads nm-applet, which is GUI for ordinary user, when a user session loads. Thus, network-manager can be managed on all the desktop environment (like Gnome, KDEE, xfce...) by desktop users.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM