[英]How to set my application's desktop icon for Linux: KDE, Gnome etc?
I have a cross platform program that runs on Windows, Linux and Macintosh. 我有一个在Windows,Linux和Macintosh上运行的跨平台程序。 My windows version has an Icon but I don't know how to make have one for my Linux build. 我的Windows版本有一个Icon,但我不知道如何为我的Linux版本制作一个。 Is there a standard format for KDE, Gnome etc. or will I have to do something special for each one? 是否有KDE,Gnome等标准格式或者我必须为每个格式做一些特殊的事情吗?
My app is in c++ and distributed as source so the end user will compile it with gcc. 我的应用程序是用c ++编写的,并作为源代码分发,因此最终用户将使用gcc编译它。
If I can have the icon embedded directly inside my exe binary that would be the best. 如果我可以在我的exe二进制文件中直接嵌入图标,那将是最好的。
For Gnome and Kde, you would probably want to include a desktop file with your app that defines how it will be launched. 对于Gnome和Kde,您可能希望在应用程序中包含一个桌面文件,用于定义如何启动它。 The specification can be found here . 规范可以在这里找到。 If you have an installer included with your app, you would probably want to have it generate this desktop file and put it in the right places to make menu entries and whatnot 如果您的应用程序附带了安装程序,您可能希望让它生成此桌面文件并将其放在正确的位置以生成菜单条目和诸如此类的东西
If you are using one of the pre-baked F/OSS build systems, such as KDE's CMake support, it's really rather easy once you have a .desktop file: 如果您正在使用其中一个预先制作的F / OSS构建系统,例如KDE的CMake支持,那么一旦您拥有.desktop文件,它就非常容易:
install( FILES myapp.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} ) kde4_add_app_icon(myapp_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/hi*-app-myappname.png") 安装(FILES myapp.desktop DESTINATION $ {XDG_APPS_INSTALL_DIR})kde4_add_app_icon(myapp_SRCS“$ {CMAKE_CURRENT_SOURCE_DIR} /hi*-app-myappname.png”)
If you are rolling your own, consider using xdg-utils , which includes handy little scripts like xdg-desktop-menu (installs desktop menu items) and xdg-desktop-icon (installs icons to the desktop) for such things. 如果您要自己动手,请考虑使用xdg-utils ,其中包括xdg-desktop-menu(安装桌面菜单项)和xdg-desktop-icon(在桌面上安装图标)等方便的小脚本。
The .desktop standard was already pointed out in the first comment, though you can also just grab one that is already installed on your system and modify it from there. .desktop标准已在第一条评论中指出,但您也可以抓住已安装在系统上的一个并从那里进行修改。 As for icons, PNGs and SVGs are geerally supported though PNGs tend to give the best results still. 至于图标,虽然PNG倾向于提供最好的结果,但PNG和SVG仍然受到支持。
KDE community with it's KDE 4 series started to use CMake as a build system. KDE社区用它的KDE 4系列开始使用CMake作为构建系统。 They developed a CMake macro that knows how to set an icon for your application regardles of the platform (windows (embedded in exe), mac (.app bundles), linux (.desktop files) etc.) 他们开发了一个CMake宏,它知道如何为平台的应用程序设置图标(windows(嵌入在exe中),mac(.app bundles),linux(.desktop文件)等)。
Maybe you can use it. 也许你可以使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.