1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: desktop.eclass
6 # base-system@gentoo.org
7 # @BLURB: support for desktop files, menus, and icons
9 if [[ -z ${_DESKTOP_ECLASS} ]]; then
12 # @FUNCTION: make_desktop_entry
13 # @USAGE: make_desktop_entry(<command>, [name], [icon], [type], [fields])
15 # Make a .desktop file.
18 # binary: what command does the app run with ?
19 # name: the name that will show up in the menu
20 # icon: the icon to use in the menu entry
21 # this can be relative (to /usr/share/pixmaps) or
22 # a full path to an icon
23 # type: what kind of application is this?
25 # https://specifications.freedesktop.org/menu-spec/latest/apa.html
26 # if unset, function tries to guess from package's category
27 # fields: extra fields to append to the desktop file; a printf string
29 make_desktop_entry() {
30 [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable"
33 local name=${2:-${PN}}
34 local icon=${3:-${PN}}
38 if [[ -z ${type} ]] ; then
39 local catmaj=${CATEGORY%%-*}
40 local catmin=${CATEGORY##*-}
44 accessibility) type="Utility;Accessibility";;
46 antivirus) type=System;;
47 arch) type="Utility;Archiving";;
48 backup) type="Utility;Archiving";;
49 cdr) type="AudioVideo;DiscBurning";;
50 dicts) type="Office;Dictionary";;
51 doc) type=Documentation;;
52 editors) type="Utility;TextEditor";;
53 emacs) type="Development;TextEditor";;
54 emulation) type="System;Emulator";;
55 laptop) type="Settings;HardwareSettings";;
57 pda) type="Office;PDA";;
58 vim) type="Development;TextEditor";;
59 xemacs) type="Development;TextEditor";;
69 action|fps) type=ActionGame;;
70 arcade) type=ArcadeGame;;
71 board) type=BoardGame;;
72 emulation) type=Emulator;;
74 puzzle) type=LogicGame;;
75 roguelike) type=RolePlaying;;
76 rpg) type=RolePlaying;;
77 simulation) type=Simulation;;
78 sports) type=SportsGame;;
79 strategy) type=StrategyGame;;
108 type="AudioVideo;${type}"
115 dialup) type=Dialup;;
116 ftp) type=FileTransfer;;
117 im) type=InstantMessaging;;
118 irc) type=IRCClient;;
122 p2p) type=FileTransfer;;
123 voip) type=Telephony;;
125 type="Network;${type}"
130 astro*) type=Astronomy;;
132 calc*) type=Calculator;;
133 chem*) type=Chemistry;;
134 elec*) type=Electronics;;
137 physics) type=Physics;;
138 visual*) type=DataVisualization;;
140 type="Education;Science;${type}"
149 client) type=WebBrowser;;
151 type="Network;${type}"
159 local slot=${SLOT%/*}
160 if [[ ${slot} == "0" ]] ; then
161 local desktop_name="${PN}"
163 local desktop_name="${PN}-${slot}"
165 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop"
166 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop
168 # Don't append another ";" when a valid category value is provided.
169 type=${type%;}${type:+;}
171 if [[ -n ${icon} && ${icon} != /* ]] && [[ ${icon} == *.xpm || ${icon} == *.png || ${icon} == *.svg ]]; then
172 ewarn "As described in the Icon Theme Specification, icon file extensions are not"
173 ewarn "allowed in .desktop files if the value is not an absolute path."
177 cat <<-EOF > "${desktop}" || die
181 Comment=${DESCRIPTION}
188 if [[ ${fields:-=} != *=* ]] ; then
189 # 5th arg used to be value to Path=
190 ewarn "make_desktop_entry: update your 5th arg to read Path=${fields}"
191 fields="Path=${fields}"
193 if [[ -n ${fields} ]]; then
194 printf '%b\n' "${fields}" >> "${desktop}" || die
198 # wrap the env here so that the 'insinto' call
199 # doesn't corrupt the env of the caller
201 insinto /usr/share/applications
203 ) || die "installing desktop file failed"
206 # @FUNCTION: make_session_desktop
207 # @USAGE: <title> <command> [command args...]
209 # Make a GDM/KDM Session file. The title is the file to execute to start the
210 # Window Manager. The command is the name of the Window Manager.
212 # You can set the name of the file via the ${wm} variable.
213 make_session_desktop() {
214 [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1
215 [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1
219 local desktop=${T}/${wm:-${PN}}.desktop
222 cat <<-EOF > "${desktop}" || die
225 Comment=This session logs you into ${title}
232 # wrap the env here so that the 'insinto' call
233 # doesn't corrupt the env of the caller
235 insinto /usr/share/xsessions
243 # Install the list of .desktop menu files into the appropriate directory
244 # (/usr/share/applications).
247 # wrap the env here so that the 'insinto' call
248 # doesn't corrupt the env of the caller
251 insinto /usr/share/applications
253 if [[ -d ${i} ]] ; then
254 doins "${i}"/*.desktop
266 # @USAGE: <menu> <newname>
268 # Like all other new* functions, install the specified menu as newname.
271 # wrap the env here so that the 'insinto' call
272 # doesn't corrupt the env of the caller
274 insinto /usr/share/applications
279 # @FUNCTION: _iconins
282 # function for use in doicon and newicon
285 # wrap the env here so that the 'insinto' call
286 # doesn't corrupt the env of the caller
288 local funcname=$1; shift
293 while [[ $# -gt 0 ]] ; do
296 if [[ ${2%%x*}x${2%%x*} == "$2" ]] ; then
302 16|22|24|32|36|48|64|72|96|128|192|256|512)
303 size=${size}x${size};;
307 eerror "${size} is an unsupported icon size!"
318 if [[ -z ${size} ]] ; then
319 insinto /usr/share/pixmaps
321 insinto /usr/share/icons/${theme}/${size}/${context}
324 if [[ ${funcname} == doicon ]] ; then
325 if [[ -f $1 ]] ; then
327 elif [[ -d $1 ]] ; then
329 doins "${1}"/*.{png,svg}
332 eerror "${1} is not a valid file/directory!"
341 if [[ ${funcname} == newicon ]] ; then
348 # @USAGE: [options] <icons>
350 # Install icon into the icon directory /usr/share/icons or into
351 # /usr/share/pixmaps if "--size" is not set.
352 # This is useful in conjunction with creating desktop/menu files.
357 # !!! must specify to install into /usr/share/icons/... !!!
358 # size of the icon, like 48 or 48x48
359 # supported icon sizes are:
360 # 16 22 24 32 36 48 64 72 96 128 192 256 512 scalable
364 # defaults to "hicolor"
366 # icons: list of icons
368 # example 1: doicon foobar.png fuqbar.svg suckbar.png
369 # results in: insinto /usr/share/pixmaps
370 # doins foobar.png fuqbar.svg suckbar.png
372 # example 2: doicon -s 48 foobar.png fuqbar.png blobbar.png
373 # results in: insinto /usr/share/icons/hicolor/48x48/apps
374 # doins foobar.png fuqbar.png blobbar.png
377 _iconins ${FUNCNAME} "$@"
381 # @USAGE: [options] <icon> <newname>
383 # Like doicon, install the specified icon as newname.
386 # example 1: newicon foobar.png NEWNAME.png
387 # results in: insinto /usr/share/pixmaps
388 # newins foobar.png NEWNAME.png
390 # example 2: newicon -s 48 foobar.png NEWNAME.png
391 # results in: insinto /usr/share/icons/hicolor/48x48/apps
392 # newins foobar.png NEWNAME.png
395 _iconins ${FUNCNAME} "$@"